uk.ac.cam.ch.wwmm.opsin
Class XOMTools

java.lang.Object
  extended by uk.ac.cam.ch.wwmm.opsin.XOMTools

public final class XOMTools
extends java.lang.Object

Accessory functions for the manipulation of XOM Nodes/Elements Only those that are necessary for OPSIN's execution


Constructor Summary
XOMTools()
           
 
Method Summary
static int[] countNumberOfElementsAndNumberOfChildLessElements(nu.xom.Element startingElement)
          Finds and returns the number of elements and the number of elements with no children, that are descendants of the startingElement The 0th position of the returned array is the total number of elements The 1st position is the number of child less elements
static java.util.List<nu.xom.Element> getChildElementsWithTagName(nu.xom.Element startingElement, java.lang.String elementName)
          Finds all child elements whose localname matches one of the strings in elementNames Equivalent to an xpath of type ./*[local-name() = 'elementName'] from the startingElement This is equivalent to XOM's getChildElements(String) other than returning an arrayList
static java.util.List<nu.xom.Element> getChildElementsWithTagNameAndAttribute(nu.xom.Element startingElement, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
          Finds all child elements whose localname matches the given elementName Additionally the element must have the specified attribute and the value of the attribute must be as specified Equivalent to an xpath of type ./*[local-name() = 'elementName'][@attribute="attributevalue"] from the startingElement
static java.util.List<nu.xom.Element> getChildElementsWithTagNames(nu.xom.Element startingElement, java.lang.String[] elementNames)
          Finds all child elements whose localname matches one of the strings in elementNames Equivalent to an xpath of type ./*[local-name() = 'elementName1']|./*[local-name() = 'elementName2']|./*[local-name() = 'elementName3'] from the startingElement
static java.util.List<nu.xom.Element> getDescendantElementsWithTagName(nu.xom.Element startingElement, java.lang.String elementName)
          Finds all descendant elements whose localname matches the given elementName Equivalent to an xpath of type .//*[local-name() = 'elementName'] from the startingElement
static java.util.List<nu.xom.Element> getDescendantElementsWithTagNameAndAttribute(nu.xom.Element startingElement, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
          Finds all descendant elements whose localname matches the given elementName Additionally the element must have the specified attribute and the value of the attribute must be as specified Equivalent to an xpath of type .//*[local-name() = 'elementName'][@attribute="attributevalue"] from the startingElement
static java.util.List<nu.xom.Element> getDescendantElementsWithTagNames(nu.xom.Element startingElement, java.lang.String[] elementNames)
          Finds all descendant elements whose localname matches one of the strings in elementNames Equivalent to an xpath of type .//*[local-name() = 'elementName1']|.//*[local-name() = 'elementName2']|.//*[local-name() = 'elementName3'] from the startingElement
static nu.xom.Node getNext(nu.xom.Node node)
          Gets the next node.
static java.util.List<nu.xom.Element> getNextAdjacentSiblingsOfType(nu.xom.Element currentElem, java.lang.String type)
          Returns an arrayList containing sibling elements of the given type after the given element.
static nu.xom.Node getNextSibling(nu.xom.Node node)
          Gets the next sibling of a given node.
static nu.xom.Node getNextSibling(nu.xom.Node current, java.lang.String tagName)
          Gets the first next sibling of a given node whose tagname matches the given string.
static nu.xom.Element getNextSiblingIgnoringCertainElements(nu.xom.Element startingEl, java.lang.String[] elementsToIgnore)
          Gets the next sibling element of the given element.
static java.util.List<nu.xom.Element> getNextSiblingsOfType(nu.xom.Element currentElem, java.lang.String type)
          Returns an arrayList containing sibling elements of the given type after the given element.
static java.util.List<nu.xom.Element> getNextSiblingsOfTypes(nu.xom.Element currentElem, java.lang.String[] types)
          Returns an arrayList containing sibling elements of the given types after the given element.
static nu.xom.Node getPrevious(nu.xom.Node node)
          Gets the previous node.
static nu.xom.Node getPreviousSibling(nu.xom.Node node)
          Gets the previous sibling of a given node.
static nu.xom.Node getPreviousSibling(nu.xom.Node current, java.lang.String tagName)
          Gets the first previous sibling of a given node whose tagname matches the given string.
static nu.xom.Element getPreviousSiblingIgnoringCertainElements(nu.xom.Element startingEl, java.lang.String[] elementsToIgnore)
          Gets the previous sibling element of the given element.
static java.util.List<nu.xom.Element> getPreviousSiblingsOfType(nu.xom.Element currentElem, java.lang.String type)
          Returns an arrayList containing sibling elements of the given type before the given element.
static java.util.List<nu.xom.Element> getSiblingsUpToElementWithTagName(nu.xom.Element startingEl, java.lang.String tagName)
          Find all the later siblings of startingElement with the search terminating at the element with string tagName or if there are not more siblings
static void insertAfter(nu.xom.Node node, nu.xom.Node newNode)
          Inserts a node so that it occurs after a reference node.
static void insertBefore(nu.xom.Node node, nu.xom.Node newNode)
          Inserts a node so that it occurs before a reference node.
static void setTextChild(nu.xom.Element group, java.lang.String newName)
          Sets the first text child of the group to the newName Throws an exception if the first child is not a Text node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XOMTools

public XOMTools()
Method Detail

getNextSibling

public static nu.xom.Node getNextSibling(nu.xom.Node node)
Gets the next sibling of a given node.

Parameters:
node - The reference node.
Returns:
The next Sibling, or null.

getNextSibling

public static nu.xom.Node getNextSibling(nu.xom.Node current,
                                         java.lang.String tagName)
Gets the first next sibling of a given node whose tagname matches the given string.

Parameters:
current - The reference node.
tagName - The tagname of a node to look for
Returns:
The matched next Sibling, or null.

getPreviousSibling

public static nu.xom.Node getPreviousSibling(nu.xom.Node node)
Gets the previous sibling of a given node.

Parameters:
node - The reference node.
Returns:
The previous Sibling, or null.

getPreviousSibling

public static nu.xom.Node getPreviousSibling(nu.xom.Node current,
                                             java.lang.String tagName)
Gets the first previous sibling of a given node whose tagname matches the given string.

Parameters:
current - The reference node.
tagName - The tagname of a node to look for
Returns:
The matched previous Sibling, or null.

insertBefore

public static void insertBefore(nu.xom.Node node,
                                nu.xom.Node newNode)
Inserts a node so that it occurs before a reference node. The new node must not currently have a parent.

Parameters:
node - The reference node.
newNode - The new node to insert.

insertAfter

public static void insertAfter(nu.xom.Node node,
                               nu.xom.Node newNode)
Inserts a node so that it occurs after a reference node. The new node must not currently have a parent.

Parameters:
node - The reference node.
newNode - The new node to insert.

getNext

public static nu.xom.Node getNext(nu.xom.Node node)
Gets the next node. This element need not be a sibling

Parameters:
node: - starting node
Returns:

getPrevious

public static nu.xom.Node getPrevious(nu.xom.Node node)
Gets the previous node. This element need not be a sibling

Parameters:
node: - starting node
Returns:

setTextChild

public static void setTextChild(nu.xom.Element group,
                                java.lang.String newName)
Sets the first text child of the group to the newName Throws an exception if the first child is not a Text node

Parameters:
group -
newName -

getNextSiblingsOfType

public static java.util.List<nu.xom.Element> getNextSiblingsOfType(nu.xom.Element currentElem,
                                                                   java.lang.String type)
Returns an arrayList containing sibling elements of the given type after the given element. These elements need not be continuous

Parameters:
currentElem: - the element to look for following siblings of
type: - the "localname" of the element type desired
Returns:

getNextAdjacentSiblingsOfType

public static java.util.List<nu.xom.Element> getNextAdjacentSiblingsOfType(nu.xom.Element currentElem,
                                                                           java.lang.String type)
Returns an arrayList containing sibling elements of the given type after the given element.

Parameters:
currentElem: - the element to look for following siblings of
type: - the "localname" of the element type desired
Returns:

getNextSiblingsOfTypes

public static java.util.List<nu.xom.Element> getNextSiblingsOfTypes(nu.xom.Element currentElem,
                                                                    java.lang.String[] types)
Returns an arrayList containing sibling elements of the given types after the given element. These elements need not be continuous and are returned in the order encountered

Parameters:
currentElem: - the element to look for following siblings of
types: - An array of the "localname"s of the element types desired
Returns:

getPreviousSiblingsOfType

public static java.util.List<nu.xom.Element> getPreviousSiblingsOfType(nu.xom.Element currentElem,
                                                                       java.lang.String type)
Returns an arrayList containing sibling elements of the given type before the given element. These elements need not be continuous

Parameters:
currentElem: - the element to look for previous siblings of
type: - the "localname" of the element type desired
Returns:

getNextSiblingIgnoringCertainElements

public static nu.xom.Element getNextSiblingIgnoringCertainElements(nu.xom.Element startingEl,
                                                                   java.lang.String[] elementsToIgnore)
Gets the next sibling element of the given element. If this element's name is within the elementsToIgnore array this is repeated If no appropriate element can be found null is returned

Parameters:
startingEl -
elementsToIgnore -
Returns:

getPreviousSiblingIgnoringCertainElements

public static nu.xom.Element getPreviousSiblingIgnoringCertainElements(nu.xom.Element startingEl,
                                                                       java.lang.String[] elementsToIgnore)
Gets the previous sibling element of the given element. If this element's name is within the elementsToIgnore array this is repeated If no appropriate element can be found null is returned

Parameters:
startingEl -
elementsToIgnore -
Returns:

getDescendantElementsWithTagName

public static java.util.List<nu.xom.Element> getDescendantElementsWithTagName(nu.xom.Element startingElement,
                                                                              java.lang.String elementName)
Finds all descendant elements whose localname matches the given elementName Equivalent to an xpath of type .//*[local-name() = 'elementName'] from the startingElement

Parameters:
startingElement -
elementName -
Returns:

getDescendantElementsWithTagNames

public static java.util.List<nu.xom.Element> getDescendantElementsWithTagNames(nu.xom.Element startingElement,
                                                                               java.lang.String[] elementNames)
Finds all descendant elements whose localname matches one of the strings in elementNames Equivalent to an xpath of type .//*[local-name() = 'elementName1']|.//*[local-name() = 'elementName2']|.//*[local-name() = 'elementName3'] from the startingElement

Parameters:
startingElement -
elementNames -
Returns:

getChildElementsWithTagNames

public static java.util.List<nu.xom.Element> getChildElementsWithTagNames(nu.xom.Element startingElement,
                                                                          java.lang.String[] elementNames)
Finds all child elements whose localname matches one of the strings in elementNames Equivalent to an xpath of type ./*[local-name() = 'elementName1']|./*[local-name() = 'elementName2']|./*[local-name() = 'elementName3'] from the startingElement

Parameters:
startingElement -
elementNames -
Returns:

getChildElementsWithTagName

public static java.util.List<nu.xom.Element> getChildElementsWithTagName(nu.xom.Element startingElement,
                                                                         java.lang.String elementName)
Finds all child elements whose localname matches one of the strings in elementNames Equivalent to an xpath of type ./*[local-name() = 'elementName'] from the startingElement This is equivalent to XOM's getChildElements(String) other than returning an arrayList

Parameters:
startingElement -
elementName -
Returns:

getDescendantElementsWithTagNameAndAttribute

public static java.util.List<nu.xom.Element> getDescendantElementsWithTagNameAndAttribute(nu.xom.Element startingElement,
                                                                                          java.lang.String elementName,
                                                                                          java.lang.String attributeName,
                                                                                          java.lang.String attributeValue)
Finds all descendant elements whose localname matches the given elementName Additionally the element must have the specified attribute and the value of the attribute must be as specified Equivalent to an xpath of type .//*[local-name() = 'elementName'][@attribute="attributevalue"] from the startingElement

Parameters:
startingElement -
elementName -
Returns:

getChildElementsWithTagNameAndAttribute

public static java.util.List<nu.xom.Element> getChildElementsWithTagNameAndAttribute(nu.xom.Element startingElement,
                                                                                     java.lang.String elementName,
                                                                                     java.lang.String attributeName,
                                                                                     java.lang.String attributeValue)
Finds all child elements whose localname matches the given elementName Additionally the element must have the specified attribute and the value of the attribute must be as specified Equivalent to an xpath of type ./*[local-name() = 'elementName'][@attribute="attributevalue"] from the startingElement

Parameters:
startingElement -
elementName -
Returns:

countNumberOfElementsAndNumberOfChildLessElements

public static int[] countNumberOfElementsAndNumberOfChildLessElements(nu.xom.Element startingElement)
Finds and returns the number of elements and the number of elements with no children, that are descendants of the startingElement The 0th position of the returned array is the total number of elements The 1st position is the number of child less elements

Parameters:
startingElement -
Returns:

getSiblingsUpToElementWithTagName

public static java.util.List<nu.xom.Element> getSiblingsUpToElementWithTagName(nu.xom.Element startingEl,
                                                                               java.lang.String tagName)
Find all the later siblings of startingElement with the search terminating at the element with string tagName or if there are not more siblings

Parameters:
startingEl -
tagName -
Returns: