to.etc.xml
Class DomTools

java.lang.Object
  extended by to.etc.xml.DomTools

public class DomTools
extends java.lang.Object

Static utility class having stuff to easily obtain data from a DOM parsed document.

Author:
Frits Jalvingh

Field Summary
static java.util.Date BIGBANG
           
static java.lang.String DBNULL
           
static java.util.Date OBLIVIAN
           
 
Method Summary
static boolean boolAttr(org.w3c.dom.Node n, java.lang.String aname)
           
static boolean boolAttr(org.w3c.dom.Node n, java.lang.String aname, boolean defval)
           
static java.lang.Boolean booleanNode(org.w3c.dom.Node rootnode, java.lang.String name)
          Finds the child node with the name specified, and returns it as a boolean value.
static boolean boolNode(org.w3c.dom.Node rootnode, java.lang.String name)
          Finds the child node with the name specified, and returns it as a boolean value.
static java.util.Date dateDecode(java.lang.String s)
          Decodes a date and converts it to the local time.
static java.lang.String dateEncode(java.util.Date dt)
          Encodes a date-only field to some readable form.
static java.util.Date dateNode(org.w3c.dom.Node rn, java.lang.String name)
           
static java.util.Date dateNode(org.w3c.dom.Node rn, java.lang.String name, java.util.Date dflt)
           
static boolean decodeBoolStr(java.lang.String nt, java.lang.String name)
           
static double doubleNode(org.w3c.dom.Node rootnode, java.lang.String name, double val)
           
static java.lang.String fileNameNode(org.w3c.dom.Node rootnode, java.lang.String name)
          Checks if there's a file node with the spec'd name in the node.
static java.lang.String findChildNodeValue(org.w3c.dom.Node rootnode, java.lang.String name)
          Deprecated.  
static org.w3c.dom.Document getDocument(java.io.File inf, boolean nsaware)
          Creates a DOM parser, parses the document, and returns the DOM associated with the thing.
static org.w3c.dom.Document getDocument(java.io.File inf, org.xml.sax.ErrorHandler eh, boolean nsaware)
          Creates a DOM parser, parses the document, and returns the DOM associated with the thing.
static org.w3c.dom.Document getDocument(java.io.InputStream is, java.lang.String ident, boolean nsaware)
          Creates a DOM parser, parses the document, and returns the DOM associated with the thing.
static org.w3c.dom.Document getDocument(java.io.InputStream is, java.lang.String ident, org.xml.sax.ErrorHandler eh, boolean nsaware)
          Creates a DOM parser, parses the document, and returns the DOM associated with the thing.
static org.w3c.dom.Document getDocument(java.io.Reader is, java.lang.String ident, boolean nsaware)
          Creates a DOM parser, parses the document, and returns the DOM associated with the thing.
static org.w3c.dom.Document getDocument(java.io.Reader is, java.lang.String ident, org.xml.sax.ErrorHandler eh, boolean nsaware)
          Creates a DOM parser, parses the document, and returns the DOM associated with the thing.
static org.w3c.dom.Document getDocumentFromZIP(java.io.File zipfile, java.lang.String name, org.xml.sax.ErrorHandler eh, boolean nsaware)
           
static org.w3c.dom.Node getDocumentRoot(java.lang.String txt, java.lang.String ident, boolean nsaware)
           
static org.w3c.dom.Node getDocumentRoot(java.lang.String txt, java.lang.String ident, org.xml.sax.ErrorHandler eh, boolean nsaware)
           
static int getNodeAttribute(org.w3c.dom.Node n, java.lang.String aname, int defval)
          Get the named attribute from a node.
static java.lang.String getNodeAttribute(org.w3c.dom.Node n, java.lang.String aname, java.lang.String defval)
          Get the named attribute from a node.
static org.w3c.dom.Node getRootElement(org.w3c.dom.Document doc)
           
static java.lang.String[] getStringList(org.w3c.dom.Node inn, java.lang.String itemname)
           
static java.util.List<java.lang.String> getStringList(org.w3c.dom.Node inn, java.lang.String listname, java.lang.String itemname)
           
static int intAttr(org.w3c.dom.Node n, java.lang.String aname)
           
static int intAttr(org.w3c.dom.Node n, java.lang.String aname, int defval)
           
