Class SpinXmlElement

  • Direct Known Subclasses:
    DomXmlElement

    public abstract class SpinXmlElement
    extends SpinXmlNode<SpinXmlElement>
    An element in a tree-oriented XML data format.
    Author:
    Sebastian Menski, Daniel Meyer
    • Constructor Detail

      • SpinXmlElement

        public SpinXmlElement()
    • Method Detail

      • hasAttr

        public abstract boolean hasAttr​(java.lang.String attributeName)
        Checks whether this element has a attribute with an empty namespace and the given name.
        Parameters:
        attributeName - the name of the attribute
        Returns:
        true if the element has an attribute with this name under the local namespace, false otherwise
        Throws:
        java.lang.IllegalArgumentException - if the attributeName is null
      • attr

        public abstract SpinXmlAttribute attr​(java.lang.String attributeName)
        Returns the wrapped attribute for an empty namespace and the given name.
        Parameters:
        attributeName - the name of the attribute
        Returns:
        the wrapped attribute
        Throws:
        java.lang.IllegalArgumentException - if the attributeName is null
        SpinXmlAttributeException - if the attribute is not found
      • attr

        public abstract SpinXmlElement attr​(java.lang.String attributeName,
                                            java.lang.String value)
        Sets the attribute value in the local namespace of this element.
        Parameters:
        attributeName - the name of the attribute
        value - the value to set
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the attributeName or value is null
      • removeAttr

        public abstract SpinXmlElement removeAttr​(java.lang.String attributeName)
        Removes the attribute with an empty namespace.
        Parameters:
        attributeName - the name of the attribute
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the attributeName is null
      • hasAttrNs

        public abstract boolean hasAttrNs​(java.lang.String namespace,
                                          java.lang.String attributeName)
        Checks whether this element has a attribute with the given namespace and name.
        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
        Throws:
        java.lang.IllegalArgumentException - if the attributeName is null
      • attrNs

        public abstract SpinXmlAttribute attrNs​(java.lang.String namespace,
                                                java.lang.String attributeName)
        Returns the wrapped attribute for the given namespace and name.
        Parameters:
        namespace - the namespace of the attribute
        attributeName - the name of the attribute
        Returns:
        the wrapped attribute
        Throws:
        java.lang.IllegalArgumentException - if attributeName or value is null
        SpinXmlElementImplementationException - if the attribute cannot be set in the underlying implementation
      • attrNs

        public abstract SpinXmlElement attrNs​(java.lang.String namespace,
                                              java.lang.String attributeName,
                                              java.lang.String value)
        Sets the attribute value in the given namespace.
        Parameters:
        namespace - the namespace of the attribute
        attributeName - the name of the attribute
        value - the value to set
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if attributeName or value is null
        SpinXmlElementImplementationException - if the attribute cannot be set in the underlying implementation
      • removeAttrNs

        public abstract SpinXmlElement removeAttrNs​(java.lang.String namespace,
                                                    java.lang.String attributeName)
        Removes the attribute under the given namespace.
        Parameters:
        namespace - the namespace of the attribute
        attributeName - the name of the attribute
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the attributeName is null
      • attrs

        public abstract SpinList<SpinXmlAttribute> attrs()
        Returns all wrapped attributes of this element.
        Returns:
        the wrapped attributes or an empty list of no attributes are found
      • attrs

        public abstract SpinList<SpinXmlAttribute> attrs​(java.lang.String namespace)
        Returns all wrapped attributes for the given namespace.
        Parameters:
        namespace - the namespace of the attributes
        Returns:
        the wrapped attributes or an empty list of no attributes are found
      • attrNames

        public abstract java.util.List<java.lang.String> attrNames()
        Returns all names of the attributes of this element.
        Returns:
        the names of the attributes
      • attrNames

        public abstract java.util.List<java.lang.String> attrNames​(java.lang.String namespace)
        Returns all names of the attributes in the given namespace.
        Returns:
        the names of the attributes
      • textContent

        public abstract java.lang.String textContent()
        Returns the text content of an element.
        Returns:
        the text content or an empty string if non exists
      • textContent

        public abstract SpinXmlElement textContent​(java.lang.String textContent)
        Sets the text content of an element.
        Parameters:
        textContent - the text content to set
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the textContent is null
      • childElement

        public abstract SpinXmlElement childElement​(java.lang.String elementName)
        Returns a single wrapped child element for the given name in the local namespace of this element.
        Parameters:
        elementName - the element name
        Returns:
        the wrapped child element
        Throws:
        java.lang.IllegalArgumentException - if the elementName is null
        SpinXmlElementException - if none or more than one child element is found
      • childElement

        public abstract SpinXmlElement childElement​(java.lang.String namespace,
                                                    java.lang.String elementName)
        Returns a single wrapped child element for the given namespace and name.
        Parameters:
        namespace - the namespace of the element
        elementName - the element name
        Returns:
        the wrapped child element
        Throws:
        java.lang.IllegalArgumentException - if the elementName is null
        SpinXmlElementException - if none or more than one child element is found
      • childElements

        public abstract SpinList<SpinXmlElement> childElements​(java.lang.String elementName)
        Returns all child elements with a given name in the local namespace of this element.
        Parameters:
        elementName - the element name
        Returns:
        a collection of wrapped elements
        Throws:
        java.lang.IllegalArgumentException - if the element name is null
        SpinXmlElementException - if no child element was found
      • childElements

        public abstract SpinList<SpinXmlElement> childElements​(java.lang.String namespace,
                                                               java.lang.String elementName)
        Returns all child elements with a given namespace and name.
        Parameters:
        namespace - the namespace of the element
        elementName - the element name
        Returns:
        a collection of wrapped elements
        Throws:
        java.lang.IllegalArgumentException - if the element name is null
        SpinXmlElementException - if no child element was found
      • append

        public abstract SpinXmlElement append​(SpinXmlElement... childElements)
        Appends child elements to this element.
        Parameters:
        childElements - the child elements to append
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the childElements is null or one of them
        SpinXmlElementImplementationException - if a child element cannot be appended in the underlying implementation
      • append

        public abstract SpinXmlElement append​(java.util.Collection<SpinXmlElement> childElements)
        Appends child elements to this element.
        Parameters:
        childElements - the child elements to append
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the childElements is null or one of them
        SpinXmlElementImplementationException - if a child element cannot be appended in the underlying implementation
      • appendBefore

        public abstract SpinXmlElement appendBefore​(SpinXmlElement childElement,
                                                    SpinXmlElement existingChildElement)
        Appends a child element to this element before the existing child element.
        Parameters:
        childElement - the child element to append
        existingChildElement - the child element to append before
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the child element or existing child element is null
        SpinXmlElementException - if the existing child element is not a child of this element
        SpinXmlElementImplementationException - if the new child element cannot be inserted in the underlying implementation
      • appendAfter

        public abstract SpinXmlElement appendAfter​(SpinXmlElement childElement,
                                                   SpinXmlElement existingChildElement)
        Appends a child element to this element after the existing child element.
        Parameters:
        childElement - the child element to append
        existingChildElement - the child element to append after
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if the child element or existing child element is null
        SpinXmlElementException - if the existing child element is not a child of this element
        SpinXmlElementImplementationException - if the new child element cannot be inserted in the underlying implementation
      • remove

        public abstract SpinXmlElement remove​(SpinXmlElement... childElements)
        Removes all child elements from this element.
        Parameters:
        childElements - the child elements to remove
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if child elements is null or any of them
        SpinXmlElementException - if one of the child elements does not exist
        SpinXmlElementImplementationException - if the child element cannot be removed in the underlying implementation
      • remove

        public abstract SpinXmlElement remove​(java.util.Collection<SpinXmlElement> childElements)
        Removes all child elements from this element.
        Parameters:
        childElements - the child elements to remove
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if child elements is null or any of them
        SpinXmlElementException - if one of the child elements does not exist
        SpinXmlElementImplementationException - if the child element cannot be removed in the underlying implementation
      • replaceChild

        public abstract SpinXmlElement replaceChild​(SpinXmlElement existingChildElement,
                                                    SpinXmlElement newChildElement)
        Replaces an existing child element with a new one.
        Parameters:
        existingChildElement - the existing child element to replace
        newChildElement - the new child element
        Returns:
        the wrapped element
        Throws:
        java.lang.IllegalArgumentException - if any of the child elements is null
        SpinXmlElementException - if the existing element is not a child element of this
        SpinXmlElementImplementationException - if the child cannot be replaced in the underlying implementation
      • xPath

        public abstract SpinXPathQuery xPath​(java.lang.String expression)
        Creates a XPath query on this element.
        Parameters:
        expression - the XPath expression
        Returns:
        the XPath query
      • toString

        public abstract java.lang.String toString()
        Returns the wrapped XML element as string representation.
        Specified by:
        toString in class Spin<SpinXmlElement>
        Returns:
        the string representation
        Throws:
        SpinXmlElementException - if the element cannot be transformed or no new transformer can be created
      • writeToWriter

        public abstract void writeToWriter​(java.io.Writer writer)
        Writes the wrapped XML element to a existing writer.
        Specified by:
        writeToWriter in class Spin<SpinXmlElement>
        Parameters:
        writer - the writer to write to
        Throws:
        SpinXmlElementException - if the element cannot be transformed or no new transformer can be created