|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dlese.dpc.xml.Dom4jUtils
public class Dom4jUtils
Utility methods for working with dom4j Documents.
Constructor Summary | |
---|---|
Dom4jUtils()
|
Method Summary | |
---|---|
static String |
delocalizeDocStr(String s,
String rootElementName,
String nameSpaceInfo)
Insert nameSpaceInformation into the root element to make validation possible. |
static Document |
delocalizeXml(Document doc,
String rootElementName,
String nameSpaceInfo)
Insert nameSpaceInformation into the root element |
static Object |
dom4j2JavaBean(Node javaObjectXmlNode)
Takes a dom4j Node that contains an XML serialized JavaBean and returns a JavaBean Object. |
protected static String |
getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout: |
static Transformer |
getLocalizingTransformer()
Gets the localizingTransformer attribute of the Dom4jUtils class |
static String |
getNameSpaceInfo(Document doc,
String rootElementName)
Gets the nameSpaceInfo associated with the root element of a Document. |
static Document |
getXmlDocument(File file)
Load an XML file into a dom4j Document. |
static Document |
getXmlDocument(File file,
String encoding)
Load an XML file into a dom4j Document using the given character encoding. |
static Document |
getXmlDocument(String s)
Load XML into a dom4j Document. |
static Document |
getXmlDocument(String url,
int timoutMs)
Load XML into a dom4j Document, specifying a max time to wait for resopnse. |
static Document |
getXmlDocument(URL url)
Load XML into a dom4j Document. |
static Document |
getXmlDocument(URL url,
int timoutMs)
Load XML into a dom4j Document, specifying a max time to wait for resopnse. |
static Document |
getXmlDocumentLocalized(String xml)
Load XML into a dom4j Document and localize the XML by removing all namespaces from it. |
static Document |
getXmlDocumentPostData(URL url,
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 XMLWriter |
getXMLWriter()
Gets an XMLWriter object |
static boolean |
isEmpty(Element e)
Gets the empty attribute of the Dom4jUtils class |
static boolean |
isEmpty(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 Document |
localizeXml(Document doc)
Localizes a Dom4j Document by removing all namespaces from it. |
static Document |
localizeXml(Document doc,
String rootElementName)
Remove nameSpaceInformation from the root element (as well as any attributes!) to facilitate xpath access |
static Element |
localizeXml(Element element)
Localizes a Dom4j Element by removing all namespaces from it. |
static Document |
localizeXml(Node node)
Localizes a Dom4j Node, Document, Branch or Element by removing all namespaces from it, returning a Document. |
static String |
localizeXml(String xml)
Localizes an XML String by removing all namespaces from it. |
static String |
localizeXml(String xml,
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(String msg)
Logger hook |
static String |
prettyPrint(Node node)
Formats an Node as a printable string |
protected static void |
prtln(String s)
Output a line of text to standard out, with datestamp, if debug is set to true. |
protected static void |
prtlnErr(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(Document doc,
File out)
Writes Document to File |
static void |
writeDocToFile(Document doc,
File out,
OutputFormat format)
Write XML Document to disk using specified OutputFormat |
static void |
writePrettyDocToFile(Document doc,
File out)
write formated xml to file to faciliate human-readibility |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Dom4jUtils()
Method Detail |
---|
public static Document getXmlDocument(File file) throws DocumentException, MalformedURLException
file
- An XML file
DocumentException
- If dom4j error
MalformedURLException
- If error in file namepublic static Document getXmlDocument(File file, String encoding) throws DocumentException, MalformedURLException, IOException
file
- An XML fileencoding
- The character encoding to use, for example 'UTF-8'
DocumentException
- If dom4j error
MalformedURLException
- If error in file name
IOException
- If IO errorpublic static Document getXmlDocument(URL url) throws DocumentException, MalformedURLException
url
- A URL to an XML document
DocumentException
- If dom4j error
MalformedURLException
- If error in the URLpublic static Document getXmlDocument(URL url, int timoutMs) throws DocumentException, MalformedURLException, IOException, URLConnectionTimedOutException
url
- A URL to an XML documenttimoutMs
- Number of milliseconds to wait before timming out, use 0 for
infinity
DocumentException
- If dom4j error
MalformedURLException
- If error in the URL
IOException
- If IO error
URLConnectionTimedOutException
- If no response before reaching timoutMspublic static Document getXmlDocument(String url, int timoutMs) throws DocumentException, MalformedURLException, IOException, URLConnectionTimedOutException
url
- A URL to an XML documenttimoutMs
- Number of milliseconds to wait before timming out, use 0 for
infinity
DocumentException
- If dom4j error
MalformedURLException
- If error in the URL
IOException
- If IO error
URLConnectionTimedOutException
- If no response before reaching timoutMspublic static Document getXmlDocumentPostData(URL url, String postData, int timoutMs) throws DocumentException, MalformedURLException, 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=value2
DocumentException
- If dom4j error
MalformedURLException
- If error in the URL
IOException
- If IO error
URLConnectionTimedOutException
- If no response before reaching timoutMspublic static Document getXmlDocument(String s) throws DocumentException
s
- A string representation of an XML document
DocumentException
- If dom4j errorpublic static Document getXmlDocumentLocalized(String xml) throws DocumentException
xml
- A string representation of an XML document
DocumentException
- If dom4j errorpublic static Object dom4j2JavaBean(Node javaObjectXmlNode) throws Exception
javaObjectXmlNode
- Dom4j Node
Exception
- If errorpublic static boolean isEmpty(Element e)
e
- NOT YET DOCUMENTED
public static boolean isEmpty(Element e, boolean ignoreWhiteSpace)
e
- an Element to testignoreWhiteSpace
- determines whether whitespace is considered as textual content .
public static String localizeXml(String xml, 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 Parameter
public static final Transformer getLocalizingTransformer() throws TransformerConfigurationException, FileNotFoundException
TransformerConfigurationException
- NOT YET DOCUMENTED
FileNotFoundException
- NOT YET DOCUMENTEDpublic static Document localizeXml(Document doc, String rootElementName)
doc
- Description of the ParameterrootElementName
- Description of the Parameter
public static String localizeXml(String xml)
xml
- XML as a String
public static Document localizeXml(Document doc)
doc
- The Document to localize
public static Element localizeXml(Element element)
element
- The Element to localize
public static Document localizeXml(Node node)
node
- The Node to localize
public static String delocalizeDocStr(String s, String rootElementName, String nameSpaceInfo)
NOTE: only delocalizes if the rootElement is empty.
s
- Description of the ParameterrootElementName
- Description of the ParameternameSpaceInfo
- Description of the Parameter
public static Document delocalizeXml(Document doc, String rootElementName, String nameSpaceInfo)
doc
- Description of the ParameterrootElementName
- Description of the ParameternameSpaceInfo
- Description of the Parameter
public static String getNameSpaceInfo(Document doc, String rootElementName)
doc
- Description of the ParameterrootElementName
- Description of the Parameter
public static void writeDocToFile(Document doc, File out) throws Exception
Document
to File
doc
- Description of the Parameterout
- Description of the Parameter
Exception
- Description of the Exceptionpublic static void writePrettyDocToFile(Document doc, File out) throws Exception
doc
- Description of the Parameterout
- Description of the Parameter
Exception
- Description of the Exceptionpublic static void writeDocToFile(Document doc, File out, OutputFormat format) throws Exception
doc
- Description of the Parameterout
- Description of the Parameterformat
- Description of the Parameter
Exception
- Description of the Exceptionpublic static XMLWriter getXMLWriter()
public static String prettyPrint(Node node)
Node
as a printable string
node
- the Node to display
public void log(String msg)
msg
- Message to be logged.protected static final String getDateStamp()
protected static final void prtlnErr(String s)
s
- The text that will be output to error out.protected static final void prtln(String s)
s
- The String that will be output.public static void setDebug(boolean db)
db
- The new debug value
|
DLESE Tools v1.6.0 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |