protected void renderElement(FuzzyXMLNode node, RenderContext renderContext, StringBuffer renderBuffer, WodParserCache cache) {
String nodeID = "node" + (_counter++);
_idToNodeMap.put(nodeID, node);
_nodeToIDMap.put(node, nodeID);
if (node instanceof FuzzyXMLElement) {
FuzzyXMLElement element = (FuzzyXMLElement) node;
boolean empty = element.isEmpty();
String nodeName = element.getName();
String className = "element";
boolean woTag = WodHtmlUtils.isWOTag(nodeName);
boolean woSimpleString = false;
IWodElement wodElement = null;
if (woTag) {
className = className + " wo";
try {
BuildProperties buildProperties = (BuildProperties)_editor.getParserCache().getProject().getAdapter(BuildProperties.class);
wodElement = WodHtmlUtils.getWodElement(element, buildProperties, true, cache);
}
catch (Throwable t) {
// IGNORE
t.printStackTrace();
}
if (wodElement != null) {
className = className + " " + wodElement.getElementType();
if ("WOString".equals(wodElement.getElementType()) || "ERXLocalizedString".equals(wodElement.getElementType())) {
if (wodElement.getBindingNamed("value") != null) {
if (wodElement.getBindingNamed("escapeHTML") != null && wodElement.getBindings().size() == 2) {
woSimpleString = true;
}
else if (wodElement.getBindings().size() == 1) {
woSimpleString = true;
}
}
// MS: FORCE OFF FOR NOW
//woSimpleString = false;
if (woSimpleString) {
className = className + " simple";
}
}
}
}
else {
className = className + " " + nodeName.toLowerCase();
}
boolean showExpandCollapse = !empty;
if ("script".equalsIgnoreCase(nodeName)) {
// don't show script
showExpandCollapse = false;
}
else if ("style".equalsIgnoreCase(nodeName)) {
// don't show style
showExpandCollapse = false;
}
if (!showExpandCollapse) {
className += " empty";
}
//renderBuffer.append("<div id = \"" + nodeID + "\" class = \"" + className + "\" onmouseover = \"window.status = 'over:" + nodeID + "';\" onmouseout = \"window.status = 'out:" + nodeID + "';\" >");
renderBuffer.append("<div id = \"" + nodeID + "\" class = \"" + className + "\">");
if (showExpandCollapse) {
renderBuffer.append("<div id = \"" + nodeID + "_toggle\" class = \"expandcollapse\" onclick = \"expandCollapse('" + nodeID + "')\">");
if (_collapsedIDs.contains(nodeID)) {
renderBuffer.append(TemplateOutlinePage.EXPAND_STRING);
}
else {
renderBuffer.append(TemplateOutlinePage.COLLAPSE_STRING);
}
renderBuffer.append("</div>");
}
renderBuffer.append("<div class = \"summary\" onclick = \"window.status = 'select:" + nodeID + "'\">");
// ... a simple string tag
if (woSimpleString) {
IWodBinding valueBinding = wodElement.getBindingNamed("value");
String text = valueBinding.getValue();
String textClassName;
if (valueBinding.isLiteral()) {
//text = text.replaceAll("^\"([^\"]+)\"", "$1");
textClassName = "text literal";
}
else if (valueBinding.isOGNL()) {
textClassName = "text ognl";
}
else {
textClassName = "text keypath";
}
renderBuffer.append("<div class = \"title\"></div> <div class = \"" + textClassName + "\">[" + text + "]</div>");
}
// ... a WO tag
else if (woTag) {
if (wodElement != null) {
if (WodHtmlUtils.isInline(nodeName)) {
String summaryName = wodElement.getElementType();
renderBuffer.append("<div class = \"title\"><span class = \"nodeName verbose\">" + summaryName + "</span></div>");
// Special case for the compact display of a conditional
if ("WOConditional".equals(summaryName)) {
String conditionValue = wodElement.getBindingValue("condition");
if (conditionValue != null) {
summaryName = conditionValue;
boolean negated = false;
IWodBinding negateBinding = wodElement.getBindingNamed("negate");
if (negateBinding != null) {
if (negateBinding.isTrueValue()) {
negated = true;
}
}
else if (nodeName.equals("wo:not")) {
negated = true;
}
if (negated) {
summaryName = "<span class = \"negate\">not</span> " + summaryName;
}
else if (negateBinding != null) {
summaryName = summaryName + " <span class = \"negate\">not = " + negateBinding.getValue() + "</span>";
}
}
}
// Special case for the compact display of a string
else if ("WOString".equals(summaryName)) {
String value = wodElement.getBindingValue("value");
if (value != null) {
summaryName = "WOString: " + value;
}
}
// Special case for the compact display of a localized string
else if ("ERXLocalizedString".equals(summaryName)) {
String value = wodElement.getBindingValue("value");
if (value != null) {
summaryName = "ERXLocalizedString: " + value;
}
}
// Special case for the compact display of links, buttons, etc
else if (wodElement.getBindingNamed("action") != null) {
String action = wodElement.getBindingValue("action");
summaryName = wodElement.getElementType() + ": " + action;
}
// Special case for the compact display of form fields
else if (wodElement.getBindingNamed("value") != null) {
String value = wodElement.getBindingValue("value");
summaryName = wodElement.getElementType() + ": " + value;
}
// Special case for the compact display of checkboxes
else if (wodElement.getBindingNamed("checked") != null) {
String checked = wodElement.getBindingValue("checked");
summaryName = wodElement.getElementType() + ": " + checked;
}
// Special case for the compact display of repetitions and popup buttons
else if (wodElement.getBindingNamed("list") != null) {
String list = wodElement.getBindingValue("list");
summaryName = wodElement.getElementType() + ": " + list;
}
renderBuffer.append("<div class = \"title\"><span class = \"nodeName compact\">" + summaryName + "</span></div>");
}
else {
renderBuffer.append("<div class = \"title\"><span class = \"nodeName\">" + wodElement.getElementName() + "</span> <span class = \"type\">: " + wodElement.getElementType() + "</span></div>");
}
// WO bindings
List<IWodBinding> wodBindings = wodElement.getBindings();
if (wodBindings.size() > 0) {
renderBuffer.append("<table class = \"bindings\">");
for (IWodBinding wodBinding : wodBindings) {
renderBuffer.append("<tr>");
renderBuffer.append("<th>" + wodBinding.getName() + "</th>");
String bindingClass;
if (wodBinding.isLiteral()) {
bindingClass = "literal";
}
else if (wodBinding.isOGNL()) {
bindingClass = "ognl";
}
else {
bindingClass = "keypath";
}
renderBuffer.append("<td class = \"" + bindingClass + "\">" + wodBinding.getValue() + "</td>");
renderBuffer.append("</tr>");
}
renderBuffer.append("</table>");
}
}
// ... if the WO tag doesn't have a WOD entry, show it as "missing"
else {
String missingName = element.getAttributeValue("name");
if (missingName == null) {
missingName = nodeName;
}
renderBuffer.append("<div class = \"title missing\">" + missingName + "</div>");
}
}
// ... an html node
else {
renderBuffer.append("<div class = \"title nonwo\"><span class = \"nodeName\">");
renderBuffer.append(nodeName);
renderBuffer.append("</span>");
String elementID = element.getAttributeValue("id");
if (elementID != null) {
renderBuffer.append("<span class = \"idName\">#" + elementID + "</span>");
}
String elementClass = element.getAttributeValue("class");
if (elementClass != null) {
elementClass = elementClass.replace(' ', '.');
renderBuffer.append("<span class = \"className\">." + elementClass + "</span>");
}
renderBuffer.append("</div>");
}
renderBuffer.append("</div>");
// ... if there are children, show the contents
if (showExpandCollapse) {
renderBuffer.append("<div id = \"" + nodeID + "_contents\" class = \"contents\"");
if (_collapsedIDs.contains(nodeID)) {
renderBuffer.append(" style = \"display: none\"");
}
renderBuffer.append(">");
FuzzyXMLNode[] children = element.getChildren();
for (FuzzyXMLNode child : children) {
renderElement(child, renderContext, renderBuffer, cache);
}
renderBuffer.append("</div>");
}