Methods Summary |
---|
public org.w3c.dom.Node | getNode(java.lang.Object treeNode)get the org.w3c.Node for a MutableTreeNode.
return ((Model)getModel()).getNode(treeNode);
|
public org.w3c.dom.Node | getRootNode()Returns the root.
return ((Model)getModel()).getRootNode();
|
public javax.swing.tree.TreeNode | getTreeNode(java.lang.Object node)get the TreeNode for the org.w3c.Node
return ((Model)getModel()).getTreeNode(node);
|
protected static java.lang.String | normalize(java.lang.String s)Normalizes the given string.
StringBuffer str = new StringBuffer();
int len = (s != null) ? s.length() : 0;
for (int i = 0; i < len; i++) {
char ch = s.charAt(i);
switch (ch) {
case '<": {
str.append("<");
break;
}
case '>": {
str.append(">");
break;
}
case '&": {
str.append("&");
break;
}
case '"": {
str.append(""");
break;
}
case '\r":
case '\n":
default: {
str.append(ch);
}
}
}
return str.toString();
|
public void | setRootNode(org.w3c.dom.Node root)Sets the root.
((Model)getModel()).setRootNode(root);
expandRow(0);
|
protected static org.w3c.dom.Attr[] | sortAttributes(org.w3c.dom.NamedNodeMap attrs)Returns a sorted list of attributes.
int len = (attrs != null) ? attrs.getLength() : 0;
Attr array[] = new Attr[len];
for (int i = 0; i < len; i++) {
array[i] = (Attr)attrs.item(i);
}
for (int i = 0; i < len - 1; i++) {
String name = array[i].getNodeName();
int index = i;
for (int j = i + 1; j < len; j++) {
String curName = array[j].getNodeName();
if (curName.compareTo(name) < 0) {
name = curName;
index = j;
}
}
if (index != i) {
Attr temp = array[i];
array[i] = array[index];
array[index] = temp;
}
}
return array;
|
public static java.lang.String | toString(org.w3c.dom.Node node)
//
// Public methods
//
StringBuffer sb = new StringBuffer();
// is there anything to do?
if (node == null) {
return "";
}
int type = node.getNodeType();
sb.append(whatArray[type]);
sb.append(" : ");
sb.append(node.getNodeName());
String value = node.getNodeValue();
if (value != null) {
sb.append(" Value: \"");
sb.append(value);
sb.append("\"");
}
switch (type) {
// document
case Node.DOCUMENT_NODE: {
break;
}
// element with attributes
case Node.ELEMENT_NODE: {
Attr attrs[] = sortAttributes(node.getAttributes());
if (attrs.length > 0)
sb.append(" ATTRS:");
for (int i = 0; i < attrs.length; i++) {
Attr attr = attrs[i];
sb.append(' ");
sb.append(attr.getNodeName());
sb.append("=\"");
sb.append(normalize(attr.getNodeValue()));
sb.append('"");
}
sb.append('>");
break;
}
// handle entity reference nodes
case Node.ENTITY_REFERENCE_NODE: {
break;
}
// cdata sections
case Node.CDATA_SECTION_NODE: {
break;
}
// text
case Node.TEXT_NODE: {
break;
}
// processing instruction
case Node.PROCESSING_INSTRUCTION_NODE: {
break;
}
// comment node
case Node.COMMENT_NODE: {
break;
}
// DOCTYPE node
case Node.DOCUMENT_TYPE_NODE: {
break;
}
// Notation node
case Node.NOTATION_NODE: {
sb.append("public:");
String id = ((Notation)node).getPublicId();
if (id == null) {
sb.append("PUBLIC ");
sb.append(id);
sb.append(" ");
}
id = ((Notation)node).getSystemId();
if (id == null) {
sb.append("system: ");
sb.append(id);
sb.append(" ");
}
break;
}
}
return sb.toString();
|