Class DomXmlElement


  • public class DomXmlElement
    extends SpinXmlElement
    Wrapper for an xml dom element.
    Author:
    Sebastian Menski
    • Field Detail

      • cachedTransformer

        protected static javax.xml.transform.Transformer cachedTransformer
      • cachedXPathFactory

        protected static javax.xml.xpath.XPathFactory cachedXPathFactory
      • domElement

        protected final org.w3c.dom.Element domElement
    • Constructor Detail

      • DomXmlElement

        public DomXmlElement​(org.w3c.dom.Element domElement,
                             DomXmlDataFormat dataFormat)
    • Method Detail

      • getDataFormatName

        public java.lang.String getDataFormatName()
        Description copied from class: Spin
        Provides the name of the dataformat used by this spin.
        Specified by:
        getDataFormatName in class Spin<SpinXmlElement>
        Returns:
        the name of the dataformat used by this Spin.
      • unwrap

        public org.w3c.dom.Element unwrap()
        Description copied from class: Spin
        Return the wrapped object. The return type of this method depends on the concrete data format.
        Specified by:
        unwrap in class Spin<SpinXmlElement>
        Returns:
        the object wrapped by this wrapper.
      • name

        public java.lang.String name()
        Description copied from class: SpinXmlNode
        Returns the local name of the node without namespace or prefix.
        Specified by:
        name in class SpinXmlNode<SpinXmlElement>
        Returns:
        the name of the node
      • namespace

        public java.lang.String namespace()
        Description copied from class: SpinXmlNode
        Returns the namespace uri of the node and not the prefix.
        Specified by:
        namespace in class SpinXmlNode<SpinXmlElement>
        Returns:
        the namespace of the node
      • prefix

        public java.lang.String prefix()
        Description copied from class: SpinXmlNode
        Returns the prefix of the node and not the namespace uri.
        Specified by:
        prefix in class SpinXmlNode<SpinXmlElement>
        Returns:
        the prefix of the node
      • hasPrefix

        public boolean hasPrefix​(java.lang.String prefix)
        Description copied from class: SpinXmlNode
        Checks if the node has a given prefix.
        Specified by:
        hasPrefix in class SpinXmlNode<SpinXmlElement>
        Parameters:
        prefix - the prefix to check
        Returns:
        true if the name has the same prefix
      • hasNamespace

        public boolean hasNamespace​(java.lang.String namespace)
        Description copied from class: SpinXmlNode
        Checks if the node has a given namespace.
        Specified by:
        hasNamespace in class SpinXmlNode<SpinXmlElement>
        Parameters:
        namespace - the namespace to check
        Returns:
        true if the node has the same namespace
      • attr

        public SpinXmlAttribute attr​(java.lang.String attributeName)
        Description copied from class: SpinXmlElement
        Returns the wrapped attribute for an empty namespace and the given name.
        Specified by:
        attr in class SpinXmlElement
        Parameters:
        attributeName - the name of the attribute
        Returns:
        the wrapped attribute
      • attrNs

        public SpinXmlAttribute attrNs​(java.lang.String namespace,
                                       java.lang.String attributeName)
        Description copied from class: SpinXmlElement
        Returns the wrapped attribute for the given namespace and name.
        Specified by:
        attrNs in class SpinXmlElement
        Parameters:
        namespace - the namespace of the attribute
        attributeName - the name of the attribute
        Returns:
        the wrapped attribute
      • hasAttr

        public boolean hasAttr​(java.lang.String attributeName)
        Description copied from class: SpinXmlElement
        Checks whether this element has a attribute with an empty namespace and the given name.
        Specified by:
        hasAttr in class SpinXmlElement
        Parameters:
        attributeName - the name of the attribute
        Returns:
        true if the element has an attribute with this name under the local namespace, false otherwise
      • hasAttrNs

        public boolean hasAttrNs​(java.lang.String namespace,
                                 java.lang.String attributeName)
        Description copied from class: SpinXmlElement
        Checks whether this element has a attribute with the given namespace and name.
        Specified by:
        hasAttrNs in class SpinXmlElement
        Parameters:
        namespace - the namespace of the attribute
        attributeName - the name of the attribute
        Returns:
        true if the element has an attribute with this name under given namespace, false otherwise
      • attrs

        public SpinList<SpinXmlAttribute> attrs​(java.lang.String namespace)
        Description copied from class: SpinXmlElement
        Returns all wrapped attributes for the given namespace.
        Specified by:
        attrs in class SpinXmlElement
        Parameters:
        namespace - the namespace of the attributes
        Returns:
        the wrapped attributes or an empty list of no attributes are found
      • attrNames

        public java.util.List<java.lang.String> attrNames()
        Description copied from class: SpinXmlElement
        Returns all names of the attributes of this element.
        Specified by:
        attrNames in class SpinXmlElement
        Returns:
        the names of the attributes
      • attrNames

        public java.util.List<java.lang.String> attrNames​(java.lang.String namespace)
        Description copied from class: SpinXmlElement
        Returns all names of the attributes in the given namespace.
        Specified by:
        attrNames in class SpinXmlElement
        Returns:
        the names of the attributes
      • textContent

        public java.lang.String textContent()
        Description copied from class: SpinXmlElement
        Returns the text content of an element.
        Specified by:
        textContent in class SpinXmlElement
        Returns:
        the text content or an empty string if non exists
      • childElement

        public SpinXmlElement childElement​(java.lang.String elementName)
        Description copied from class: SpinXmlElement
        Returns a single wrapped child element for the given name in the local namespace of this element.
        Specified by:
        childElement in class SpinXmlElement
        Parameters:
        elementName - the element name
        Returns:
        the wrapped child element
      • childElement

        public SpinXmlElement childElement​(java.lang.String namespace,
                                           java.lang.String elementName)
        Description copied from class: SpinXmlElement
        Returns a single wrapped child element for the given namespace and name.
        Specified by:
        childElement in class SpinXmlElement
        Parameters:
        namespace - the namespace of the element
        elementName - the element name
        Returns:
        the wrapped child element
      • childElements

        public SpinList<SpinXmlElement> childElements​(java.lang.String namespace,
                                                      java.lang.String elementName)
        Description copied from class: SpinXmlElement
        Returns all child elements with a given namespace and name.
        Specified by:
        childElements in class SpinXmlElement
        Parameters:
        namespace - the namespace of the element
        elementName - the element name
        Returns:
        a collection of wrapped elements
      • attr

        public SpinXmlElement attr​(java.lang.String attributeName,
                                   java.lang.String value)
        Description copied from class: SpinXmlElement
        Sets the attribute value in the local namespace of this element.
        Specified by:
        attr in class SpinXmlElement
        Parameters:
        attributeName - the name of the attribute
        value - the value to set
        Returns:
        the wrapped element
      • attrNs

        public SpinXmlElement attrNs​(java.lang.String namespace,
                                     java.lang.String attributeName,
                                     java.lang.String value)
        Description copied from class: SpinXmlElement
        Sets the attribute value in the given namespace.
        Specified by:
        attrNs in class SpinXmlElement
        Parameters:
        namespace - the namespace of the attribute
        attributeName - the name of the attribute
        value - the value to set
        Returns:
        the wrapped element
      • removeAttr

        public SpinXmlElement removeAttr​(java.lang.String attributeName)
        Description copied from class: SpinXmlElement
        Removes the attribute with an empty namespace.
        Specified by:
        removeAttr in class SpinXmlElement
        Parameters:
        attributeName - the name of the attribute
        Returns:
        the wrapped element
      • removeAttrNs

        public SpinXmlElement removeAttrNs​(java.lang.String namespace,
                                           java.lang.String attributeName)
        Description copied from class: SpinXmlElement
        Removes the attribute under the given namespace.
        Specified by:
        removeAttrNs in class SpinXmlElement
        Parameters:
        namespace - the namespace of the attribute
        attributeName - the name of the attribute
        Returns:
        the wrapped element
      • xPath

        public SpinXPathQuery xPath​(java.lang.String expression)
        Description copied from class: SpinXmlElement
        Creates a XPath query on this element.
        Specified by:
        xPath in class SpinXmlElement
        Parameters:
        expression - the XPath expression
        Returns:
        the XPath query
      • adoptElement

        protected void adoptElement​(DomXmlElement elementToAdopt)
        Adopts an xml dom element to the owner document of this element if necessary.
        Parameters:
        elementToAdopt - the element to adopt
      • toString

        public java.lang.String toString()
        Description copied from class: SpinXmlElement
        Returns the wrapped XML element as string representation.
        Specified by:
        toString in class SpinXmlElement
        Returns:
        the string representation
      • writeToWriter

        public void writeToWriter​(java.io.Writer writer)
        Description copied from class: SpinXmlElement
        Writes the wrapped XML element to a existing writer.
        Specified by:
        writeToWriter in class SpinXmlElement
        Parameters:
        writer - the writer to write to
      • getXPathFactory

        protected javax.xml.xpath.XPathFactory getXPathFactory()
        Returns a XPath Factory
        Returns:
        the XPath factory
      • mapTo

        public <C> C mapTo​(java.lang.Class<C> javaClass)
        Description copied from class: SpinXmlNode
        Maps XML into specific class
        Specified by:
        mapTo in class SpinXmlNode<SpinXmlElement>
        Parameters:
        javaClass - Class to which the Xml should be mapped
        Returns:
        mapped Class
      • mapTo

        public <C> C mapTo​(java.lang.String javaClass)
        Description copied from class: SpinXmlNode
        Maps Xml into specific class
        Specified by:
        mapTo in class SpinXmlNode<SpinXmlElement>
        Parameters:
        javaClass - canonical name of the class
        Returns:
        mapped class