Class XmlElement

    • Field Detail

      • name

        private java.lang.String name
    • Constructor Detail

      • XmlElement

        XmlElement​(XmlElement parent,
                   java.lang.String name,
                   XmlAttribute[] attributes,
                   org.w3c.dom.Node node)
        Creates a new XML element fragment artifact.
        Parameters:
        parent - the parent artifact
        name - the name of the element
        attributes - the attributes
        node - the node that is represented by this XmlElement
    • Method Detail

      • create

        public static XmlElement create​(XmlElement parent,
                                        java.lang.String name,
                                        java.lang.String contents)
                                 throws VilException
        Creates a new XmlElement as child of given parent, with given name.
        Parameters:
        parent - The parent of the new XmlElement.
        name - The name of the new XmlElement.
        contents - optional initial contents, ignored if empty
        Returns:
        The created XmlElement.
        Throws:
        VilException - if element could not be created.
      • create

        public static XmlElement create​(XmlFileArtifact parent,
                                        java.lang.String name,
                                        java.lang.String contents)
                                 throws VilException
        Creates a new XmlElement as child of the root element of the given file artifact, with given name.
        Parameters:
        parent - The parent of the new XmlElement.
        name - The name of the new XmlElement.
        contents - optional initial contents, ignored if empty
        Returns:
        The created XmlElement.
        Throws:
        VilException - if element could not be created.
      • buildElement

        public static XmlElement buildElement​(XmlElement parent,
                                              java.lang.String name,
                                              java.lang.String contents)
                                       throws VilException
        Creates a new XmlElement as child of given parent, with given name, but returns the parent element.
        Parameters:
        parent - The parent of the new XmlElement.
        name - The name of the new XmlElement.
        contents - optional initial contents, ignored if empty
        Returns:
        parent (element builder style)
        Throws:
        VilException - if element could not be created.
      • buildAttribute

        public static XmlElement buildAttribute​(XmlElement parent,
                                                java.lang.String name,
                                                java.lang.String value)
                                         throws VilException
        Creates a new Attribute for given XmlElement, with given name and value, but returns the parent XML element.
        Parameters:
        parent - The XmlElement the attribute is for.
        name - The name of the new attribute.
        value - The value of the new attribute.
        Returns:
        parent (element builder style)
        Throws:
        VilException - if attribute could not be created.
      • buildAttribute

        public static XmlElement buildAttribute​(XmlElement parent,
                                                java.lang.String name,
                                                java.lang.String value,
                                                boolean forceOverwrite)
                                         throws VilException
        Creates a new Attribute for given XmlElement, with given name and value, but returns the parent. Overwrites by default.
        Parameters:
        parent - The XmlElement the attribute is for.
        name - The name of the attribute.
        value - The value of the new attribute.
        forceOverwrite - True if existing attributes with same name shall be overwritten. Default = true.
        Returns:
        parent (element builder style)
        Throws:
        VilException - if attribute could not be created for different reason then pre-existance.
      • findField

        private java.lang.reflect.Field findField​(java.lang.Class<?> cls,
                                                  java.lang.String name)
        Findes a field called name in cls or one of its super classes except for Object (not needed here).
        Parameters:
        cls - the class to search
        name - the name of the field
        Returns:
        the field or null if not found
      • sortAttributes

        void sortAttributes​(org.xml.sax.Attributes att)
        Sorts the attribute sequence of this element according to the given SAX attribute set.
        Overrides:
        sortAttributes in class XmlNode
        Parameters:
        att - the SAX attributes
      • synchronizeAttributeSequence

        void synchronizeAttributeSequence()
        Synchronizes the attribute sequence. This is a horrible hack. Reason: Extending JDK-Xalan is not really possible (restricted access, implementation requires certain class hierarchy preventing delegation) and we do not want to extend the EASy deployment by Eclipse-Xalan and its dependency. So access the attribute implementation and sort the nodes in there accordingly.
        Overrides:
        synchronizeAttributeSequence in class XmlNode
      • logSequenceException

        private void logSequenceException​(java.lang.String text,
                                          java.lang.Exception ex)
        Logs a sequence synchronization exception.
        Parameters:
        text - the text indicating the problem stated by the exception
        ex - the exception detailing the problem (may be null)
      • deleteChild

        void deleteChild​(XmlNode child)
        Description copied from class: XmlNode
        Removes a child from this Element.
        Specified by:
        deleteChild in class XmlNode
        Parameters:
        child - the child that is to be removed.
      • getName

        public java.lang.String getName()
                                 throws VilException
        Description copied from interface: IArtifact
        Returns the name of this artifact.
        Specified by:
        getName in interface IArtifact
        Returns:
        the name of this artifact
        Throws:
        VilException - in case of serious problems so that this operation cannot continue
      • getNameSafe

        java.lang.String getNameSafe()
        Description copied from class: XmlNode
        Returns the name of this attribute without potential exception.
        Overrides:
        getNameSafe in class XmlNode
        Returns:
        the name
      • rename

        public void rename​(java.lang.String name)
                    throws VilException
        Description copied from interface: IArtifact
        Renames this artifact.
        Specified by:
        rename in interface IArtifact
        Parameters:
        name - the new name of this artifact
        Throws:
        VilException - in case of serious problems so that this operation cannot continue
      • exists

        public boolean exists()
        Description copied from interface: IArtifact
        Returns whether this artifact is exists.
        Specified by:
        exists in interface IArtifact
        Overrides:
        exists in class FragmentArtifact
        Returns:
        true if this artifact exists, false else
      • nodes

        public Set<XmlNode> nodes()
                           throws VilException
        Returns all nested nodes in sequence.
        Returns:
        the nodes
        Throws:
        VilException - in case that access is not possible
      • comments

        public Sequence<XmlComment> comments()
        Returns all nested comments in sequence.
        Returns:
        the elements
        Throws:
        VilException - in case that access is not possible
      • projectNodes

        private <T> Sequence<T> projectNodes​(java.lang.Class<? extends T> type)
        Projects nodes to a node type.
        Type Parameters:
        T - the target element type
        Parameters:
        type - the type to project to
        Returns:
        the projected elements (may be empty)
      • getAttribute

        public XmlAttribute getAttribute​(java.lang.String name)
                                  throws VilException
        Returns a specific attribute.
        Parameters:
        name - the name of the attribute (may be a regular expression)
        Returns:
        the attribute or null if there is none
        Throws:
        VilException - in case of already deleted attributes
      • setAttribute

        public void setAttribute​(java.lang.String name,
                                 java.lang.String value)
                          throws VilException
        Directly modifies an attribute. [convenience]
        Parameters:
        name - the name of the attribute
        value - the new value of the attribute
        Throws:
        VilException - in case that the attribute cannot be found
      • selectAttributeByRegex

        public Set<XmlAttribute> selectAttributeByRegex​(java.lang.String regEx)
                                                 throws VilException
        Returns a specific attribute.
        Parameters:
        regEx - a regular expression specifying the attributes to be selected
        Returns:
        the set of attribute, being empty if there is none
        Throws:
        VilException - in case that regEx is invalid
      • selectByName

        public Set<XmlElement> selectByName​(java.lang.String name)
                                     throws VilException
        Description copied from interface: IXmlContainer
        Returns a Set with all XmlElements matching name. Childs are processed aswell.
        Uses case sensitivity by default.
        Specified by:
        selectByName in interface IXmlContainer
        Parameters:
        name - The required name.
        Returns:
        set with matching XmlElements.
        Throws:
        VilException - in case that invalid Elements are used.
      • selectByPath

        public Set<XmlElement> selectByPath​(java.lang.String path)
                                     throws VilException
        Description copied from interface: IXmlContainer
        Selects XML elements according to a given path. We may go for XPath expressions in future.
        Specified by:
        selectByPath in interface IXmlContainer
        Parameters:
        path - the path to the elements
        Returns:
        the matching elements (may be empty)
        Throws:
        VilException - in case invalid XmlElements are used.
      • selectByXPath

        public Set<XmlElement> selectByXPath​(java.lang.String path)
                                      throws VilException
        Description copied from interface: IXmlContainer
        Selects XML elements according to a given XPath.
        Specified by:
        selectByXPath in interface IXmlContainer
        Parameters:
        path - the XPath to the elements
        Returns:
        the matching elements (may be empty)
        Throws:
        VilException - in case invalid XmlElements are used.
      • selectByName

        public Set<XmlElement> selectByName​(java.lang.String name,
                                            boolean caseSensitive)
                                     throws VilException
        Returns a Set with all XmlElements matching name. Childs are processed aswell.
        Case sensitivity can be set.
        Parameters:
        name - The required name.
        caseSensitive - True if case-sensitive, false otherwise.
        Returns:
        set with matching XmlElements.
        Throws:
        VilException - in case that invalid Elements are used.
      • selectByRegEx

        public Set<XmlElement> selectByRegEx​(java.lang.String regEx)
                                      throws VilException
        Returns a set of all XmlElements specified by regEx. Childs are processed aswell.

        To get a set of all XmlElements having a certain pre- and suffix use:
        prefix.*suffix (replace prefix and suffix).
        To enable case insensitivity use (?i) :
        (?i) cASe iS noT imPORtaNt
        Parameters:
        regEx - a regular expression specifying the elements to be selected
        Returns:
        Set of XmlElements matching the regEx.
        Throws:
        VilException - in case that invalid Elements are used.
      • deleteAttribute

        void deleteAttribute​(XmlAttribute attribute)
        Deletes an attribute (internal function, called from attribute).
        Parameters:
        attribute - the attribute to be deleted.
      • renameAttribute

        void renameAttribute​(XmlAttribute attribute,
                             java.lang.String name)
                      throws VilException
        Renames an Attribute (internal called from XmlAttribute).
        Parameters:
        attribute - the attribute to be renamed.
        name - the new name of this attribute
        Throws:
        VilException - in case that invalid attributes are used
      • setName

        void setName​(java.lang.String name)
        Changes the name of this element.
        Parameters:
        name - the new name of this element.
      • setNodes

        void setNodes​(XmlNode[] nodes)
        Replaces the child nodes of this element.
        Parameters:
        nodes - An array with all child nodes.
      • hasChild

        boolean hasChild​(XmlElement child)
        Checks whether this element has child as a child.
        Parameters:
        child - the child element to check for.
        Returns:
        true if child is a child. false otherwise.
      • addChild

        void addChild​(XmlNode child)
               throws VilException
        Adds a child XmlElement to this XmlElement.
        Parameters:
        child - The new child.
        Throws:
        VilException - If child could not be added.
      • appendChild

        XmlElement appendChild​(XmlElement child,
                               org.w3c.dom.Node childNode)
                        throws VilException
        Appends a new child. Default position is after last child of the parent.
        Parameters:
        child - The new child XmlElement.
        childNode - The new child Node.
        Returns:
        The created XmlElement.
        Throws:
        VilException - If child could not be appended.
      • addAttribute

        XmlAttribute addAttribute​(java.lang.String name,
                                  java.lang.String value)
                           throws VilException
        Adds an attribute to this XmlElement.
        Parameters:
        name - The name of the new attribute.
        value - The value of the new attribute.
        Returns:
        The created attribute.
        Throws:
        VilException - If attribute could not be added.
      • addAttribute

        XmlAttribute addAttribute​(java.lang.String name,
                                  java.lang.String value,
                                  boolean forceOverwrite)
                           throws VilException
        Adds an attribute to this XmlElement. Overwrites by default.
        Parameters:
        name - The name of the new attribute.
        value - The value of the new attribute.
        forceOverwrite - True if existing attributes with same name shall be overwritten. Default = true.
        Returns:
        The created attribute.
        Throws:
        VilException - If attribute could not be added.
      • insertElement

        private void insertElement​(XmlNode elem,
                                   XmlNode previous)
                            throws VilException
        Inserts an XmlElement at a certain position.
        Parameters:
        elem - The XmlElement that is to be inserted.
        previous - The XmlElement previous to the new XmlElement. If null, XmlElement will be inserted as first.
        Throws:
        VilException - if XmlElement could not be inserted for whatever reason.
      • getStringValue

        public java.lang.String getStringValue​(IStringValueProvider.StringComparator comparator)
        Description copied from interface: IStringValueProvider
        Returns the string value of this object.
        Specified by:
        getStringValue in interface IStringValueProvider
        Parameters:
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value
      • getChildCount

        int getChildCount()
        Description copied from class: XmlNode
        Returns the number of children.
        Overrides:
        getChildCount in class XmlNode
        Returns:
        the number of children
      • getChild

        XmlNode getChild​(int index)
        Description copied from class: XmlNode
        Returns the child at the given index.
        Overrides:
        getChild in class XmlNode
        Parameters:
        index - the 0-based index of the child to return
        Returns:
        the child