static int intNode(org.w3c.dom.Node rootnode, java.lang.String name)
           
static int intNode(org.w3c.dom.Node rootnode, java.lang.String name, int val)
           
static boolean isBigBang(java.util.Date dt)
           
static boolean isOblivian(java.util.Date dt)
           
static boolean isTextOnly(org.w3c.dom.Node inn)
           
static long longAttr(org.w3c.dom.Node n, java.lang.String aname)
           
static java.lang.Long longAttrWrapped(org.w3c.dom.Node n, java.lang.String aname)
           
static long longNode(org.w3c.dom.Node rootnode, java.lang.String name)
           
static long longNode(org.w3c.dom.Node rootnode, java.lang.String name, long val)
           
static java.lang.Long longWrapperNode(org.w3c.dom.Node rootnode, java.lang.String name)
           
static org.w3c.dom.Node nodeFind(org.w3c.dom.Node rn, java.lang.String name)
          Finds a single element with the name spec'd in the node.
static org.w3c.dom.Node nodeFindXpath(org.w3c.dom.Node node, java.lang.String xpathQuery)
          Finds a child node, via the xpath query route.
static java.util.List<org.w3c.dom.Node> nodesFind(org.w3c.dom.Node rn, java.lang.String name)
          Searches for child Nodes in the specified Node which have the specified name and returns the result as a Set.
static void saveDocument(java.io.File of, org.w3c.dom.Document doc)
           
static void setAttr(org.w3c.dom.Node elem, java.lang.String name, java.lang.String value)
           
static java.lang.String strAttr(org.w3c.dom.Node n, java.lang.String aname)
           
static java.lang.String strAttr(org.w3c.dom.Node n, java.lang.String aname, java.lang.String def)
           
static java.lang.String stringNode_untrimmed(org.w3c.dom.Node rootnode, java.lang.String name)
          Finds the child node with the name specified, and returns it's text value.
static java.lang.String stringNode_untrimmed(org.w3c.dom.Node rootnode, java.lang.String name, java.lang.String deflt)
          Finds the child node with the name specified, and returns it's text value.
static java.lang.String stringNode(org.w3c.dom.Node rootnode, java.lang.String name)
          Finds the child node with the name specified, and returns it's text value.
static java.lang.String stringNode(org.w3c.dom.Node rootnode, java.lang.String name, int trunclen)
          Finds the child node with the name specified, and returns it's text value.
static java.lang.String stringNode(org.w3c.dom.Node rootnode, java.lang.String name, java.lang.String deflt)
          Finds the child node with the name specified, and returns it's text value.
static java.lang.String textFrom_untrimmed(org.w3c.dom.Node n)
          Gets the text part contained in a node...
static java.lang.String textFrom(org.w3c.dom.Node n)
          Gets the text part contained in a node...
static int timeNode(org.w3c.dom.Node rn, java.lang.String name, int dflt)
          Scans a node as a hh:mm:ss time (or hh:mm).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OBLIVIAN

public static final java.util.Date OBLIVIAN

BIGBANG

public static final java.util.Date BIGBANG

DBNULL

public static final java.lang.String DBNULL
See Also:
Constant Field Values
Method Detail

getDocument

public static org.w3c.dom.Document getDocument(java.io.InputStream is,
                                               java.lang.String ident,
                                               org.xml.sax.ErrorHandler eh,
                                               boolean nsaware)
                                        throws java.lang.Exception
Creates a DOM parser, parses the document, and returns the DOM associated with the thing. If errors occur they are logged into an error message string; these are thrown as an exception when complete.

Throws:
java.lang.Exception

getDocumentRoot

public static org.w3c.dom.Node getDocumentRoot(java.lang.String txt,
                                               java.lang.String ident,
                                               org.xml.sax.ErrorHandler eh,
                                               boolean nsaware)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getDocumentRoot

public static org.w3c.dom.Node getDocumentRoot(java.lang.String txt,
                                               java.lang.String ident,
                                               boolean nsaware)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getDocument

public static org.w3c.dom.Document getDocument(java.io.Reader is,
                                               java.lang.String ident,
                                               org.xml.sax.ErrorHandler eh,
                                               boolean nsaware)
                                        throws java.lang.Exception
