Class XmlStructure


  • public class XmlStructure
    extends Object
    The structure for handling the XML files.
    • Constructor Detail

      • XmlStructure

        public XmlStructure​(File f,
                            String encoding)
        Constructor. Create an instance of this data-structure from an XML file.
        Parameters:
        f - The XML file
        encoding - the encoding to use to read the file
      • XmlStructure

        public XmlStructure​(org.dom4j.Element subTreeRoot)
        Constructor. Creating a new instance of this data-structure from the branch of another instance.
        Parameters:
        subTreeRoot - The root of the tree for this instance
    • Method Detail

      • getRoot

        public org.dom4j.Element getRoot()
        Function to retrieving the root of this branch in the XML tree.
        Returns:
        The root element
      • getChild

        public org.dom4j.Element getChild​(String name)
        Function for retrieving a single specific branch.
        Parameters:
        name - The name of the branch
        Returns:
        The child element of the XML tree structure
      • getChildren

        public List<org.dom4j.Element> getChildren​(String name)
        For receiving a list of specific branches.
        Parameters:
        name - The name of the children to be found.
        Returns:
        A list of the children with the given name.
      • getXML

        public String getXML()
        Retrieves the XML code for this entire branch.
        Returns:
        The XML code.
      • getSubChild

        public org.dom4j.Element getSubChild​(String... name)
        For retrieving the first children along a path.
        Parameters:
        name - The path to the child.
        Returns:
        The child element, or null if no such child exists.
      • getSubChildValue

        public String getSubChildValue​(String... name)
        Retrieves the content of a branch deep in tree structure.
        Parameters:
        name - Specifies the path in the tree (e.g. in HTML: GetSubChildValue("HTML", "HEAD", "TITLE") to get the title of a HTML document)
        Returns:
        The content of the leaf. If it is not a leaf, the entire XML-branch is returned. Returns 'null' if the path to the branch cannot be found.
      • getLeafValue

        public String getLeafValue​(String... path)
        Retrieves the content of a branch deep in tree structure.
        Parameters:
        path - Specifies the path in the tree (e.g. in HTML: GetSubChildValue("HTML", "HEAD", "TITLE") to get the title of a HTML document)
        Returns:
        The content of the leaf. If it is not a leaf, return null. Returns 'null' if the path to the branch cannot be found.
      • getLeafValues

        public String[] getLeafValues​(String... path)
        Retrieves the content of a the leafs deep in the tree structure. It only retrieves branches at the first path.
        Parameters:
        path - Specifies the path in the tree (e.g. in HTML: GetSubChildValue("HTML", "HEAD", "TITLE") to get the title of a HTML document)
        Returns:
        The content of the leaf. If no leafs are found then an empty collection of strings are returned (new String[0]).
      • overWrite

        public void overWrite​(org.dom4j.Element overwriter)
        This function initialise the process of overwriting a part of the tree.

        This is used for the Settings attributes in the deploy.

        Parameters:
        overwriter - The settings instance for the current element
      • overWriteOnly

        public void overWriteOnly​(org.dom4j.Element branch,
                                  String value,
                                  String... path)
        Overwrites the leaf at the end of the path from the branch.
        Parameters:
        branch - The branch where to begin.
        value - The value to overwrite the leaf with.
        path - The path from the branch to the leaf.
      • overWriteOnlyInt

        public void overWriteOnlyInt​(org.dom4j.Element branch,
                                     int position,
                                     char value,
                                     String... path)
        Specific overwrite function for overwriting a specific character in a string.
        Parameters:
        branch - The initial branch of the XML tree.
        position - The position in the String where the character are to be changed.
        value - The new value of the character to change.
        path - The path to the leaf of the string to change.
      • makeElementFromString

        public static org.dom4j.Element makeElementFromString​(String content)
        Creates an dom4j.Element from a String. This string has to be in the XML format, otherwise return null.
        Parameters:
        content - The content of a String.
        Returns:
        The Element.
      • pathAndContentToXML

        public static String pathAndContentToXML​(String content,
                                                 String... path)
        This function creates the XML code for the path.
        Parameters:
        content - The content at the leaf of the branch.
        path - The path to the branch.
        Returns:
        The XML code for the branch with content.
      • getAllChildrenAlongPath

        public static List<org.dom4j.Element> getAllChildrenAlongPath​(org.dom4j.Element current,
                                                                      String... path)
        This function recursively calls it self, and retrieves all the leaf children from all sibling branches along the path. When a call to it-self is made, the first string in path is removed.
        Parameters:
        current - The current element to retrieve children along the path.
        path - The path to the leafs.
        Returns:
        The complete list of elements which can be found along the path.