Class AbstractDocument

    • Field Detail

      • encoding

        protected java.lang.String encoding
        The encoding of this document as stated in the XML declaration
    • Constructor Detail

      • AbstractDocument

        public AbstractDocument()
    • 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
        Overrides:
        getNodeType in class AbstractNode
        Returns:
        a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE
      • getPath

        public java.lang.String getPath(Element context)
        Description copied from interface: Node
        Returns the relative 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
        Parameters:
        context - is the parent context from which the relative path should start. If the context is null or the context is not an ancestor of this node then the path will be absolute and start from the document and so begin with the '/' character.
        Returns:
        the XPath expression relative to the given context which will return a nodeset containing at least this node.
      • getUniquePath

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

        Returns the relative unique XPath expression from the given context 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
        Parameters:
        context - is the parent context from which the path should start. If the context is null or the context is not an ancestor of this node then the path will start from the document and so begin with the '/' character.
        Returns:
        the XPath expression relative to the given context which will return a nodeset containing just this node.
      • 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
        Overrides:
        getDocument in class AbstractNode
        Returns:
        the document of this node or null if this feature is not supported or the node is not associated with a Document
      • getXMLEncoding

        public java.lang.String getXMLEncoding()
        Description copied from interface: Document
        Return the encoding of this document, as part of the XML declaration This is null when unspecified or when it is not known (such as when the Document was created in memory) or when the implementation does not support this operation. The way this encoding is retrieved also depends on the way the XML source is parsed. For instance, if the SAXReader is used and if the underlying XMLReader implementation support the org.xml.sax.ext.Locator2 interface, the result returned by this method is specified by the getEncoding() method of that interface.
        Specified by:
        getXMLEncoding in interface Document
        Returns:
        The encoding of this document, as stated in the XML declaration, or null if unknown.
      • 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
        Overrides:
        getStringValue in class AbstractNode
        Returns:
        the text from all the child Text and Element nodes appended together.
      • asXML

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

        asXML returns the textual XML representation of this node.

        Specified by:
        asXML in interface Node
        Returns:
        the XML representation of this node
      • write

        public void write(java.io.Writer out)
                   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
        Overrides:
        write in class AbstractNode
        Parameters:
        out - is the Writer to output the XML to
        Throws:
        java.io.IOException - DOCUMENT ME!
      • accept

        public void accept(Visitor visitor)

        accept method is the Visitor Pattern method.

        Specified by:
        accept in interface Node
        Parameters:
        visitor - Visitor is the visitor.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • normalize

        public void normalize()
        Description copied from interface: Branch
        Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.
        Specified by:
        normalize in interface Branch
      • addComment

        public Document addComment(java.lang.String comment)
        Description copied from interface: Document
        Adds a new Comment node with the given text to this branch.
        Specified by:
        addComment in interface Document
        Parameters:
        comment - is the text for the Comment node.
        Returns:
        this Document instance.
      • addProcessingInstruction

        public Document addProcessingInstruction(java.lang.String target,
                                                 java.lang.String data)
        Description copied from interface: Document
        Adds a processing instruction for the given target
        Specified by:
        addProcessingInstruction in interface Document
        Parameters:
        target - is the target of the processing instruction
        data - is the textual data (key/value pairs) of the processing instruction
        Returns:
        this Document instance.
      • addProcessingInstruction

        public Document addProcessingInstruction(java.lang.String target,
                                                 java.util.Map<java.lang.String,java.lang.String> data)
        Description copied from interface: Document
        Adds a processing instruction for the given target
        Specified by:
        addProcessingInstruction in interface Document
        Parameters:
        target - is the target of the processing instruction
        data - is a Map of the key / value pairs of the processing instruction
        Returns:
        this Document instance.
      • addElement

        public Element addElement(java.lang.String name)
        Description copied from interface: Branch
        Adds a new Element node with the given name to this branch and returns a reference to the new node.
        Specified by:
        addElement in interface Branch
        Overrides:
        addElement in class AbstractBranch
        Parameters:
        name - is the name for the Element node.
        Returns:
        the newly added Element node.
      • addElement

        public Element addElement(java.lang.String qualifiedName,
                                  java.lang.String namespaceURI)
        Description copied from interface: Branch
        Adds a new Element node with the given qualified name and namespace URI to this branch and returns a reference to the new node.
        Specified by:
        addElement in interface Branch
        Overrides:
        addElement in class AbstractBranch
        Parameters:
        qualifiedName - is the fully qualified name of the Element
        namespaceURI - is the URI of the namespace to use
        Returns:
        the newly added Element node.
      • addElement

        public Element addElement(QName qName)
        Description copied from interface: Branch
        Adds a new Element node with the given QNameto this branch and returns a reference to the new node.
        Specified by:
        addElement in interface Branch
        Overrides:
        addElement in class AbstractBranch
        Parameters:
        qName - is the qualified name for the Element node.
        Returns:
        the newly added Element node.
      • setRootElement

        public void setRootElement(Element rootElement)
        Description copied from interface: Document
        Sets the root element for this document
        Specified by:
        setRootElement in interface Document
        Parameters:
        rootElement - the new root element for this document
      • add

        public void add(Element element)
        Description copied from interface: Branch
        Adds the given Element to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.
        Specified by:
        add in interface Branch
        Overrides:
        add in class AbstractBranch
        Parameters:
        element - is the element to be added
      • remove

        public boolean remove(Element element)
        Description copied from interface: Branch
        Removes the given Element if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node.detach()method should be used instead.
        Specified by:
        remove in interface Branch
        Overrides:
        remove in class AbstractBranch
        Parameters:
        element - is the element to be removed
        Returns:
        true if the element was removed
      • 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
        Overrides:
        asXPathResult in class AbstractNode
        Parameters:
        parent - DOCUMENT ME!
        Returns:
        a Node which supports the parent relationship
      • childAdded

        protected void childAdded(Node node)
        Description copied from class: AbstractBranch
        Called when a new child node has been added to me to allow any parent relationships to be created or events to be fired.
        Specified by:
        childAdded in class AbstractBranch
        Parameters:
        node - DOCUMENT ME!
      • childRemoved

        protected void childRemoved(Node node)
        Description copied from class: AbstractBranch
        Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.
        Specified by:
        childRemoved in class AbstractBranch
        Parameters:
        node - DOCUMENT ME!
      • checkAddElementAllowed

        protected void checkAddElementAllowed(Element element)
      • rootElementAdded

        protected abstract void rootElementAdded(Element rootElement)
        Called to set the root element variable
        Parameters:
        rootElement - DOCUMENT ME!
      • setXMLEncoding

        public void setXMLEncoding(java.lang.String enc)
        Description copied from interface: Document
        Sets the encoding of this document as it will appear in the XML declaration part of the document.
        Specified by:
        setXMLEncoding in interface Document
        Parameters:
        enc - the encoding of the document