Creates a DOM parser, parses the document, and returns the DOM associated with the thing. If errors occur they are logged into an error message string; these are thrown as an exception when complete.

Throws:
java.lang.Exception

getDocument

public static org.w3c.dom.Document getDocument(java.io.File inf,
                                               org.xml.sax.ErrorHandler eh,
                                               boolean nsaware)
                                        throws java.lang.Exception
Creates a DOM parser, parses the document, and returns the DOM associated with the thing. If errors occur they are logged into an error message string; these are thrown as an exception when complete.

Throws:
java.lang.Exception

getDocument

public static org.w3c.dom.Document getDocument(java.io.File inf,
                                               boolean nsaware)
                                        throws java.lang.Exception
Creates a DOM parser, parses the document, and returns the DOM associated with the thing. If errors occur they are logged into an error message string; these are thrown as an exception when complete.

Throws:
java.lang.Exception

getDocument

public static org.w3c.dom.Document getDocument(java.io.InputStream is,
                                               java.lang.String ident,
                                               boolean nsaware)
                                        throws java.lang.Exception
Creates a DOM parser, parses the document, and returns the DOM associated with the thing. If errors occur they are logged into an error message string; these are thrown as an exception when complete.

Throws:
java.lang.Exception

getDocument

public static org.w3c.dom.Document getDocument(java.io.Reader is,
                                               java.lang.String ident,
                                               boolean nsaware)
                                        throws java.lang.Exception
Creates a DOM parser, parses the document, and returns the DOM associated with the thing. If errors occur they are logged into an error message string; these are thrown as an exception when complete.

Throws:
java.lang.Exception

getDocumentFromZIP

public static org.w3c.dom.Document getDocumentFromZIP(java.io.File zipfile,
                                                      java.lang.String name,
                                                      org.xml.sax.ErrorHandler eh,
                                                      boolean nsaware)
                                               throws java.lang.Exception
Throws:
java.lang.Exception

nodeFind

public static org.w3c.dom.Node nodeFind(org.w3c.dom.Node rn,
                                        java.lang.String name)
                                 throws java.lang.Exception
Finds a single element with the name spec'd in the node. If more than one node with the same name exists this throws an exception.

Throws:
java.lang.Exception

nodesFind

public static java.util.List<org.w3c.dom.Node> nodesFind(org.w3c.dom.Node rn,
                                                         java.lang.String name)
Searches for child Nodes in the specified Node which have the specified name and returns the result as a Set. If null is specified for the parentNode an empty Set is returned.

Parameters:
rn, - the Node which is queried.
name, - the name of the childNodes we are searching.
Returns:
a Set containing the childnodes with the specified name.

textFrom_untrimmed

public static java.lang.String textFrom_untrimmed(org.w3c.dom.Node n)
Gets the text part contained in a node... All text parts are obtained and concatenated with a single space.


textFrom

public static java.lang.String textFrom(org.w3c.dom.Node n)
Gets the text part contained in a node... All text parts are obtained and concatenated with a single space.


findChildNodeValue

@Deprecated
public static java.lang.String findChildNodeValue(org.w3c.dom.Node rootnode,
                                                             java.lang.String name)
                                           throws java.lang.Exception
Deprecated. 

Finds the child node with the name specified, and returns it's text value. If the node is not found it returns null.

Throws:
java.lang.Exception
See Also:
stringNode(Node, String)

stringNode

public static java.lang.String stringNode(org.w3c.dom.Node rootnode,
                                          java.lang.String name)
                                   throws java.lang.Exception
Finds the child node with the name specified, and returns it's text value. If the node is not found it returns null.

Throws:
java.lang.Exception

stringNode

public static java.lang.String stringNode(org.w3c.dom.Node rootnode,
                                          java.lang.String name,
                                          int trunclen)
                                   throws java.lang.Exception
Finds the child node with the name specified, and returns it's text value. If the node is not found it returns null.

Throws:
java.lang.Exception

stringNode

public static java.lang.String stringNode(org.w3c.dom.Node rootnode,
                                          java.lang.String name,
                                          java.lang.String deflt)
                                   throws java.lang.Exception
Finds the child node with the name specified, and returns it's text value. If the node is not found it returns the default string.

Throws:
java.lang.Exception

stringNode_untrimmed

public static java.lang.String stringNode_untrimmed(org.w3c.dom.Node rootnode,
                                                    java.lang.String name)
                                             throws java.lang.Exception
Finds the child node with the name specified, and returns it's text value. If the node is not found it returns null.

Throws:
java.lang.Exception

stringNode_untrimmed

public static java.lang.String stringNode_untrimmed(org.w3c.dom.Node rootnode,
                                                    java.lang.String name,
                                                    java.lang.String deflt)
                                             throws java.lang.Exception
Finds the child node with the name specified, and returns it's text value. If the node is not found it returns the default string.

Throws:
java.lang.Exception

dateNode

public static java.util.Date dateNode(org.w3c.dom.Node rn,
                                      java.lang.String name)
                               throws java.lang.Exception
Throws:
java.lang.Exception

dateNode

public static java.util.Date dateNode(org.w3c.dom.Node rn,
                                      java.lang.String name,
                                      java.util.Date dflt)
                               throws java.lang.Exception
Throws:
java.lang.Exception

timeNode

public static int timeNode(org.w3c.dom.Node rn,
                           java.lang.String name,
                           int dflt)
                    throws java.lang.Exception
Scans a node as a hh:mm:ss time (or hh:mm). The time is returned as a #seconds in the day.

Parameters:
rn -
name -
dflt -
Returns:
Throws:
java.lang.Exception

intNode

public static int intNode(org.w3c.dom.Node rootnode,
                          java.lang.String name)
                   throws java.lang.Exception
Throws:
java.lang.Exception

intNode

public static int intNode(org.w3c.dom.Node rootnode,
                          java.lang.String name,
                          int val)
                   throws java.lang.Exception
Throws:
java.lang.Exception

longWrapperNode

public static java.lang.Long longWrapperNode(org.w3c.dom.Node rootnode,
                                             java.lang.String name)
                                      throws java.lang.Exception
Throws:
java.lang.Exception

longNode

public static long longNode(org.w3c.dom.Node rootnode,
                            java.lang.String name)
                     throws java.lang.Exception
Throws:
java.lang.Exception

longNode

public static long longNode(org.w3c.dom.Node rootnode,
                            java.lang.String name,
                            long val)
                     throws java.lang.Exception
Throws:
java.lang.Exception

doubleNode

public static double doubleNode(org.w3c.dom.Node rootnode,
                                java.lang.String name,
                                double val)
                         throws java.lang.Exception
Throws:
java.lang.Exception

fileNameNode

public static java.lang.String fileNameNode(org.w3c.dom.Node rootnode,
                                            java.lang.String name)
                                     throws java.lang.Exception
Checks if there's a file node with the spec'd name in the node. If so this returns the node's filename... If the node doesn't exist this returns null..

Parameters:
rootnode -
name -
Returns:
Throws:
java.lang.Exception

boolNode

public static boolean boolNode(org.w3c.dom.Node rootnode,
                               java.lang.String name)
                        throws java.lang.Exception
Finds the child node with the name specified, and returns it as a boolean value. If the node has NO text associated then this returns TRUE, if the node is not present then this returns false; if the node is present and has text the text field is interpreted: if numeric we return T if the number is not null; if text the value must start with T for true and F for false. All other values throw an exception.

Throws:
java.lang.Exception

booleanNode

public static java.lang.Boolean booleanNode(org.w3c.dom.Node rootnode,
                                            java.lang.String name)
                                     throws java.lang.Exception
Finds the child node with the name specified, and returns it as a boolean value. If the node has NO text associated then this returns TRUE, if the node is not present then this returns false; if the node is present and has text the text field is interpreted: if numeric we return T if the number is not null; if text the value must start with T for true and F for false. All other values throw an exception.

Throws:
java.lang.Exception

decodeBoolStr

public static boolean decodeBoolStr(java.lang.String nt,
                                    java.lang.String name)

getNodeAttribute

public static java.lang.String getNodeAttribute(org.w3c.dom.Node n,
                                                java.lang.String aname,
                                                java.lang.String defval)
Get the named attribute from a node. If the attribute is not present return the default value in defval

Parameters:
n - the node to containing the attribute.
aname - the name of the attribute.
defval - the value to return if the attribute is not present,
Returns:
a string containing the attribute's value or the default.

