Class XMLDocumentUtility


  • public class XMLDocumentUtility
    extends Object
    An xml document utility. Provides some usefull methods to simplify manipulation with the XML file(s).
    Author:
    martin
    • Constructor Detail

      • XMLDocumentUtility

        public XMLDocumentUtility​(String nsName,
                                  String nsURL)
        Creates instance for the given xml namespace.
        Parameters:
        nsName -
        nsURL -
    • Method Detail

      • register

        public void register​(Element elem)
                      throws XSPFException
        Registers given element to this utility (populates he namespace).
        Parameters:
        elem -
        Throws:
        XSPFException
      • listChildrenElems

        public java.util.stream.Stream<Element> listChildrenElems​(Node container)
                                                           throws XSPFException
        Lists all the children of the given container node (element or document).
        Parameters:
        container -
        Returns:
        Throws:
        XSPFException
      • listChildrenElems

        public java.util.stream.Stream<Element> listChildrenElems​(Node container,
                                                                  String elemName)
                                                           throws XSPFException
        Lists the children of the given name of the given container node (element or document).
        Parameters:
        container -
        elemName -
        Returns:
        Throws:
        XSPFException
      • listChildrenElemsClones

        public java.util.stream.Stream<Element> listChildrenElemsClones​(Node container,
                                                                        String elemName)
                                                                 throws XSPFException
        Lists the copies of the children of the given name of the given container node (element or document).
        Parameters:
        container -
        elemName -
        Returns:
        Throws:
        XSPFException
      • getChildElemOrNull

        public Element getChildElemOrNull​(Node owner,
                                          String elemName)
                                   throws XSPFException
        Returns the child element of the given name of the given owner. Returns null if none, fails if more.
        Parameters:
        owner -
        elemName -
        Returns:
        Throws:
        XSPFException
      • getOrCreateChildElem

        public Element getOrCreateChildElem​(Node owner,
                                            String elemName)
                                     throws XSPFException
        Returns the child element of the given name of the given owner. Creates and returns if none.
        Parameters:
        owner -
        elemName -
        Returns:
        Throws:
        XSPFException
      • getChildElemCloneOrNull

        public Element getChildElemCloneOrNull​(Node owner,
                                               String elemName)
                                        throws XSPFException
        Returns the copy of the child element of the given name of the given owner. Returns null if none, fails if more.
        Parameters:
        owner -
        elemName -
        Returns:
        Throws:
        XSPFException
      • getElemClone

        public Element getElemClone​(Element elem)
        Returns the copy of the given element.
        Parameters:
        elem -
        Returns:
      • removeChildElement

        public void removeChildElement​(Node owner,
                                       String elemName)
                                throws XSPFException
        Removes one child element of the given name of the given owner. Fails if none or more.
        Parameters:
        owner -
        elemName -
        Throws:
        XSPFException
      • removeChildElements

        public void removeChildElements​(Node owner,
                                        String elemName)
                                 throws XSPFException
        Removes all child elements of the given name of the given owner.
        Parameters:
        owner -
        elemName -
        Throws:
        XSPFException
      • replaceChildElement

        public void replaceChildElement​(Node owner,
                                        String elemName,
                                        Element replacement)
                                 throws XSPFException
        Replaces one child element of the given name of the given owner with the another one. If none just adds, fails if more.
        Parameters:
        owner -
        elemName -
        replacement -
        Throws:
        XSPFException
      • replaceChildElements

        public void replaceChildElements​(Node owner,
                                         String elemName,
                                         java.util.stream.Stream<Element> replacements)
                                  throws XSPFException
        Replaces all child elements of the given name of the given owner with the another ones.
        Parameters:
        owner -
        elemName -
        replacements -
        Throws:
        XSPFException
      • replaceChildElementByClone

        public void replaceChildElementByClone​(Node owner,
                                               String elemName,
                                               Element replacement)
                                        throws XSPFException
        Replaces one child element of the given name of the given owner with the clone of another one. If none just adds, fails if more.
        Parameters:
        owner -
        elemName -
        replacement -
        Throws:
        XSPFException
      • replaceChildElementsByClone

        public void replaceChildElementsByClone​(Node owner,
                                                String elemName,
                                                java.util.stream.Stream<Element> replacements)
                                         throws XSPFException
        Replaces all child elements of the given name of the given owner with the clone of another ones.
        Parameters:
        owner -
        elemName -
        replacements -
        Throws:
        XSPFException
      • createNewElement

        public Element createNewElement​(Node context,
                                        String name)
                                 throws XSPFException
        Just creates new element in the document given by the context (the whole document including).
        Parameters:
        context -
        name -
        Returns:
        Throws:
        XSPFException
      • addChildElements

        public void addChildElements​(Node owner,
                                     java.util.stream.Stream<Element> elems)
        Just adds all the given elements to the given owner.
        Parameters:
        owner -
        elems -
      • removeChildElement

        public void removeChildElement​(Node owner,
                                       Element elem)
                                throws XSPFException
        Just removes the given element from the given owner.
        Parameters:
        owner -
        elem -
        Throws:
        XSPFException
      • removeChildElements

        public void removeChildElements​(Node owner,
                                        java.util.stream.Stream<Element> elems)
        Just removes the given elements from the given owner.
        Parameters:
        owner -
        elems -
      • replaceChildElement

        public void replaceChildElement​(Node owner,
                                        Element original,
                                        Element replacement)
                                 throws XSPFException
        Just replaces the given element with another one.
        Parameters:
        owner -
        original -
        replacement -
        Throws:
        XSPFException
      • replaceChildElements

        public void replaceChildElements​(Node owner,
                                         java.util.stream.Stream<Element> originals,
                                         java.util.stream.Stream<Element> replacements)
                                  throws XSPFException
        Just replaces the given elements by another ones.
        Parameters:
        owner -
        originals -
        replacements -
        Throws:
        XSPFException