|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.pentaho.platform.util.xml.dom4j.XmlDom4JHelper
public class XmlDom4JHelper
A set of static methods to help in with: * the construction of XML DOM
Documents (org.dom4j.Document) from files, streams, and Strings * in the
creation of XML DOM Documents as the result of an XSLT transform * persisting
of XML DOM documents to the file system or a Writer
. * the
encoding of a String of Xml text
Design notes: This class should never have any dependencies (i.e. imports) on
anything on org.pentaho or com.pentaho or their decendant packages. In
general, methods in the class should not attempt to handle exceptions, but
should let the exceptions propogate to the caller to be handled there. Please
do not use european-reuse in this class. One of the primary design goals for
this class was to construct it in a way that it could be used without change
outside of the Pentaho platform. Related XML-helper type code that is
dependant on the platform should be moved "up" to XmlHelper.
Constructor Summary | |
---|---|
XmlDom4JHelper()
|
Method Summary | |
---|---|
static StringBuffer |
docToString(Document doc)
Convert a W3C Document to a String. |
static org.dom4j.Document |
getDocFromFile(File file,
EntityResolver resolver)
Create a Document from the contents of a file. |
static org.dom4j.Document |
getDocFromFile(String path,
EntityResolver resolver)
Create a Document from the contents of a file. |
static org.dom4j.Document |
getDocFromStream(InputStream inStream)
Create a Document from the contents of an input stream,
where the input stream contains valid XML. |
static org.dom4j.Document |
getDocFromStream(InputStream inStream,
EntityResolver resolver)
Create a Document from the contents of an input stream,
where the input stream contains valid XML. |
static org.dom4j.Document |
getDocFromString(String strXml,
EntityResolver resolver)
Create a Document from str . |
static org.dom4j.Document |
getDocFromString(String strXml,
String encoding,
EntityResolver resolver)
Create a Document from str . |
static String |
getNodeText(String xpath,
org.dom4j.Node rootNode)
|
static double |
getNodeText(String xpath,
org.dom4j.Node rootNode,
double defaultValue)
|
static long |
getNodeText(String xpath,
org.dom4j.Node rootNode,
long defaultValue)
|
static String |
getNodeText(String xpath,
org.dom4j.Node rootNode,
String defaultValue)
|
static String |
getXmlEncodedString(String rawValue)
convert any character in the XML input ( rawValue ) whose
code position is greater than or equal to 0x080 to its Numeric Character
Reference. |
static void |
main(String[] args)
|
static void |
saveDomToFile(org.dom4j.Document doc,
File file,
String encoding)
Write an XML document to a file using the specified character encoding. |
static void |
saveDomToFile(org.dom4j.Document doc,
String filePath,
String encoding)
Write an XML document to a file using the specified character encoding. |
static void |
saveDomToWriter(org.dom4j.Document doc,
Writer writer)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XmlDom4JHelper()
Method Detail |
---|
public static org.dom4j.Document getDocFromString(String strXml, String encoding, EntityResolver resolver) throws XmlParseException
Document
from str
.
str
- String containing the XML that will be used to create the Documentencoding
- String specifying the character encoding. The encoding of the xml
String can be discovered by calling CleanXmlHelper.getEncoding().resolver
- EntityResolver an instance of an EntityResolver that will resolve
any external URIs. See the docs on EntityResolver. null is an acceptable value.
Document
initialized with the xml in
strXml
.
org.dom4j.DocumentException
UnsupportedEncodingException
XmlParseException
public static org.dom4j.Document getDocFromString(String strXml, EntityResolver resolver) throws XmlParseException
Document
from str
.
str
- String containing the XML that will be used to create the Document
can be discovered by calling CleanXmlHelper.getEncoding().resolver
- EntityResolver an instance of an EntityResolver that will resolve
any external URIs. See the docs on EntityResolver. null is an acceptable value.
Document
initialized with the xml in
strXml
.
org.dom4j.DocumentException
XmlParseException
public static org.dom4j.Document getDocFromFile(String path, EntityResolver resolver) throws org.dom4j.DocumentException, IOException
Document
from the contents of a file.
path
- String containing the path to the file containing XML that will be
used to create the Document.resolver
- EntityResolver an instance of an EntityResolver that will resolve
any external URIs. See the docs on EntityResolver. null is an acceptable value.
Document
initialized with the xml in
strXml
.
org.dom4j.DocumentException
- if the document isn't valid
IOException
public static org.dom4j.Document getDocFromFile(File file, EntityResolver resolver) throws org.dom4j.DocumentException, IOException
Document
from the contents of a file.
path
- String containing the path to the file containing XML that will be
used to create the Document.resolver
- EntityResolver an instance of an EntityResolver that will resolve
any external URIs. See the docs on EntityResolver. null is an acceptable value.
Document
initialized with the xml in
strXml
.
org.dom4j.DocumentException
- if the document isn't valid
IOException
- if the file doesn't existpublic static org.dom4j.Document getDocFromStream(InputStream inStream, EntityResolver resolver) throws org.dom4j.DocumentException, IOException
Document
from the contents of an input stream,
where the input stream contains valid XML.
inStream
-
org.dom4j.DocumentException
IOException
public static org.dom4j.Document getDocFromStream(InputStream inStream) throws org.dom4j.DocumentException, IOException
Document
from the contents of an input stream,
where the input stream contains valid XML.
inStream
-
org.dom4j.DocumentException
IOException
public static final StringBuffer docToString(Document doc) throws TransformerConfigurationException, TransformerException
doc
- org.w3c.dom.Document to be converted to a String.
TransformerConfigurationException
- If unable to get an instance of a Transformer
TransformerException
- If the attempt to transform the document fails.public static String getXmlEncodedString(String rawValue)
rawValue
) whose
code position is greater than or equal to 0x080 to its Numeric Character
Reference. For a description of Numeric Character References see:
http://www.w3.org/TR/html4/charset.html#h-5.3.1
rawValue
- String containing the XML to be encoded.
public static void saveDomToFile(org.dom4j.Document doc, String filePath, String encoding) throws IOException
doc
- Document to be writtenfilePath
- path identifying the File that will be the output of the Documentencoding
- String specifying the character encoding. Can be null, in which
case the default encoding will be used. See
http://java.sun.com/j2se/1.5.0/docs/api/java/io/OutputStreamWriter.html
IOException
- if unable to obtain a FileWriter on the specified filepublic static void saveDomToFile(org.dom4j.Document doc, File file, String encoding) throws IOException
doc
- Document to be writtenfile
- File that will be the output of the Documentencoding
- String specifying the character encoding. Can be null, in which
case the default encoding will be used. See
http://java.sun.com/j2se/1.5.0/docs/api/java/io/OutputStreamWriter.html
IOException
- if unable to obtain a FileWriter on the specified filepublic static void saveDomToWriter(org.dom4j.Document doc, Writer writer) throws IOException
IOException
public static void main(String[] args)
public static String getNodeText(String xpath, org.dom4j.Node rootNode)
public static long getNodeText(String xpath, org.dom4j.Node rootNode, long defaultValue)
public static double getNodeText(String xpath, org.dom4j.Node rootNode, double defaultValue)
public static String getNodeText(String xpath, org.dom4j.Node rootNode, String defaultValue)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |