|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.opengts.util.XMLTools
public class XMLTools
A set of tools for simplifying the reading and validating of XML documents
Nested Class Summary | |
---|---|
static class |
XMLTools.XMLErrorHandler
XMLErrorHandler class |
Constructor Summary | |
---|---|
XMLTools()
|
Method Summary | |
---|---|
static java.lang.String |
ATTR(java.lang.String key,
boolean value)
Create Attribute |
static java.lang.String |
ATTR(java.lang.String key,
int value)
Create Attribute |
static java.lang.String |
ATTR(java.lang.String key,
long value)
Create Attribute |
static java.lang.String |
ATTR(java.lang.String key,
java.lang.Object value)
Create Attribute |
static java.lang.String |
ATTR(java.lang.String key,
java.lang.String value)
Create Attribute |
static java.lang.String |
CDATA(boolean isSoapReq,
java.lang.String content)
Wrap content in CDATA |
static java.lang.String |
endTAG(boolean isSoapReq,
java.lang.String tag,
boolean newLine)
End tag |
static java.lang.String |
escapeXML(java.lang.String val)
Escape the specified String, suitable for an XML attribute value |
static java.lang.String |
getAttribute(org.w3c.dom.Element elem,
java.lang.String key)
Returns the value for the specified attribute key, or null if the key is not defined in the specified Element |
static java.lang.String |
getAttribute(org.w3c.dom.Element elem,
java.lang.String key,
java.lang.String dft)
Returns the value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static java.lang.String |
getAttribute(org.w3c.dom.Element elem,
java.lang.String key,
java.lang.String dft,
boolean resolveRT)
Returns the value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static boolean |
getAttributeBoolean(org.w3c.dom.Element elem,
java.lang.String key,
boolean dft)
Returns the boolean value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static boolean |
getAttributeBoolean(org.w3c.dom.Element elem,
java.lang.String key,
boolean dft,
boolean resolveRT)
Returns the boolean value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static double |
getAttributeDouble(org.w3c.dom.Element elem,
java.lang.String key,
double dft)
Returns the double value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static double |
getAttributeDouble(org.w3c.dom.Element elem,
java.lang.String key,
double dft,
boolean resolveRT)
Returns the double value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static int |
getAttributeInt(org.w3c.dom.Element elem,
java.lang.String key,
int dft)
Returns the int value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static int |
getAttributeInt(org.w3c.dom.Element elem,
java.lang.String key,
int dft,
boolean resolveRT)
Returns the int value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static long |
getAttributeLong(org.w3c.dom.Element elem,
java.lang.String key,
long dft)
Returns the long value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static long |
getAttributeLong(org.w3c.dom.Element elem,
java.lang.String key,
long dft,
boolean resolveRT)
Returns the long value for the specified attribute key, or the default value if the key is not defined in the specified Element |
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Node root,
java.lang.String name)
Gets the first child element of the specified Node having the specified name |
static org.w3c.dom.NodeList |
getChildElements(org.w3c.dom.Node root,
java.lang.String name)
Gets all child elements of the specified Node having the specified name |
static org.w3c.dom.Document |
getDocument(byte[] xml)
Load and parse a XML document from an array of bytes |
static org.w3c.dom.Document |
getDocument(byte[] xml,
boolean checkErrors)
Load and parse a XML document from an array of bytes |
static org.w3c.dom.Document |
getDocument(java.io.File xmlFile)
Load and parses a XML document from a file |
static org.w3c.dom.Document |
getDocument(java.io.File xmlFile,
boolean checkErrors)
Load and parses a XML document from a file |
static org.w3c.dom.Document |
getDocument(java.io.InputStream input)
Load and parse a XML document from an input stream |
static org.w3c.dom.Document |
getDocument(java.io.InputStream input,
boolean checkErrors)
Load and parse a XML document from an input stream |
static org.w3c.dom.Document |
getDocument(java.lang.String xml)
Load and parse a XML document from a String |
static org.w3c.dom.Document |
getDocument(java.lang.String xml,
boolean checkErrors)
Load and parse a XML document from a String |
static java.lang.String |
getNodeText(org.w3c.dom.Node root)
Parse text from node. |
static java.lang.String |
getNodeText(org.w3c.dom.Node root,
java.lang.String repNewline)
Parse text from node. |
static java.lang.String |
getNodeText(org.w3c.dom.Node root,
java.lang.String repNewline,
boolean resolveRT)
Parse text from node. |
static java.lang.String |
getNodeText(org.w3c.dom.Node root,
java.lang.String repNewline,
boolean resolveRT,
java.lang.String dft)
Parse text from node. |
static org.w3c.dom.Element |
getPathElement(org.w3c.dom.Element root,
java.lang.String nodes)
Gets an element by a relative path from root |
static org.w3c.dom.Element |
getPathElement(org.w3c.dom.Element root,
java.util.StringTokenizer nodes)
Gets an element by a relative path from root |
static java.lang.String |
getPathText(org.w3c.dom.Element root,
java.lang.String nodes)
Gets gets the path of an element found at a relative path from root |
static void |
main(java.lang.String[] argv)
Main entry point for testing/debugging |
static java.lang.String |
nodeToString(org.w3c.dom.Node n)
|
static java.lang.String[] |
parseLines(java.lang.String text)
Parse String into an array terminated by CR, NL, or CRNL |
static java.lang.String |
PREFIX(boolean isSoapReq,
int indent)
Create prefix spaces |
static void |
printNodeTree(java.lang.String indent,
org.w3c.dom.Node n)
|
static java.lang.String |
startTAG(boolean isSoapReq,
java.lang.String tag,
java.lang.String attr,
boolean endTag,
boolean newLine)
Start tag |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLTools()
Method Detail |
---|
public static java.lang.String escapeXML(java.lang.String val)
public static java.lang.String startTAG(boolean isSoapReq, java.lang.String tag, java.lang.String attr, boolean endTag, boolean newLine)
public static java.lang.String endTAG(boolean isSoapReq, java.lang.String tag, boolean newLine)
public static java.lang.String CDATA(boolean isSoapReq, java.lang.String content)
public static java.lang.String PREFIX(boolean isSoapReq, int indent)
public static java.lang.String ATTR(java.lang.String key, java.lang.Object value)
public static java.lang.String ATTR(java.lang.String key, java.lang.String value)
public static java.lang.String ATTR(java.lang.String key, int value)
public static java.lang.String ATTR(java.lang.String key, long value)
public static java.lang.String ATTR(java.lang.String key, boolean value)
public static org.w3c.dom.Document getDocument(java.io.File xmlFile)
xmlFile
- The file to load the document from
public static org.w3c.dom.Document getDocument(java.io.File xmlFile, boolean checkErrors)
xmlFile
- The file to load the document fromcheckErrors
- True if the XML document should be validated
against it's DTD
public static org.w3c.dom.Document getDocument(java.io.InputStream input)
input
- The input stream to read the document from
public static org.w3c.dom.Document getDocument(java.io.InputStream input, boolean checkErrors)
input
- The input stream to read the document fromcheckErrors
- True if the XML document should be validated
against it's DTD
public static org.w3c.dom.Document getDocument(byte[] xml)
xml
- The byte array to read the document from
public static org.w3c.dom.Document getDocument(byte[] xml, boolean checkErrors)
xml
- The byte array to read the document fromcheckErrors
- True if the XML document should be validated
against it's DTD
public static org.w3c.dom.Document getDocument(java.lang.String xml)
xml
- The String to read the document from
public static org.w3c.dom.Document getDocument(java.lang.String xml, boolean checkErrors)
xml
- The String to read the document fromcheckErrors
- True if the XML document should be validated
against it's DTD
public static java.lang.String getNodeText(org.w3c.dom.Node root)
root
Node.
This method does not return null.
root
- The node to get the text of
public static java.lang.String getNodeText(org.w3c.dom.Node root, java.lang.String repNewline)
root
Node.
This method does not return null.
root
- The node to get the text ofrepNewline
- The string to replace any newlines with
public static java.lang.String getNodeText(org.w3c.dom.Node root, java.lang.String repNewline, boolean resolveRT)
root
Node.
This method does not return null.
root
- The node to get the text ofrepNewline
- The string to replace any newlines withresolveRT
- If true, resolve any runtime config variables
public static java.lang.String getNodeText(org.w3c.dom.Node root, java.lang.String repNewline, boolean resolveRT, java.lang.String dft)
root
Node. This method
may return the specified default value, dft
.
root
- The node to get the text ofrepNewline
- The string to replace any newlines withresolveRT
- If true, resolve any runtime config variablesdft
- The default value to return if no text was found
public static java.lang.String[] parseLines(java.lang.String text)
text
- The String text to parse
public static java.lang.String getAttribute(org.w3c.dom.Element elem, java.lang.String key)
elem
- The Element from which the key attribute will be returnedkey
- The attribute key
public static java.lang.String getAttribute(org.w3c.dom.Element elem, java.lang.String key, java.lang.String dft)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default value to return if the key is not defined
public static java.lang.String getAttribute(org.w3c.dom.Element elem, java.lang.String key, java.lang.String dft, boolean resolveRT)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default value to return if the key is not definedresolveRT
- If true, resolve any runtime config variables
public static boolean getAttributeBoolean(org.w3c.dom.Element elem, java.lang.String key, boolean dft)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default boolean value to return if the key is not defined
public static boolean getAttributeBoolean(org.w3c.dom.Element elem, java.lang.String key, boolean dft, boolean resolveRT)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default boolean value to return if the key is not definedresolveRT
- If true, resolve any runtime config variables
public static int getAttributeInt(org.w3c.dom.Element elem, java.lang.String key, int dft)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default int value to return if the key is not defined
public static int getAttributeInt(org.w3c.dom.Element elem, java.lang.String key, int dft, boolean resolveRT)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default int value to return if the key is not definedresolveRT
- If true, resolve any runtime config variables
public static long getAttributeLong(org.w3c.dom.Element elem, java.lang.String key, long dft)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default long value to return if the key is not defined
public static long getAttributeLong(org.w3c.dom.Element elem, java.lang.String key, long dft, boolean resolveRT)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default long value to return if the key is not definedresolveRT
- If true, resolve any runtime config variables
public static double getAttributeDouble(org.w3c.dom.Element elem, java.lang.String key, double dft)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default double value to return if the key is not defined
public static double getAttributeDouble(org.w3c.dom.Element elem, java.lang.String key, double dft, boolean resolveRT)
elem
- The Element from which the key attribute will be returnedkey
- The attribute keydft
- The default double value to return if the key is not definedresolveRT
- If true, resolve any runtime config variables
public static org.w3c.dom.Element getChildElement(org.w3c.dom.Node root, java.lang.String name)
root
- The Node to look for the child element inname
- The name of the child element
public static org.w3c.dom.NodeList getChildElements(org.w3c.dom.Node root, java.lang.String name)
root
- The Node to look for the child element inname
- The name of the child element
public static java.lang.String getPathText(org.w3c.dom.Element root, java.lang.String nodes)
root
root
- The root nodenodes
- The path to the child element, delimited with '/'
null
public static org.w3c.dom.Element getPathElement(org.w3c.dom.Element root, java.lang.String nodes)
root
root
- The root nodenodes
- The path to the child element, delimited with '/'
null
public static org.w3c.dom.Element getPathElement(org.w3c.dom.Element root, java.util.StringTokenizer nodes)
root
root
- The root nodenodes
- The path to the child element, delimited with '/'
null
public static java.lang.String nodeToString(org.w3c.dom.Node n)
public static void printNodeTree(java.lang.String indent, org.w3c.dom.Node n)
public static void main(java.lang.String[] argv)
argv
- Comand-line arguments
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |