dk.netarkivet.deploy
Class XmlStructure

java.lang.Object
  extended by dk.netarkivet.deploy.XmlStructure

public class XmlStructure
extends java.lang.Object

The structure for handling the XML files.


Constructor Summary
XmlStructure(org.dom4j.Element subTreeRoot)
          Constructor.
XmlStructure(java.io.File f)
          Constructor.
 
Method Summary
static java.util.List<org.dom4j.Element> getAllChildrenAlongPath(org.dom4j.Element current, java.lang.String... path)
          This function recursively calls it self, and retrieves all the leaf children from all sibling branches along the path.
 org.dom4j.Element getChild(java.lang.String name)
          Function for retrieving a single specific branch.
 java.util.List<org.dom4j.Element> getChildren(java.lang.String name)
          For receiving a list of specific branches.
 java.lang.String getLeafValue(java.lang.String... path)
          Retrieves the content of a branch deep in tree structure.
 java.lang.String[] getLeafValues(java.lang.String... path)
          Retrieves the content of a the leafs deep in the tree structure.
 org.dom4j.Element getRoot()
          Function to retrieving the root of this branch in the XML tree.
 org.dom4j.Element getSubChild(java.lang.String... name)
          For retrieving the first children along a path.
 java.lang.String getSubChildValue(java.lang.String... name)
          Retrieves the content of a branch deep in tree structure.
 java.lang.String getXML()
          Retrieves the XML code for this entire branch.
static org.dom4j.Element makeElementFromString(java.lang.String content)
          Creates an dom4j.Element from a String.
 void overWrite(org.dom4j.Element overwriter)
          This function initialise the process of overwriting a part of the tree.
 void overWriteOnly(org.dom4j.Element branch, java.lang.String value, java.lang.String... path)
          Overwrites the leaf at the end of the path from the branch.
 void overWriteOnlyInt(org.dom4j.Element branch, int position, char value, java.lang.String... path)
          Specific overwrite function for overwriting a specific character in a string.
static java.lang.String pathAndContentToXML(java.lang.String content, java.lang.String... path)
          This function creates the XML code for the path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlStructure

public XmlStructure(java.io.File f)
Constructor. Create an instance of this data-structure from an XML file.

Parameters:
f - The XML 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(java.lang.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 java.util.List<org.dom4j.Element> getChildren(java.lang.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 java.lang.String getXML()
Retrieves the XML code for this entire branch.

Returns:
The XML code.

getSubChild

public org.dom4j.Element getSubChild(java.lang.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 java.lang.String getSubChildValue(java.lang.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 java.lang.String getLeafValue(java.lang.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 java.lang.String[] getLeafValues(java.lang.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,
                          java.lang.String value,
                          java.lang.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,
                             java.lang.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(java.lang.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 java.lang.String pathAndContentToXML(java.lang.String content,
                                                   java.lang.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 java.util.List<org.dom4j.Element> getAllChildrenAlongPath(org.dom4j.Element current,
                                                                        java.lang.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.