Class XMLTree

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class XMLTree extends JTree
A JTree that displays an xml document.
Since:
3.3.0
Author:
Xiaoming Liu
See Also:
  • Field Details

  • Constructor Details

    • XMLTree

      public XMLTree(Element xmlRoot, String basePath)
      ctor
      Parameters:
      xmlRoot - The root of the xml dom tree
      basePath - Where the xml came from
  • Method Details

    • loadDocument

      public void loadDocument(Element xmlRoot, String basePath)
      loadDocument
      Parameters:
      xmlRoot - The root of the xml dom tree
      basePath - Where the xml came from
    • treeClick

      protected void treeClick(MouseEvent event)
      Gets called when the tree is clicked.
      Parameters:
      event - Mouse event
    • addTagsToProcess

      public void addTagsToProcess(List tags)
      Define the set of tags who we should process
      Parameters:
      tags - List of tag names
    • shouldProcess

      protected boolean shouldProcess(Element xmlNode)
      Should we show the given xml Element
      Parameters:
      xmlNode -
      Returns:
      Should we look at this node and turn it into a jtree node
    • process

      protected void process(XMLTree.XmlTreeNode parentTreeNode, Element xmlNode)
      Walk the xml tree at the given xmlNode and create the JTree
      Parameters:
      parentTreeNode - The parent jtree node
      xmlNode - The xml node to process
    • shouldRecurse

      protected boolean shouldRecurse(Element xmlNode)
      Should we recursiely descend the children of the given xml Element
      Parameters:
      xmlNode - The xml node
      Returns:
      Should we recurse down
    • getLabel

      public String getLabel(Element n)
      Return the String used for the JTree node. This first looks in the tagNameToLabelAttr hashtable for an attribute name to fetch the label. If not found we try the attributes "label" and "name".
      Parameters:
      n - The node
      Returns:
      Its label
    • getXmlTreeNodeAt

      public XMLTree.XmlTreeNode getXmlTreeNodeAt(int x, int y)
      Return the xml tree node located at the given position
      Parameters:
      x - x
      y - y
      Returns:
      The node or null
    • getXmlTreeNodeAtPath

      protected XMLTree.XmlTreeNode getXmlTreeNodeAtPath(TreePath path)
      Return the xml tree node located at the given position
      Parameters:
      path - The tree path
      Returns:
      The node or null
    • setMultipleSelect

      public void setMultipleSelect(boolean v)
      Set tree select mode
      Parameters:
      v - Do multiples?
    • getLocalName

      public String getLocalName(Node element)
      Get the non qualified tag name
      Parameters:
      element - element
      Returns:
      tag name
    • getAttribute

      public String getAttribute(Node element, String name, String dflt)
      Get the given name-d attribute from the given element.
      Parameters:
      element - The xml element to look within.
      name - The attribute name.
      dflt - The default value.
      Returns:
      The attribute value or the dflt if not found.
    • getAttribute

      public String getAttribute(NamedNodeMap attrs, String name, String dflt)
      Get the given name-d attribute from the given attrs map. If not found then return the dflt argument.
      Parameters:
      attrs - The xml attribute map.
      name - The name of the attribute.
      dflt - The default value
      Returns:
      The attribute valueif found, else the dflt argument.
    • getChildText

      public String getChildText(Node parent)
      Concatenates the node values (grom getNodeValue) of the children of the given parent Node.
      Parameters:
      parent - The xml node to search its chidlren.
      Returns:
      The text values contained by the children of the given parent.
    • getElement

      public Element getElement(Element parent, String tagName)
      Get the first Element children of the given parent Element with the given tagName.
      Parameters:
      parent - The xml node to search its children.
      tagName - The tag to match.
      Returns:
      The first Element child that matches the given tag name.
    • getElements

      public NodeList getElements(Element parent)
      Get all children of the given parent Element who are instances of the Element class.
      Parameters:
      parent - The xml node to search its chidlren.
      Returns:
      All Element children of the given parent.
    • getElements

      public XMLTree.XmlNodeList getElements(Element parent, String tagName)
      Get all Element children of the given parent Element with the given tagName.
      Parameters:
      parent - The xml node to search its children.
      tagName - The tag to match.
      Returns:
      The Element children of the given parent node whose tags match the given tagName.
    • getElements

      public static NodeList getElements(Element parent, XMLTree.XmlNodeList nodeList)
      Get all children of the given parent Element who are instances of the Element class.
      Parameters:
      parent - The xml node to search its chidlren.
      nodeList - list to add to
      Returns:
      All Element children of the given parent.
    • isTag

      public boolean isTag(Node node, String name)
      Checks if the tag name of the given node matches the given name. If the given name is fully qualified (e.g., namespace:tagname) then check if it matches the full name of the node. If the node name is fully qualified and the name isn't then strip off the namespace of the node and compare else just compare the 2
      Parameters:
      node - the xml node
      name - name
      Returns:
      is non qualified tag name the same
    • equals

      public boolean equals(Object o1, Object o2)