strAttr

public static java.lang.String strAttr(org.w3c.dom.Node n,
                                       java.lang.String aname,
                                       java.lang.String def)

strAttr

public static java.lang.String strAttr(org.w3c.dom.Node n,
                                       java.lang.String aname)

intAttr

public static int intAttr(org.w3c.dom.Node n,
                          java.lang.String aname,
                          int defval)
                   throws java.lang.Exception
Throws:
java.lang.Exception

intAttr

public static int intAttr(org.w3c.dom.Node n,
                          java.lang.String aname)
                   throws java.lang.Exception
Throws:
java.lang.Exception

longAttr

public static long longAttr(org.w3c.dom.Node n,
                            java.lang.String aname)
                     throws java.lang.Exception
Throws:
java.lang.Exception

longAttrWrapped

public static java.lang.Long longAttrWrapped(org.w3c.dom.Node n,
                                             java.lang.String aname)
                                      throws java.lang.Exception
Throws:
java.lang.Exception

boolAttr

public static boolean boolAttr(org.w3c.dom.Node n,
                               java.lang.String aname)
                        throws java.lang.Exception
Throws:
java.lang.Exception

boolAttr

public static boolean boolAttr(org.w3c.dom.Node n,
                               java.lang.String aname,
                               boolean defval)
                        throws java.lang.Exception
Throws:
java.lang.Exception

getNodeAttribute

public static int getNodeAttribute(org.w3c.dom.Node n,
                                   java.lang.String aname,
                                   int defval)
                            throws java.lang.Exception
Get the named attribute from a node. If the attribute is not present return the default value in defval

Parameters:
n - the node to containing the attribute.
aname - the name of the attribute.
defval - the value to return if the attribute is not present,
Returns:
a string containing the attribute's value or the default.
Throws:
java.lang.Exception

dateEncode

public static java.lang.String dateEncode(java.util.Date dt)
Encodes a date-only field to some readable form. Can be decoded by decodeDate or getNodeDate(). The date contains local timezone info.

Parameters:
dt - the date to encode.
Returns:
a string

dateDecode

public static java.util.Date dateDecode(java.lang.String s)
Decodes a date and converts it to the local time. The format MUST match the format generated by encode or we fail. Dates can contain three special values:
(dbnull)
The date field is null
big-bang
The date field represents a date before any other date,
oblivian
The dtae field represents a date after any other date.
 Format:
 0123456789012345678901234567
 2001-12-24 18:10:52.0012 (timezone)

Parameters:
s -
Returns:

isOblivian

public static final boolean isOblivian(java.util.Date dt)

isBigBang

public static final boolean isBigBang(java.util.Date dt)

getStringList

public static final java.lang.String[] getStringList(org.w3c.dom.Node inn,
                                                     java.lang.String itemname)
                                              throws java.lang.Exception
Throws:
java.lang.Exception

getStringList

public static final java.util.List<java.lang.String> getStringList(org.w3c.dom.Node inn,
                                                                   java.lang.String listname,
                                                                   java.lang.String itemname)
                                                            throws java.lang.Exception
Throws:
java.lang.Exception

getRootElement

public static org.w3c.dom.Node getRootElement(org.w3c.dom.Document doc)
                                       throws java.lang.Exception
Throws:
java.lang.Exception

isTextOnly

public static boolean isTextOnly(org.w3c.dom.Node inn)

saveDocument

public static void saveDocument(java.io.File of,
                                org.w3c.dom.Document doc)
                         throws java.lang.Exception
Throws:
java.lang.Exception

setAttr

public static void setAttr(org.w3c.dom.Node elem,
                           java.lang.String name,
                           java.lang.String value)

nodeFindXpath

public static org.w3c.dom.Node nodeFindXpath(org.w3c.dom.Node node,
                                             java.lang.String xpathQuery)
                                      throws java.lang.Exception
Finds a child node, via the xpath query route. Thus the name of all the nodes, separated by a "/". The path can only use unique names. If a child node with the same name exists an exception will be thrown.

Parameters:
node - the node to search
xpathQuery - path to the child node
Returns:
the child node, or null if it cannot be found.
Throws:
java.lang.Exception