public class Dom4jUtils
extends java.lang.Object
| Constructor and Description |
|---|
Dom4jUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
delocalizeDocStr(java.lang.String s,
java.lang.String rootElementName,
java.lang.String nameSpaceInfo)
Insert nameSpaceInformation into the root element to make validation possible.
|
static org.dom4j.Document |
delocalizeXml(org.dom4j.Document doc,
java.lang.String rootElementName,
java.lang.String nameSpaceInfo)
Insert nameSpaceInformation into the root element
|
static java.lang.Object |
dom4j2JavaBean(org.dom4j.Node javaObjectXmlNode)
Takes a dom4j Node that contains an XML serialized JavaBean and returns a JavaBean Object.
|
protected static java.lang.String |
getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout:
|
static javax.xml.transform.Transformer |
getLocalizingTransformer()
Gets the localizingTransformer attribute of the Dom4jUtils class
|
static java.lang.String |
getNameSpaceInfo(org.dom4j.Document doc,
java.lang.String rootElementName)
Gets the nameSpaceInfo associated with the root element of a Document.
|
static org.dom4j.Document |
getXmlDocument(java.io.File file)
Load an XML file into a dom4j Document.
|
static org.dom4j.Document |
getXmlDocument(java.io.File file,
java.lang.String encoding)
Load an XML file into a dom4j Document using the given character encoding.
|
static org.dom4j.Document |
getXmlDocument(java.lang.String s)
Load XML into a dom4j Document.
|
static org.dom4j.Document |
getXmlDocument(java.lang.String url,
int timoutMs)
Load XML into a dom4j Document, specifying a max time to wait for resopnse.
|
static org.dom4j.Document |
getXmlDocument(java.net.URL url)
Load XML into a dom4j Document.
|
static org.dom4j.Document |
getXmlDocument(java.net.URL url,
int timoutMs)
Load XML into a dom4j Document, specifying a max time to wait for resopnse.
|
static org.dom4j.Document |
getXmlDocumentLocalized(java.lang.String xml)
Load XML into a dom4j Document and localize the XML by removing all namespaces from it.
|
static org.dom4j.Document |
getXmlDocumentPostData(java.net.URL url,
java.lang.String postData,
int timoutMs)
Post data to a URL and load the response XML into a dom4j Document, specifying a max time to wait for
resopnse.
|
static org.dom4j.io.XMLWriter |
getXMLWriter()
Gets an XMLWriter object
|
static boolean |
isEmpty(org.dom4j.Element e)
Gets the empty attribute of the Dom4jUtils class
|
static boolean |
isEmpty(org.dom4j.Element e,
boolean ignoreWhiteSpace)
isEmpty returns true if neither the element, or any children recursively, have textual content or have a
non-empty attribute.
|
static org.dom4j.Document |
localizeXml(org.dom4j.Document doc)
Localizes a Dom4j Document by removing all namespaces from it.
|
static org.dom4j.Document |
localizeXml(org.dom4j.Document doc,
java.lang.String rootElementName)
Remove nameSpaceInformation from the root element (as well as any attributes!) to facilitate xpath access
|
static org.dom4j.Element |
localizeXml(org.dom4j.Element element)
Localizes a Dom4j Element by removing all namespaces from it.
|
static org.dom4j.Document |
localizeXml(org.dom4j.Node node)
Localizes a Dom4j Node, Document, Branch or Element by removing all namespaces from it, returning a
Document.
|
static java.lang.String |
localizeXml(java.lang.String xml)
Localizes an XML String by removing all namespaces from it.
|
static java.lang.String |
localizeXml(java.lang.String xml,
java.lang.String elementName)
Strips all attributes (including namespace information) from a particular element within a string
representation of an XML element (having arbitrary content and subelements), then removes all namespace
prefixes throughout the xml using a trnasformer.
|
void |
log(java.lang.String msg)
Logger hook
|
static java.lang.String |
prettyPrint(org.dom4j.Node node)
Formats an
Node as a printable string |
protected static void |
prtln(java.lang.String s)
Output a line of text to standard out, with datestamp, if debug is set to true.
|
protected static void |
prtlnErr(java.lang.String s)
Output a line of text to error out, with datestamp.
|
static void |
setDebug(boolean db)
Sets the debug attribute of the object
|
static void |
writeDocToFile(org.dom4j.Document doc,
java.io.File out)
Writes
Document to File |
static void |
writeDocToFile(org.dom4j.Document doc,
java.io.File out,
org.dom4j.io.OutputFormat format)
Write XML Document to disk using specified OutputFormat
|
static void |
writePrettyDocToFile(org.dom4j.Document doc,
java.io.File out)
write formated xml to file to faciliate human-readibility
|
public static org.dom4j.Document getXmlDocument(java.io.File file)
throws org.dom4j.DocumentException,
java.net.MalformedURLException
file - An XML fileorg.dom4j.DocumentException - If dom4j errorjava.net.MalformedURLException - If error in file namepublic static org.dom4j.Document getXmlDocument(java.io.File file,
java.lang.String encoding)
throws org.dom4j.DocumentException,
java.net.MalformedURLException,
java.io.IOException
file - An XML fileencoding - The character encoding to use, for example 'UTF-8'org.dom4j.DocumentException - If dom4j errorjava.net.MalformedURLException - If error in file namejava.io.IOException - If IO errorpublic static org.dom4j.Document getXmlDocument(java.net.URL url)
throws org.dom4j.DocumentException,
java.net.MalformedURLException
url - A URL to an XML documentorg.dom4j.DocumentException - If dom4j errorjava.net.MalformedURLException - If error in the URLpublic static org.dom4j.Document getXmlDocument(java.net.URL url,
int timoutMs)
throws org.dom4j.DocumentException,
java.net.MalformedURLException,
java.io.IOException,
URLConnectionTimedOutException
url - A URL to an XML documenttimoutMs - Number of milliseconds to wait before timming out, use 0 for
infinityorg.dom4j.DocumentException - If dom4j errorjava.net.MalformedURLException - If error in the URLjava.io.IOException - If IO errorURLConnectionTimedOutException - If no response before reaching timoutMspublic static org.dom4j.Document getXmlDocument(java.lang.String url,
int timoutMs)
throws org.dom4j.DocumentException,
java.net.MalformedURLException,
java.io.IOException,
URLConnectionTimedOutException
url - A URL to an XML documenttimoutMs - Number of milliseconds to wait before timming out, use 0 for
infinityorg.dom4j.DocumentException - If dom4j errorjava.net.MalformedURLException - If error in the URLjava.io.IOException - If IO errorURLConnectionTimedOutException - If no response before reaching timoutMspublic static org.dom4j.Document getXmlDocumentPostData(java.net.URL url,
java.lang.String postData,
int timoutMs)
throws org.dom4j.DocumentException,
java.net.MalformedURLException,
java.io.IOException,
URLConnectionTimedOutException
url - A base URL to the service with no http paramstimoutMs - Number of milliseconds to wait before timming out, use 0 for
infinitypostData - Data to post in the request of the form
parm1=value1¶m2=value2org.dom4j.DocumentException - If dom4j errorjava.net.MalformedURLException - If error in the URLjava.io.IOException - If IO errorURLConnectionTimedOutException - If no response before reaching timoutMspublic static org.dom4j.Document getXmlDocument(java.lang.String s)
throws org.dom4j.DocumentException
s - A string representation of an XML documentorg.dom4j.DocumentException - If dom4j errorpublic static org.dom4j.Document getXmlDocumentLocalized(java.lang.String xml)
throws org.dom4j.DocumentException
xml - A string representation of an XML documentorg.dom4j.DocumentException - If dom4j errorpublic static java.lang.Object dom4j2JavaBean(org.dom4j.Node javaObjectXmlNode)
throws java.lang.Exception
javaObjectXmlNode - Dom4j Nodejava.lang.Exception - If errorpublic static boolean isEmpty(org.dom4j.Element e)
e - NOT YET DOCUMENTEDpublic static boolean isEmpty(org.dom4j.Element e,
boolean ignoreWhiteSpace)
e - an Element to testignoreWhiteSpace - determines whether whitespace is considered as textual content .public static java.lang.String localizeXml(java.lang.String xml,
java.lang.String elementName)
NOTE: this method is DANGEROUS because it not only strips namespace information, but all attributes from the element.
xml - Description of the ParameterelementName - Description of the Parameterpublic static final javax.xml.transform.Transformer getLocalizingTransformer()
throws javax.xml.transform.TransformerConfigurationException,
java.io.FileNotFoundException
javax.xml.transform.TransformerConfigurationException - NOT YET DOCUMENTEDjava.io.FileNotFoundException - NOT YET DOCUMENTEDpublic static org.dom4j.Document localizeXml(org.dom4j.Document doc,
java.lang.String rootElementName)
doc - Description of the ParameterrootElementName - Description of the Parameterpublic static java.lang.String localizeXml(java.lang.String xml)
xml - XML as a Stringpublic static org.dom4j.Document localizeXml(org.dom4j.Document doc)
doc - The Document to localizepublic static org.dom4j.Element localizeXml(org.dom4j.Element element)
element - The Element to localizepublic static org.dom4j.Document localizeXml(org.dom4j.Node node)
node - The Node to localizepublic static java.lang.String delocalizeDocStr(java.lang.String s,
java.lang.String rootElementName,
java.lang.String nameSpaceInfo)
NOTE: only delocalizes if the rootElement is empty.
s - Description of the ParameterrootElementName - Description of the ParameternameSpaceInfo - Description of the Parameterpublic static org.dom4j.Document delocalizeXml(org.dom4j.Document doc,
java.lang.String rootElementName,
java.lang.String nameSpaceInfo)
doc - Description of the ParameterrootElementName - Description of the ParameternameSpaceInfo - Description of the Parameterpublic static java.lang.String getNameSpaceInfo(org.dom4j.Document doc,
java.lang.String rootElementName)
doc - Description of the ParameterrootElementName - Description of the Parameterpublic static void writeDocToFile(org.dom4j.Document doc,
java.io.File out)
throws java.lang.Exception
Document to Filedoc - Description of the Parameterout - Description of the Parameterjava.lang.Exception - Description of the Exceptionpublic static void writePrettyDocToFile(org.dom4j.Document doc,
java.io.File out)
throws java.lang.Exception
doc - Description of the Parameterout - Description of the Parameterjava.lang.Exception - Description of the Exceptionpublic static void writeDocToFile(org.dom4j.Document doc,
java.io.File out,
org.dom4j.io.OutputFormat format)
throws java.lang.Exception
doc - Description of the Parameterout - Description of the Parameterformat - Description of the Parameterjava.lang.Exception - Description of the Exceptionpublic static org.dom4j.io.XMLWriter getXMLWriter()
public static java.lang.String prettyPrint(org.dom4j.Node node)
Node as a printable stringnode - the Node to displaypublic void log(java.lang.String msg)
msg - Message to be logged.protected static final java.lang.String getDateStamp()
protected static final void prtlnErr(java.lang.String s)
s - The text that will be output to error out.protected static final void prtln(java.lang.String s)
s - The String that will be output.public static void setDebug(boolean db)
db - The new debug value