summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-08-23 18:35:05 (EDT)
committer pelder2006-08-23 18:35:05 (EDT)
commit55c74eda57972d6092f8b09b70d1f5579607648f (patch)
tree03f6c7b47b5e1a0daa54b7d8b5f55b3eab1eb554
parentc1bcfadcf3d8e772434c45967973b64dad10ccf9 (diff)
downloadorg.eclipse.jet-55c74eda57972d6092f8b09b70d1f5579607648f.zip
org.eclipse.jet-55c74eda57972d6092f8b09b70d1f5579607648f.tar.gz
org.eclipse.jet-55c74eda57972d6092f8b09b70d1f5579607648f.tar.bz2
[154930] Revise dump to include all elements.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DumpTag.java120
1 files changed, 118 insertions, 2 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DumpTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DumpTag.java
index 87eeafe..6bd3c57 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DumpTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DumpTag.java
@@ -104,7 +104,11 @@ public class DumpTag extends AbstractEmptyTag {
if ("true".equalsIgnoreCase(_entities)) { entities = true; } //$NON-NLS-1$
if ("yes".equalsIgnoreCase(_entities)) { entities = true; } //$NON-NLS-1$
- dump(resolved_node,format,entities,1,context,out);
+// dump(resolved_node,format,entities,1,context,out);
+
+ StringBuffer buffer = new StringBuffer();
+ dump2(resolved_node,format,entities,1,context,buffer);
+ out.write(buffer.toString());
/**
* End doAction logic
@@ -112,7 +116,119 @@ public class DumpTag extends AbstractEmptyTag {
}
- public void dump(Object node, boolean format, boolean entities, int indent, JET2Context context, JET2Writer out) {
+ private void dump2(Object node, boolean format, boolean entities, int indent, JET2Context context, StringBuffer out)
+ {
+ final String CHILD_NODES_XPATH = "child::node()"; //$NON-NLS-1$
+ final String ATTRIBUTEs_XPATH = "attribute::*"; //$NON-NLS-1$
+ final String ATTRIBUTE_NAME_XPATH = "name()"; //$NON-NLS-1$
+ final String NODE_VALUE_XPATH = "string()"; //$NON-NLS-1$
+ XPathContextExtender xpc = XPathContextExtender.getInstance(context);
+
+ INodeInspector inspector = InspectorManager.getInstance().getInspector(node);
+ if(inspector == null)
+ {
+ return;
+ }
+
+ final NodeKind nodeKind = inspector.getNodeKind(node);
+ if(nodeKind == NodeKind.ELEMENT)
+ {
+ out.append("<"); //$NON-NLS-1$
+ final String tagName = inspector.nameOf(node);
+ out.append(tagName);
+ final Object[] attrs = xpc.resolve(node, ATTRIBUTEs_XPATH);
+ for (int i = 0; attrs != null && i < attrs.length; i++)
+ {
+ out.append(" "); //$NON-NLS-1$
+ out.append(xpc.resolveAsString(attrs[i], ATTRIBUTE_NAME_XPATH));
+ out.append("="); //$NON-NLS-1$
+ out.append(useRightQuotes(xpc.resolveAsString(attrs[i], NODE_VALUE_XPATH)));
+ }
+ final Object[] children = xpc.resolve(node, CHILD_NODES_XPATH);
+ if(children != null && children.length > 0)
+ {
+ out.append(">"); //$NON-NLS-1$
+ writeChildren(children, format, entities, indent, context, out);
+ out.append("</"); //$NON-NLS-1$
+ out.append(tagName);
+ out.append(">"); //$NON-NLS-1$
+ }
+ else
+ {
+ out.append("/>"); //$NON-NLS-1$
+ }
+ }
+ else if(nodeKind == NodeKind.TEXT)
+ {
+ String buffer = xpc.resolveAsString(node, NODE_VALUE_XPATH);
+ if (entities) { buffer = insertEntities(buffer); }
+ out.append(buffer);
+ }
+ else if(nodeKind == NodeKind.COMMENT)
+ {
+ out.append("<!--"); //$NON-NLS-1$
+ out.append(xpc.resolveAsString(node, NODE_VALUE_XPATH));
+ out.append("-->"); //$NON-NLS-1$
+ }
+ else if(nodeKind == NodeKind.ROOT)
+ {
+ final Object[] children = xpc.resolve(node, CHILD_NODES_XPATH);
+ if(children != null) {
+ writeChildren(children, format, entities, 0, context, out);
+ }
+ }
+ else if(nodeKind == NodeKind.PROCESSING_INSTRUCTION)
+ {
+
+ }
+ else
+ {
+
+ }
+ }
+
+ /**
+ * @param children
+ * @param format
+ * @param entities
+ * @param indent
+ * @param context
+ * @param out
+ */
+ private void writeChildren(final Object[] children, boolean format, boolean entities, int indent, JET2Context context, StringBuffer out)
+ {
+ boolean textEncountered = false;
+ for (int i = 0; i < children.length; i++)
+ {
+ INodeInspector childInspector = InspectorManager.getInstance().getInspector(children[i]);
+ textEncountered = textEncountered || childInspector.getNodeKind(children[i]) == NodeKind.TEXT;
+
+ if(!textEncountered && format)
+ {
+ out.append(NL);
+ indent(out, indent);
+ }
+
+ dump2(children[i], format, entities, indent + 1, context, out);
+
+ }
+ if(!textEncountered && format)
+ {
+ out.append(NL);
+ indent(out, indent - 1);
+ }
+ }
+
+ /**
+ * @param out
+ * @param indent
+ */
+ private void indent(StringBuffer out, int indent)
+ {
+ for (int j = 0; j < indent; j++) { out.append(" "); } //$NON-NLS-1$
+ }
+
+ public void dump(Object node, boolean format, boolean entities, int indent, JET2Context context, JET2Writer out) {
boolean written = false;
boolean writeKids = false;