ocean.utils
Class XMLutils

java.lang.Object
  |
  +--ocean.utils.XMLutils

public class XMLutils
extends java.lang.Object

The XMLutils class contains many utility methods that wrap the DOM, causing many common tasks that take several lines of code to take one.


Constructor Summary
XMLutils()
           
 
Method Summary
static void attachAttrToNode(org.w3c.dom.Element e, org.w3c.dom.Document d, java.lang.String name, java.lang.String val)
          Create a named attribute with a value and attach it to an element.
static void attachElemToNode(org.w3c.dom.Node n, org.w3c.dom.Document d, java.lang.String name)
          Create a named element and attach it to a node .
static void attachText(org.w3c.dom.Node n, org.w3c.dom.Document d, java.lang.String text)
          Set a text value for an existing text node.
static void attachTextToNode(org.w3c.dom.Node n, org.w3c.dom.Document d, java.lang.String name, java.lang.String val)
          Create a text, set its value and append it to a node.
static org.w3c.dom.Element getAttachedElem(org.w3c.dom.Node n, org.w3c.dom.Document d, java.lang.String name)
          Create a named element and attach it to a node, returning the created element
static java.lang.String getAttrVal(org.w3c.dom.Node node, java.lang.String val)
          Search a Node for an attribute value.
static org.w3c.dom.Node getChildByName(org.w3c.dom.Node node, java.lang.String name)
          Search for the first child node of a Node by name.
static org.w3c.dom.Node getChildByType(org.w3c.dom.Node n, short code)
          Search a Node for the first child of a given type
static org.w3c.dom.Node getChildElement(org.w3c.dom.Node node)
          Search for the first child of a Node that is an Element.
static java.util.Vector getChildrenByName(org.w3c.dom.Node node, java.lang.String searchName)
          Search for all children of a Node by name.
static org.w3c.dom.Document getDOMDoc(java.lang.String docContent)
          Construct an instance of the Document interface by parsing the String representation of an XML document.
static java.lang.String getNodeText(org.w3c.dom.Node node)
          Get the text value of an element whose type is text.
static org.w3c.dom.Node getSiblingByName(org.w3c.dom.Node node, java.lang.String siblingName)
          Search for the sibling node of a Node by name.
static java.util.Vector getSiblingsByName(org.w3c.dom.Node node, java.lang.String searchName, java.lang.String stopName)
          Search for all siblings of a Node by name.
static org.w3c.dom.Document NewDoc()
          Create a new instance of the Document interface.
static javax.xml.transform.Transformer NewTrans()
          Create an instance of the Transformer interface.
static java.lang.String TransformNodeTree(org.w3c.dom.Node rootNode)
          Transform a node tree to a String representation.
static java.lang.String TransformOCEANDoc(OCEANDoc doc)
          Transform an OCEAN trade proposal document to a String representation.
static java.io.File TransformOCEANDocToFile(OCEANDoc doc, java.lang.String fName)
          Transform an OCEAN trade proposal document to a file.
static java.lang.String TransformXMLFile(java.lang.String xmlFileName)
          Transform the contents of an XML file to a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLutils

public XMLutils()
Method Detail

NewDoc

public static org.w3c.dom.Document NewDoc()
Create a new instance of the Document interface.
Returns:
a newly created Document

getDOMDoc

public static org.w3c.dom.Document getDOMDoc(java.lang.String docContent)
Construct an instance of the Document interface by parsing the String representation of an XML document.
Returns:
a Document tree that results from parsing the String

NewTrans

public static javax.xml.transform.Transformer NewTrans()
Create an instance of the Transformer interface.
Returns:
a newly created Transformer

TransformXMLFile

public static final java.lang.String TransformXMLFile(java.lang.String xmlFileName)
Transform the contents of an XML file to a String
Parameters:
xmlFileName - name of the file to transform
Returns:
String contents of the file

TransformNodeTree

public static final java.lang.String TransformNodeTree(org.w3c.dom.Node rootNode)
Transform a node tree to a String representation.
Parameters:
rootNode - root of the node tree to transform
Returns:
String contents of the node tree

TransformOCEANDoc

public static final java.lang.String TransformOCEANDoc(OCEANDoc doc)
Transform an OCEAN trade proposal document to a String representation.
Parameters:
doc - the document to transform
Returns:
String content of the OCEAN document

