org.mule.module.xml.util
Class XMLUtils

java.lang.Object
  extended by org.mule.util.XMLUtils
      extended by org.mule.module.xml.util.XMLUtils

public class XMLUtils
extends XMLUtils

General utility methods for working with XML.


Field Summary
static String APACHE_XML_FEATURES_VALIDATION_SCHEMA
           
static String APACHE_XML_FEATURES_VALIDATION_SCHEMA_FULL_CHECKING
           
static String JAXP_PROPERTIES_SCHEMA_LANGUAGE
           
static String JAXP_PROPERTIES_SCHEMA_LANGUAGE_VALUE
           
static String JAXP_PROPERTIES_SCHEMA_SOURCE
           
static String TRANSFORMER_FACTORY_JDK5
           
 
Constructor Summary
XMLUtils()
           
 
Method Summary
static void copy(XMLStreamReader reader, XMLStreamWriter writer)
          Copies the reader to the writer.
static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment)
           
static Transformer getTransformer()
           
static List<Node> select(String xpath, Node node)
          Select a set of Node objects using the Xpath expression
static Node selectOne(String xpath, Node node)
          Select a single XML node using an Xpath
static String selectValue(String xpath, Node node)
          Select a single XML String value using an Xpath
static org.dom4j.Document toDocument(Object obj, MuleContext muleContext)
           
static org.dom4j.Document toDocument(Object obj, String externalSchemaLocation, MuleContext muleContext)
          Converts an object of unknown type to an org.dom4j.Document if possible.
static Source toStreamSource(XMLInputFactory xmlInputFactory, boolean useStaxSource, InputStream stream)
           
static Document toW3cDocument(Object payload)
          Converts a payload to a Document representation.
static String toXml(Document dom)
          Converts a DOM to an XML string.
static Source toXmlSource(XMLInputFactory xmlInputFactory, boolean useStaxSource, Object src)
          Convert our object to a Source type efficiently.
static XMLStreamReader toXMLStreamReader(XMLInputFactory factory, Object obj)
          Returns an XMLStreamReader for an object of unknown type if possible.
 
Methods inherited from class org.mule.util.XMLUtils
attributeName, elementToString, getTextChild, isLocalName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRANSFORMER_FACTORY_JDK5

public static final String TRANSFORMER_FACTORY_JDK5
See Also:
Constant Field Values

APACHE_XML_FEATURES_VALIDATION_SCHEMA

public static final String APACHE_XML_FEATURES_VALIDATION_SCHEMA
See Also:
Constant Field Values

APACHE_XML_FEATURES_VALIDATION_SCHEMA_FULL_CHECKING

public static final String APACHE_XML_FEATURES_VALIDATION_SCHEMA_FULL_CHECKING
See Also:
Constant Field Values

JAXP_PROPERTIES_SCHEMA_SOURCE

public static final String JAXP_PROPERTIES_SCHEMA_SOURCE
See Also:
Constant Field Values

JAXP_PROPERTIES_SCHEMA_LANGUAGE

public static final String JAXP_PROPERTIES_SCHEMA_LANGUAGE
See Also:
Constant Field Values

JAXP_PROPERTIES_SCHEMA_LANGUAGE_VALUE

public static final String JAXP_PROPERTIES_SCHEMA_LANGUAGE_VALUE
See Also:
Constant Field Values
Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

toXml

public static String toXml(Document dom)
Converts a DOM to an XML string.

Parameters:
dom - the dome object to convert
Returns:
A string representation of the document

getTransformer

public static Transformer getTransformer()
                                  throws TransformerConfigurationException
Returns:
a new XSLT transformer
Throws:
TransformerConfigurationException - if no TransformerFactory can be located in the runtime environment.

toDocument

public static org.dom4j.Document toDocument(Object obj,
                                            MuleContext muleContext)
                                     throws Exception
Throws:
Exception

toDocument

public static org.dom4j.Document toDocument(Object obj,
                                            String externalSchemaLocation,
                                            MuleContext muleContext)
                                     throws Exception
Converts an object of unknown type to an org.dom4j.Document if possible.

Returns:
null if object cannot be converted
Throws:
org.dom4j.DocumentException - if an error occurs while parsing
Exception

toW3cDocument

public static Document toW3cDocument(Object payload)
                              throws Exception
Converts a payload to a Document representation.

Reproduces the behavior from toDocument(Object, MuleContext) which works converting to Document.

Parameters:
payload - the payload to convert.
Returns:
a document from the payload or null if the payload is not a valid XML document.
Throws:
Exception

toXMLStreamReader

public static XMLStreamReader toXMLStreamReader(XMLInputFactory factory,
                                                Object obj)
                                         throws XMLStreamException
Returns an XMLStreamReader for an object of unknown type if possible.

Returns:
null if no XMLStreamReader can be created for the object type
Throws:
XMLStreamException

toXmlSource

public static Source toXmlSource(XMLInputFactory xmlInputFactory,
                                 boolean useStaxSource,
                                 Object src)
                          throws Exception
Convert our object to a Source type efficiently.

Throws:
Exception

toStreamSource

public static Source toStreamSource(XMLInputFactory xmlInputFactory,
                                    boolean useStaxSource,
                                    InputStream stream)
                             throws XMLStreamException
Throws:
XMLStreamException

copy

public static void copy(XMLStreamReader reader,
                        XMLStreamWriter writer)
                 throws XMLStreamException
Copies the reader to the writer. The start and end document methods must be handled on the writer manually. TODO: if the namespace on the reader has been declared previously to where we are in the stream, this probably won't work.

Parameters:
reader -
writer -
Throws:
XMLStreamException

copy

public static void copy(XMLStreamReader reader,
                        XMLStreamWriter writer,
                        boolean fragment)
                 throws XMLStreamException
Throws:
XMLStreamException

selectOne

public static Node selectOne(String xpath,
                             Node node)
                      throws XPathExpressionException
Select a single XML node using an Xpath

Parameters:
xpath - the XPath expression to evaluate
node - the node (or document) to exaluate on
Returns:
the result of the evaluation.
Throws:
XPathExpressionException - if the XPath expression is malformed and cannot be parsed

selectValue

public static String selectValue(String xpath,
                                 Node node)
                          throws XPathExpressionException
Select a single XML String value using an Xpath

Parameters:
xpath - the XPath expression to evaluate
node - the node (or document) to evaluate on
Returns:
the result of the evaluation.
Throws:
XPathExpressionException - if the XPath expression is malformed and cannot be parsed

select

public static List<Node> select(String xpath,
                                Node node)
                         throws XPathExpressionException
Select a set of Node objects using the Xpath expression

Parameters:
xpath - the XPath expression to evaluate
node - the node (or document) to evaluate on
Returns:
the result of the evaluation.
Throws:
XPathExpressionException - if the XPath expression is malformed and cannot be parsed


Copyright © 2003-2012 MuleSoft, Inc.. All Rights Reserved.