Class AbstractNode

    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractNode()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Node asXPathResult(Element parent)
      asXPathResult returns a version of this node which is capable of being an XPath result.
      java.lang.Object clone()
      clone will return a deep clone or if this node is read-only then clone will return the same instance.
      Pattern createPattern(java.lang.String patternText)  
      XPath createXPath(java.lang.String xpathExpression)
      createXPath creates an XPath object for the given xpathExpression.
      NodeFilter createXPathFilter(java.lang.String patternText)  
      protected Node createXPathResult(Element parent)  
      Node detach()
      Removes this node from its parent if there is one.
      Document getDocument()
      getDocument returns the Document that this Node is part of if this node supports the parent relationship.
      protected DocumentFactory getDocumentFactory()  
      java.lang.String getName()
      getName returns the name of this node.
      short getNodeType()
      Returns the code according to the type of node.
      java.lang.String getNodeTypeName()
      DOCUMENT ME!
      Element getParent()
      getParent returns the parent Element if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.
      java.lang.String getPath()
      Returns the XPath expression which will return a node set containing the given node such as /a/b/@c.
      java.lang.String getStringValue()
      Returns the XPath string-value of this node.
      java.lang.String getText()
      Returns the text of this node.
      java.lang.String getUniquePath()
      Returns the XPath expression which will return a nodeset of one node which is the current node.
      boolean hasContent()
      hasContent returns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.
      boolean isReadOnly()
      isReadOnly returns true if this node is read only and cannot be modified.
      boolean matches(java.lang.String patternText)
      matches returns true if evaluating the given XPath expression on this node returns a non-empty node set containing this node.
      java.lang.Number numberValueOf(java.lang.String xpathExpression)
      numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.
      java.util.List<Node> selectNodes(java.lang.String xpathExpression)
      selectNodes evaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression.
      java.util.List<Node> selectNodes(java.lang.String xpathExpression, java.lang.String comparisonXPathExpression)
      selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.
      java.util.List<Node> selectNodes(java.lang.String xpathExpression, java.lang.String comparisonXPathExpression, boolean removeDuplicates)
      selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.
      java.lang.Object selectObject(java.lang.String xpathExpression)
      selectObject evaluates an XPath expression and returns the result as an Object.
      Node selectSingleNode(java.lang.String xpathExpression)
      selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.
      void setDocument(Document document)
      setDocument sets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.
      void setName(java.lang.String name)
      Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.
      void setParent(Element parent)
      setParent sets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.
      void setText(java.lang.String text)
      Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.
      boolean supportsParent()
      supportsParent returns true if this node supports the parent relationship.
      java.lang.String valueOf(java.lang.String xpathExpression)
      valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
      void write(java.io.Writer writer)
      write writes this node as the default XML notation for this node.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NODE_TYPE_NAMES

        protected static final java.lang.String[] NODE_TYPE_NAMES
    • Constructor Detail

      • AbstractNode

        public AbstractNode()
    • Method Detail

      • getNodeType

        public short getNodeType()
        Description copied from interface: Node
        Returns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.
        Specified by:
        getNodeType in interface Node
        Returns:
        a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE
      • getNodeTypeName

        public java.lang.String getNodeTypeName()
        Description copied from interface: Node
        DOCUMENT ME!
        Specified by:
        getNodeTypeName in interface Node
        Returns:
        the name of the type of node such as "Document", "Element", "Attribute" or "Text"
      • getDocument

        public Document getDocument()
        Description copied from interface: Node

        getDocument returns the Document that this Node is part of if this node supports the parent relationship.

        This method is an optional feature and may not be supported for all Node implementations.

        Specified by:
        getDocument in interface Node
        Returns:
        the document of this node or null if this feature is not supported or the node is not associated with a Document
      • setDocument

        public void setDocument(Document document)
        Description copied from interface: Node

        setDocument sets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.

        This method should only be called from inside a Document implementation method and is not intended for general use.

        Specified by:
        setDocument in interface Node
        Parameters:
        document - is the new document of this node.
      • getParent

        public Element getParent()
        Description copied from interface: Node

        getParent returns the parent Element if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.

        This method is an optional feature and may not be supported for all Node implementations.

        Specified by:
        getParent in interface Node
        Returns:
        the parent of this node or null if it is the root of the tree or the parent relationship is not supported.
      • setParent

        public void setParent(Element parent)
        Description copied from interface: Node

        setParent sets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.

        This method should only be called from inside an Element implementation method and is not intended for general use.

        Specified by:
        setParent in interface Node
        Parameters:
        parent - is the new parent of this node.
      • supportsParent

        public boolean supportsParent()
        Description copied from interface: Node

        supportsParent returns true if this node supports the parent relationship.

        Some XML tree implementations are singly linked and only support downward navigation through children relationships. The default case is that both parent and children relationships are supported though for memory and performance reasons the parent relationship may not be supported.

        Specified by:
        supportsParent in interface Node
        Returns:
        true if this node supports the parent relationship or false it is not supported
      • isReadOnly

        public boolean isReadOnly()
        Description copied from interface: Node

        isReadOnly returns true if this node is read only and cannot be modified. Any attempt to modify a read-only Node will result in an UnsupportedOperationException being thrown.

        Specified by:
        isReadOnly in interface Node
        Returns:
        true if this Node is read only and cannot be modified otherwise false.
      • hasContent

        public boolean hasContent()
        Description copied from interface: Node

        hasContent returns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.

        Specified by:
        hasContent in interface Node
        Returns:
        true if this Node is a Branch with a nodeCount() of one or more.
      • getPath

        public java.lang.String getPath()
        Description copied from interface: Node

        Returns the XPath expression which will return a node set containing the given node such as /a/b/@c. No indexing will be used to restrict the path if multiple elements with the same name occur on the path.

        Specified by:
        getPath in interface Node
        Returns:
        the XPath expression which will return a nodeset containing at least this node.
      • getUniquePath

        public java.lang.String getUniquePath()
        Description copied from interface: Node

        Returns the XPath expression which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.

        Specified by:
        getUniquePath in interface Node
        Returns:
        the XPath expression which will return a nodeset containing just this node.
      • clone

        public java.lang.Object clone()
        Description copied from interface: Node

        clone will return a deep clone or if this node is read-only then clone will return the same instance.

        Specified by:
        clone in interface Node
        Overrides:
        clone in class java.lang.Object
        Returns:
        a deep clone of myself or myself if I am read only.
      • detach

        public Node detach()
        Description copied from interface: Node

        Removes this node from its parent if there is one. If this node is the root element of a document then it is removed from the document as well.

        This method is useful if you want to remove a node from its source document and add it to another document. For example

        Node node = ...; Element someOtherElement = ...; someOtherElement.add( node.detach() );
        Specified by:
        detach in interface Node
        Returns:
        the node that has been removed from its parent node if any and its document if any.
      • getName

        public java.lang.String getName()
        Description copied from interface: Node

        getName returns the name of this node. This is the XML local name of the element, attribute, entity or processing instruction. For CDATA and Text nodes this method will return null.

        Specified by:
        getName in interface Node
        Returns:
        the XML name of this node
      • setName

        public void setName(java.lang.String name)
        Description copied from interface: Node

        Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

        Specified by:
        setName in interface Node
        Parameters:
        name - is the new name of this node
      • getText

        public java.lang.String getText()
        Description copied from interface: Node

        Returns the text of this node.

        Specified by:
        getText in interface Node
        Returns:
        the text for this node.
      • getStringValue

        public java.lang.String getStringValue()
        Description copied from interface: Node
        Returns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .
        Specified by:
        getStringValue in interface Node
        Returns:
        the text from all the child Text and Element nodes appended together.
      • setText

        public void setText(java.lang.String text)
        Description copied from interface: Node

        Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

        Specified by:
        setText in interface Node
        Parameters:
        text - is the new textual value of this node
      • write

        public void write(java.io.Writer writer)
                   throws java.io.IOException
        Description copied from interface: Node

        write writes this node as the default XML notation for this node. If you wish to control the XML output (such as for pretty printing, changing the indentation policy etc.) then please use XMLWriter or its derivations.

        Specified by:
        write in interface Node
        Parameters:
        writer - is the Writer to output the XML to
        Throws:
        java.io.IOException - DOCUMENT ME!
      • selectObject

        public java.lang.Object selectObject(java.lang.String xpathExpression)
        Description copied from interface: Node

        selectObject evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of one or more Nodeinstances or a scalar object like a Stringor a Numberinstance depending on the XPath expression.

        Specified by:
        selectObject in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        Returns:
        the value of the XPath expression as a Listof Node instances, a Stringor a Numberinstance depending on the XPath expression.
      • selectNodes

        public java.util.List<Node> selectNodes(java.lang.String xpathExpression)
        Description copied from interface: Node

        selectNodes evaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression.

        Specified by:
        selectNodes in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        Returns:
        the list of Node or String instances depending on the XPath expression
      • selectNodes

        public java.util.List<Node> selectNodes(java.lang.String xpathExpression,
                                                java.lang.String comparisonXPathExpression)
        Description copied from interface: Node

        selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.

        Specified by:
        selectNodes in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        comparisonXPathExpression - is the XPath expression used to compare the results by for sorting
        Returns:
        the list of Node instances sorted by the comparisonXPathExpression
      • selectNodes

        public java.util.List<Node> selectNodes(java.lang.String xpathExpression,
                                                java.lang.String comparisonXPathExpression,
                                                boolean removeDuplicates)
        Description copied from interface: Node

        selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.

        Specified by:
        selectNodes in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        comparisonXPathExpression - is the XPath expression used to compare the results by for sorting
        removeDuplicates - if this parameter is true then duplicate values (using the comparisonXPathExpression) are removed from the result List.
        Returns:
        the list of Node instances sorted by the comparisonXPathExpression
      • selectSingleNode

        public Node selectSingleNode(java.lang.String xpathExpression)
        Description copied from interface: Node

        selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.

        Specified by:
        selectSingleNode in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        Returns:
        the Node matching the XPath expression
      • valueOf

        public java.lang.String valueOf(java.lang.String xpathExpression)
        Description copied from interface: Node

        valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node. The string-value for a given node type is defined in the XPath specification .

        Specified by:
        valueOf in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        Returns:
        the string-value representation of the results of the XPath expression
      • numberValueOf

        public java.lang.Number numberValueOf(java.lang.String xpathExpression)
        Description copied from interface: Node

        numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.

        Specified by:
        numberValueOf in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        Returns:
        the numeric result of the XPath expression or null if the result is not a number.
      • matches

        public boolean matches(java.lang.String patternText)
        Description copied from interface: Node

        matches returns true if evaluating the given XPath expression on this node returns a non-empty node set containing this node.

        This method does not behave like the <xsl:if> element - if you want that behaviour, to evaluate if an XPath expression matches something, then you can use the following code to be equivalent...

        if ( node.selectSingleNode( "/some/path" ) != nulll )
        Specified by:
        matches in interface Node
        Parameters:
        patternText - is an XPath expression
        Returns:
        true if this node is returned by the given XPath expression
      • createXPath

        public XPath createXPath(java.lang.String xpathExpression)
        Description copied from interface: Node

        createXPath creates an XPath object for the given xpathExpression. The XPath object allows the variable context to be specified.

        Specified by:
        createXPath in interface Node
        Parameters:
        xpathExpression - is the XPath expression to be evaluated
        Returns:
        an XPath object represeting the given expression
      • createXPathFilter

        public NodeFilter createXPathFilter(java.lang.String patternText)
      • createPattern

        public Pattern createPattern(java.lang.String patternText)
      • asXPathResult

        public Node asXPathResult(Element parent)
        Description copied from interface: Node

        asXPathResult returns a version of this node which is capable of being an XPath result. The result of an XPath expression should always support the parent relationship, whether the original XML tree was singly or doubly linked. If the node does not support the parent relationship then a new node will be created which is linked to its parent and returned.

        Specified by:
        asXPathResult in interface Node
        Parameters:
        parent - DOCUMENT ME!
        Returns:
        a Node which supports the parent relationship
      • createXPathResult

        protected Node createXPathResult(Element parent)