TransformOCEANDocToFile

public static final java.io.File TransformOCEANDocToFile(OCEANDoc doc,
                                                         java.lang.String fName)
Transform an OCEAN trade proposal document to a file.
Parameters:
doc - the document to transform
fName - name of the file in which to save the XML content
Returns:
the file with the content contained in the OCEAN document

getSiblingByName

public static final org.w3c.dom.Node getSiblingByName(org.w3c.dom.Node node,
                                                      java.lang.String siblingName)
Search for the sibling node of a Node by name.
Parameters:
node - The node where the search begins.
siblingName - name of the node to search for
Returns:
the Node if found, null if no such sibling exists.

getChildByName

public static final org.w3c.dom.Node getChildByName(org.w3c.dom.Node node,
                                                    java.lang.String name)
Search for the first child node of a Node by name.
Parameters:
node - The node where the search begins
name - the name of the node to search for
Returns:
the Node if found, null if no such child exists.

getChildrenByName

public static final java.util.Vector getChildrenByName(org.w3c.dom.Node node,
                                                       java.lang.String searchName)
Search for all children of a Node by name.
Parameters:
node - The node where the search begins
searchName - the name to search for
Returns:
a Vector containing the found Nodes. If none found, the Vector is empty.

getSiblingsByName

public static final java.util.Vector getSiblingsByName(org.w3c.dom.Node node,
                                                       java.lang.String searchName,
                                                       java.lang.String stopName)
Search for all siblings of a Node by name.
Parameters:
node - The node where the search begins
searchName - the name to search for
Returns:
a Vector containing the found Nodes. If none found, the Vector is empty.

getChildElement

public static final org.w3c.dom.Node getChildElement(org.w3c.dom.Node node)
Search for the first child of a Node that is an Element.
Returns:
the first child of the node that is an element node, null if none exists.

getAttrVal

public static final java.lang.String getAttrVal(org.w3c.dom.Node node,
                                                java.lang.String val)
Search a Node for an attribute value.
Parameters:
node - the node to search
val - the name of the attribute for which a value is sought
Returns:
the text value of the attribute, "" if the attribute does not exist

getNodeText

public static final java.lang.String getNodeText(org.w3c.dom.Node node)
Get the text value of an element whose type is text.
Parameters:
node - the Node for which the text value is sought
Returns:
the text value, "" if the call fails

getChildByType

public static final org.w3c.dom.Node getChildByType(org.w3c.dom.Node n,
                                                    short code)
Search a Node for the first child of a given type
Parameters:
n - the node to search
code - the code that indicates the Node type

attachTextToNode

public static final void attachTextToNode(org.w3c.dom.Node n,
                                          org.w3c.dom.Document d,
                                          java.lang.String name,
                                          java.lang.String val)
Create a text, set its value and append it to a node.
Parameters:
n - the node to which the new node is attached
d - the document in which the node is created
name - the name of the new node
val - the text value to set for the new node

attachText

public static final void attachText(org.w3c.dom.Node n,
                                    org.w3c.dom.Document d,
                                    java.lang.String text)
Set a text value for an existing text node.
Parameters:
n - the node for which the text will be set
d - the document in which these actions will occur
text - the text to assign to the node

attachAttrToNode

public static final void attachAttrToNode(org.w3c.dom.Element e,
                                          org.w3c.dom.Document d,
                                          java.lang.String name,
                                          java.lang.String val)
Create a named attribute with a value and attach it to an element.
Parameters:
e - the element to which the attribute is attached
d - the document in which these action occur
name - the name of the attribute to create
val - the value of the attribute

attachElemToNode

public static final void attachElemToNode(org.w3c.dom.Node n,
                                          org.w3c.dom.Document d,
                                          java.lang.String name)
Create a named element and attach it to a node .
Parameters:
n - the node to which the element is attached
d - the document in which these actions occur
name - the name of the new element

getAttachedElem

public static final org.w3c.dom.Element getAttachedElem(org.w3c.dom.Node n,
                                                        org.w3c.dom.Document d,
                                                        java.lang.String name)
Create a named element and attach it to a node, returning the created element
Parameters:
n - the node to which the element is attached
d - the document in which these actions occur
name - the name of the new element
Returns:
the newly created element