1 56 57 package org.jdom.contrib.output; 58 59 69 import java.util.Iterator ; 70 import java.util.List ; 71 import javax.swing.*; 72 import javax.swing.tree.DefaultMutableTreeNode ; 73 import javax.swing.tree.TreeNode ; 74 import org.jdom.input.SAXBuilder; 75 import org.jdom.Document; 76 import org.jdom.Attribute; 77 import org.jdom.Element; 78 79 public class JTreeOutputter { 80 81 public JTreeOutputter() { 82 } 83 84 public JTreeOutputter(boolean toBeCompatible) { 85 } 87 88 93 public void output(Document doc, DefaultMutableTreeNode root) { 94 processElement(doc.getRootElement(),root); 95 } 96 97 102 public void output(Element el, DefaultMutableTreeNode root) { 103 processElement(el, root); 104 } 105 106 protected void processElement(Element el, DefaultMutableTreeNode dmtn) { 107 DefaultMutableTreeNode dmtnLocal = 108 new DefaultMutableTreeNode (el.getName()); 109 String elText = el.getTextNormalize(); 110 if (elText != null && !elText.equals("")) { 111 dmtnLocal.add(new DefaultMutableTreeNode (elText)); 112 } 113 processAttributes(el, dmtnLocal); 114 115 Iterator iter = el.getChildren().iterator(); 116 117 while (iter.hasNext()) { 118 Element nextEl = (Element)iter.next(); 119 processElement(nextEl, dmtnLocal); 120 } 121 dmtn.add(dmtnLocal); 122 } 123 124 protected void processAttributes(Element el, DefaultMutableTreeNode dmtn) { 125 Iterator atts = el.getAttributes().iterator(); 126 while (atts.hasNext()) { 127 Attribute att = (Attribute)atts.next(); 128 DefaultMutableTreeNode node = 129 new DefaultMutableTreeNode ("@" + att.getName()); 130 node.add(new DefaultMutableTreeNode (att.getValue())); 131 dmtn.add(node); 132 } 133 } 134 } 135 136 | Popular Tags |