//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
*
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.framework.htmlview.function;
import com.nexirius.framework.htmlview.HTMLParser;
import com.nexirius.framework.htmlview.HTMLResolver;
import com.nexirius.framework.htmlview.HTMLSessionVariable;
import com.nexirius.util.StringVector;
/**
* This class handles the $!debug(true|false, comment|html) function. This funnction displays debugging information if the given parameter is true.
* The second parameter is used to produce plain html comment of html information
*/
public class DebugHTMLFunction extends DefaultHTMLFunction {
public String getFunctionName() {
return "debug";
}
/**
* translate the function into HTML and write the result back to the parser
*
* @param sessionVariable
* @param parser the parser which translates the embedded commands
* @throws Exception
*/
public void translate(HTMLSessionVariable sessionVariable, HTMLParser parser)
throws Exception {
String on = getArgument(0);
String argument1 = getArgument(1);
boolean renderHTML = (argument1 != null && argument1.equalsIgnoreCase("html"));
if (on == null || on.equalsIgnoreCase("true")) {
HTMLResolver resolver = parser.getResolver();
String rootModel_fieldName = resolver.getRootModel().getFieldName();
String actModel_fieldName = parser.getModel().getFieldName();
String modelStack = resolver.getModelStackAsString(parser.getModel());
StringVector variableNames = resolver.getVariableStore().getVariableNames();
StringBuffer result = new StringBuffer();
if (renderHTML) {
result.append("<table>");
} else {
result.append("<!--\n");
}
appendLine(renderHTML, result, "Root Model: " + rootModel_fieldName);
appendLine(renderHTML, result, "Act Model: " + actModel_fieldName);
appendLine(renderHTML, result, "Model Stack: " + modelStack);
appendLine(renderHTML, result, HTMLFunction.PARAMETER_BUTTON + "=" + sessionVariable.getButton());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_CHILD + "=" + sessionVariable.getChild());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_DUPLICATE + "=" + sessionVariable.getDuplicate());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_EVENT + "=" + sessionVariable.getEvent());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_INDEX + "=" + sessionVariable.getIndex());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_ISEDITOR + "=" + sessionVariable.isEditor());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_SELECTED + "=" + sessionVariable.getSelectedChildren());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_STATE + "=" + sessionVariable.getState());
appendLine(renderHTML, result, HTMLFunction.PARAMETER_TEMPLATE + "=" + sessionVariable.getTemplate());
for (String s = variableNames.firstItem(); s != null; s = variableNames.nextItem()) {
appendLine(renderHTML, result, "VARIABLE " + s + ": " + resolver.getVariableStore().getValueOf(s));
}
if (renderHTML) {
result.append("</table>");
} else {
result.append("-->");
}
parser.getOut().write(result.toString().getBytes());
}
}
private void appendLine(boolean renderHTML, StringBuffer result, String line) {
if (renderHTML) {
result.append("<tr><td>");
}
result.append(line);
if (renderHTML) {
result.append("</td></tr>");
} else {
result.append('\n');
}
}
}