public class XmlDom4JHelper extends Object
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 and Description |
---|
XmlDom4JHelper() |
Modifier and Type | Method and Description |
---|---|
protected static void |
closeInputStream(InputStream strm)
Convenience method to close an input stream and handle (log and throw away) any exceptions.
|
static org.dom4j.Document |
convertToDom4JDoc(Document doc) |
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 |
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 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 |
saveDom(org.dom4j.Document doc,
OutputStream outputStream,
String encoding)
Write an XML document to a file using the specified character encoding.
|
static void |
saveDom(org.dom4j.Document doc,
OutputStream outputStream,
String encoding,
boolean suppressDeclaration) |
static void |
saveDom(org.dom4j.Document doc,
OutputStream outputStream,
String encoding,
boolean suppressDeclaration,
boolean prettyPrint) |
protected static StringBuffer |
transformXml(StreamSource xslSrc,
StreamSource docSrc,
Map params,
URIResolver resolver)
Use the transform specified by xslSrc and transform the document specified by docSrc, and return the resulting
document.
|
public static org.dom4j.Document getDocFromString(String strXml, EntityResolver resolver) throws org.pentaho.platform.api.util.XmlParseException
Document
from str
.str
- String containing the XML that will be used to create the Documentresolver
- 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.pentaho.platform.api.util.XmlParseException
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 validIOException
- 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
protected static final StringBuffer transformXml(StreamSource xslSrc, StreamSource docSrc, Map params, URIResolver resolver) throws TransformerConfigurationException, TransformerException
xslSrc
- StreamSrc containing the xsl transformdocSrc
- StreamSrc containing the document to be transformedparams
- Map of properties to set on the transformresolver
- URIResolver instance to resolve URI's in the output document.TransformerConfigurationException
- if the TransformerFactory fails to create a Transformer.TransformerException
- if actual transform fails.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 TransformerTransformerException
- 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.1rawValue
- String containing the XML to be encoded.public static void saveDom(org.dom4j.Document doc, OutputStream outputStream, String encoding) throws IOException
doc
- Document to be writtenoutputStream
- the output streamencoding
- 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.htmlIOException
public static void saveDom(org.dom4j.Document doc, OutputStream outputStream, String encoding, boolean suppressDeclaration) throws IOException
IOException
public static void saveDom(org.dom4j.Document doc, OutputStream outputStream, String encoding, boolean suppressDeclaration, boolean prettyPrint) throws IOException
IOException
protected static void closeInputStream(InputStream strm)
strm
- InputStream to be closedpublic 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)
public static org.dom4j.Document convertToDom4JDoc(Document doc) throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, org.dom4j.DocumentException
TransformerConfigurationException
TransformerException
TransformerFactoryConfigurationError
org.dom4j.DocumentException
Copyright © 2019 Hitachi Vantara. All rights reserved.