Class ElementImpl

  • All Implemented Interfaces:
    NodeInfo, javax.xml.transform.dom.DOMLocator, javax.xml.transform.Source, javax.xml.transform.SourceLocator, org.w3c.dom.Element, org.w3c.dom.Node
    Direct Known Subclasses:
    ElementWithAttributes

    public class ElementImpl
    extends ParentNodeImpl
    implements org.w3c.dom.Element
    ElementImpl implements an element with no attributes or namespace declarations.

    This class is an implementation of NodeInfo. For elements with attributes or namespace declarations, class ElementWithAttributes is used.

    Author:
    Michael H. Kay
    • Field Detail

      • nameCode

        protected int nameCode
    • Constructor Detail

      • ElementImpl

        public ElementImpl()
        Construct an empty ElementImpl
    • Method Detail

      • setNameCode

        public void setNameCode​(int nameCode)
        Set the name code. Used when creating a dummy element in the Stripper
      • initialise

        public void initialise​(int nameCode,
                               AttributeCollection atts,
                               NodeInfo parent,
                               java.lang.String baseURI,
                               int lineNumber,
                               int sequenceNumber)
        Initialise a new ElementImpl with an element name
        Parameters:
        name - The element name, with namespaces resolved
        atts - The attribute list: always null
        parent - The parent node
      • setSystemId

        public void setSystemId​(java.lang.String uri)
        Set the system ID of this node. This method is provided so that a NodeInfo implements the javax.xml.transform.Source interface, allowing a node to be used directly as the Source of a transformation
        Specified by:
        setSystemId in interface javax.xml.transform.Source
        Overrides:
        setSystemId in class NodeImpl
      • getSystemId

        public final java.lang.String getSystemId()
        Get the system ID of the entity containing this element node.
        Specified by:
        getSystemId in interface NodeInfo
        Specified by:
        getSystemId in interface javax.xml.transform.Source
        Specified by:
        getSystemId in interface javax.xml.transform.SourceLocator
        Overrides:
        getSystemId in class NodeImpl
        Returns:
        the System Identifier of the entity in the source document containing the node, or null if not known. Note this is not the same as the base URI: the base URI can be modified by xml:base, but the system ID cannot.
      • getBaseURI

        public java.lang.String getBaseURI()
        Get the base URI of this element node. This will be the same as the System ID unless xml:base has been used.
        Specified by:
        getBaseURI in interface org.w3c.dom.Node
        Specified by:
        getBaseURI in interface NodeInfo
        Overrides:
        getBaseURI in class NodeImpl
      • setLineNumber

        public void setLineNumber​(int line)
        Set the line number of the element within its source document entity
      • getLineNumber

        public int getLineNumber()
        Get the line number of the node within its source document entity
        Specified by:
        getLineNumber in interface NodeInfo
        Specified by:
        getLineNumber in interface javax.xml.transform.SourceLocator
        Overrides:
        getLineNumber in class NodeImpl
        Returns:
        the line number of the node in its original source document; or -1 if not available
      • generateId

        public java.lang.String generateId()
        Get a character string that uniquely identifies this node within this document (The calling code will prepend a document identifier)
        Specified by:
        generateId in interface NodeInfo
        Overrides:
        generateId in class NodeImpl
        Returns:
        a string.
      • getURICodeForPrefix

        public short getURICodeForPrefix​(java.lang.String prefix)
                                  throws NamespaceException
        Search the NamespaceList for a given prefix, returning the corresponding URI.
        Parameters:
        prefix - The prefix to be matched. To find the default namespace, supply ""
        Returns:
        The URI code corresponding to this namespace. If it is an unnamed default namespace, return Namespace.NULL_CODE.
        Throws:
        NamespaceException - if the prefix has not been declared on this NamespaceList.
      • getPrefixForURI

        public java.lang.String getPrefixForURI​(java.lang.String uri)
        Search the NamespaceList for a given URI, returning the corresponding prefix.
        Parameters:
        uri - The URI to be matched.
        Returns:
        The prefix corresponding to this URI. If not found, return null. If there is more than one prefix matching the URI, the first one found is returned. If the URI matches the default namespace, return an empty string.
      • makeNameCode

        public final int makeNameCode​(java.lang.String qname,
                                      boolean useDefault)
                               throws NamespaceException
        Make a NameCode, using this Element as the context for namespace resolution. The name will be entered in the namepool: therefore this method should not be called once the name pool is sealed.
        Parameters:
        qname - The name as written, in the form "[prefix:]localname"
        Throws:
        NamespaceException
      • addNamespaceNodes

        public void addNamespaceNodes​(ElementImpl owner,
                                      java.util.Vector list,
                                      boolean addXML)
        Make the set of all namespace nodes associated with this element.
        Parameters:
        owner - The element owning these namespace nodes.
        list - a Vector containing NamespaceImpl objects representing the namespaces in scope for this element; the method appends nodes to this Vector, which should initially be empty. Note that the returned list will never contain the XML namespace (to get this, the NamespaceEnumeration class adds it itself). The list WILL include an entry for the undeclaration xmlns=""; again it is the job of NamespaceEnumeration to ignore this, since it doesn't represent a true namespace node.
        addXML - Add the XML namespace node to the list
      • outputNamespaceNodes

        public void outputNamespaceNodes​(Outputter out,
                                         boolean includeAncestors)
                                  throws javax.xml.transform.TransformerException
        Output all namespace nodes associated with this element.
        Specified by:
        outputNamespaceNodes in interface NodeInfo
        Overrides:
        outputNamespaceNodes in class NodeImpl
        Parameters:
        out - The relevant outputter
        includeAncestors - True if namespaces declared on ancestor elements must be output; false if it is known that these are already on the result tree
        Throws:
        javax.xml.transform.TransformerException
      • getNodeType

        public final short getNodeType()
        Return the type of node.
        Specified by:
        getNodeType in interface org.w3c.dom.Node
        Specified by:
        getNodeType in interface NodeInfo
        Returns:
        NodeInfo.ELEMENT
      • getAttributeList

        public AttributeCollection getAttributeList()
        Get the attribute list for this element.
        Returns:
        The attribute list. This will not include any namespace attributes. The attribute names will be in expanded form, with prefixes replaced by URIs
      • getAttributeValue

        public java.lang.String getAttributeValue​(java.lang.String name)
        Find the value of a given attribute of this element.
        This is a short-cut method; the full capability to examine attributes is offered via the getAttributeList() method.
        The attribute may either be one that was present in the original XML document, or one that has been set by the application using setAttribute().
        Parameters:
        name - the name of an attribute. There must be no prefix in the name.
        Returns:
        the value of the attribute, if it exists, otherwise null
      • setAttribute

        public void setAttribute​(java.lang.String name,
                                 java.lang.String value)
                          throws org.w3c.dom.DOMException
        Set the value of an attribute on the current element.
        Specified by:
        setAttribute in interface org.w3c.dom.Element
        Throws:
        org.w3c.dom.DOMException - (always): the Saxon tree is immutable
      • copy

        public void copy​(Outputter out)
                  throws javax.xml.transform.TransformerException
        Copy this node to a given outputter (supporting xsl:copy-of)
        Specified by:
        copy in interface NodeInfo
        Throws:
        javax.xml.transform.TransformerException
      • copy

        public void copy​(Outputter out,
                         boolean allNamespaces)
                  throws javax.xml.transform.TransformerException
        Copy this node to a given outputter (supporting xsl:copy-of)
        Parameters:
        out - The outputter
        allNamespaces - true if namespaces for ancestor nodes must be output
        Throws:
        javax.xml.transform.TransformerException