global.sandbox.xmlutilities
Class XmlUtilities

java.lang.Object
  extended by global.sandbox.xmlutilities.XmlUtilities

public class XmlUtilities
extends Object

This class provides simple XML utilities.

Version:
1.2
Author:
Petr Hadraba

Field Summary
private  NamespaceContext defaultNamespaceContext
          Stores the default NamespaceContext.
private  DocumentBuilder documentBuilder
          Stores document builder.
private  DocumentBuilderFactory documentBuilderFactory
          Stores document builder factory.
private static Logger LOGGER
          Internal logger.
private  SchemaFactory schemaFactory
          Stores schema factory.
private  Transformer transformer
          Stores localTransformer.
private  TransformerFactory transformerFactory
          Stores localTransformer factory.
(package private) static String XMLUTILITIES_LOGGER_NAME
          Name of internal logger.
private  XPath xpath
          Stores XPath evaluator.
private  XPathFactory xpathFactory
          Stores XPath factory.
 
Constructor Summary
XmlUtilities()
          Initializes XML Utilities.
XmlUtilities(DocumentBuilderFactory documentBuilderFactory, DocumentBuilder documentBuilder, SchemaFactory schemaFactory, TransformerFactory transformerFactory, Transformer transformer, XPathFactory xpathFactory, XPath xpath, NamespaceContext defaultNamespaceContext)
          Initializes XML Utilities.
 
Method Summary
static void disableLogging()
          Disables logging of XmlTools and XmlUtilities.
(package private) static void disableLogging0()
          Disables logging.
 String documentToString(Document source)
          Converts XML Document into String.
 String documentToString(Document source, OutputFormat outputFormat)
          Converts XML Document into String.
 String documentToString(Document source, Properties outputProperties)
          Converts XML Document into String.
 NodeList evaluateXPath(String query, Node context)
          Evaluates specified XPath expression on specified context node.
<E extends Node>
NodeListCollection<E>
evaluateXPath(String query, Node context, Class<E> elementType)
          Evaluates specified XPath expression on specified context node and returns results as NodeListCollection of specified element types.
 NodeList evaluateXPath(String query, Node context, NamespaceContext namespaces)
          Evaluates specified XPath expression on specified context node.
<E extends Node>
NodeListCollection<E>
evaluateXPath(String query, Node context, NamespaceContext namespaces, Class<E> elementType)
          Evaluates specified XPath expression on specified context node and returns results as NodeListCollection of specified element types.
 NamespaceContext getDefaultNamespaceContext()
          Returns default NamespaceContext used by the XML Utilities.
 DocumentBuilder getDocumentBuilder()
          Returns DocumentBuilder object internally used by the XML Utilities.
 DocumentBuilderFactory getDocumentBuilderFactory()
          Returns DocumentBuilderFactory object internally used by the XML Utilities.
 Node getFirstNodeForXPath(String query, Node context)
          Evaluates specified XPath expression and returns first Node if XPath has matches.
<E extends Node>
E
getFirstNodeForXPath(String query, Node context, Class<E> elementType)
          Evaluates specified XPath expression and returns first Node as specified element type if XPath has matches.
 Node getFirstNodeForXPath(String query, Node context, NamespaceContext namespaces)
          Evaluates specified XPath expression and returns first Node if XPath has matches.
<E extends Node>
E
getFirstNodeForXPath(String query, Node context, NamespaceContext namespaces, Class<E> elementType)
          Evaluates specified XPath expression and returns first Node as specified element type if XPath has matches.
 SchemaFactory getSchemaFactory()
          Returns SchemaFactory object internally used by the XML Utilities.
 Transformer getTransformer()
          Returns Transformer object internally used by the XML Utilities.
 TransformerFactory getTransformerFactory()
          Returns TransformerFactory object internally used by the XML Utilities.
 XPath getXPath()
          Returns XPath object internally used by the XML Utilities.
 XPathFactory getXPathFactory()
          Returns XPathFactory object internally used by the XML Utilities.
 Document loadDocumentFromClassLoader(String resource, Class<?> fallbackClazz)
          Loads document from ClassLoaders.
 Document loadDocumentFromClassLoader(String resource, DocumentBuilder documentBuilder, Class<?> fallbackClazz)
          Loads document from ClassLoaders.
 Document loadDocumentFromFile(File file)
          Loads XML from file specified with the File object.
 Document loadDocumentFromFile(File file, DocumentBuilder documentBuilder)
          Loads XML from file specified with the file object.
 Document loadDocumentFromFile(String fileName)
          Loads XML from file specified with file name.
 Document loadDocumentFromFile(String fileName, DocumentBuilder documentBuilder)
          Loads XML from file specified with file name.
 Document loadDocumentFromResource(String resource, Class<?> clazz)
          Loads Document from resource from given class.
 Document loadDocumentFromResource(String resource, ClassLoader classLoader)
          Loads document from resource using specified ClassLoader.
 Document loadDocumentFromResource(String resource, DocumentBuilder documentBuilder, Class<?> clazz)
          Loads Document from resource from given class.
 Document loadDocumentFromResource(String resource, DocumentBuilder documentBuilder, ClassLoader classLoader)
          Loads document from resource using specified ClassLoader.
 Document loadDocumentFromStream(InputStream is)
          loads XML from specified input stream.
 Document loadDocumentFromStream(InputStream is, DocumentBuilder documentBuilder)
          Loads XML from specified input stream.
 Document loadDocumentFromStreamAndClose(InputStream is, boolean close)
          Loads XML from specified input stream and closes it if specified.
 Document loadDocumentFromStreamAndClose(InputStream is, DocumentBuilder documentBuilder, boolean close)
          Loads XML from specified input stream and closes it if specified.
 Document loadDocumentFromString(String source)
          Loads document from String into the Document.
 Document loadDocumentFromString(String source, DocumentBuilder documentBuilder)
          Loads document from String into the Document.
static void setLoggingLevel(Level newLevel)
          Sets new logging level of XmlTools and XmlUtilities.
(package private) static void setLoggingLevel0(Level newLevel)
          Sets new logging level.
 String sourceToString(Source source)
          Converts XML Source into String.
 String sourceToString(Source source, OutputFormat outputFormat)
          Converts XML Source into String.
 String sourceToString(Source source, Properties outputProperties)
          Converts XML Source into String.
 Document transformToDocument(Source xsltTemplate, Source document)
          Transforms specified XML document using specified XSLT template.
 Document transformToDocument(Source xsltTemplate, Source document, Map<String,Object> parameters)
          Transforms specified XML document using specified XSLT template.
 Document transformToDocument(Templates xsltTemplate, Source document)
          Transforms specified XML document using XSLT (compiled) template.
 Document transformToDocument(Templates xsltTemplate, Source document, Map<String,Object> parameters)
          Transforms specified XML using XSLT (compiled) template.
 String transformToString(Source xsltTemplate, Source document)
          Transforms specified XML document using specified XSLT template.
 String transformToString(Source xsltTemplate, Source document, Map<String,Object> parameters)
          Transforms specified XML source using specified XSLT template.
 String transformToString(Templates xsltTemplate, Source document)
          Transforms specified XML source using specified XSLT (compiled) template.
 String transformToString(Templates xsltTemplate, Source document, Map<String,Object> parameters)
          Transforms specified XML source using specified XSLT (compiled) template.
 String validateXmlUsingSchema(Source xmlDocument, Source xmlSchema)
          Validates XML Document against XML Schema.
 void writeDocumentToBufferedStreamAndClose(Document doc, OutputStream os, Integer bufferSize)
          Writes Document to stream using internal buffer and closes the stream.
 void writeDocumentToBufferedStreamAndClose(Document doc, OutputStream os, Integer bufferSize, OutputFormat outputFormat)
          Writes Document to stream using internal buffer and closes the stream.
 void writeDocumentToBufferedStreamAndClose(Document doc, OutputStream os, Integer bufferSize, Properties outputProperties)
          Writes Document to stream using internal buffer and closes the stream.
 void writeDocumentToBufferedStreamAndClose(Document doc, OutputStream os, Integer bufferSize, Transformer transformer)
          Writes Document to stream using internal buffer and closes the stream.
 void writeDocumentToFile(Document doc, File file)
          Writes Document to specified file.
 void writeDocumentToFile(Document doc, File file, Integer bufferSize)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, File file, Integer bufferSize, OutputFormat outputFormat)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, File file, Integer bufferSize, Properties outputProperties)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, File file, Integer bufferSize, Transformer transformer)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, File file, OutputFormat outputFormat)
          Writes Document to specified file.
 void writeDocumentToFile(Document doc, File file, Properties outputProperties)
          Writes Document to specified file.
 void writeDocumentToFile(Document doc, File file, Transformer transformer)
          Writes Document to specified file.
 void writeDocumentToFile(Document doc, String file)
          Writes Document to specified file.
 void writeDocumentToFile(Document doc, String file, Integer bufferSize)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, String file, Integer bufferSize, OutputFormat outputFormat)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, String file, Integer bufferSize, Properties outputProperties)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, String file, Integer bufferSize, Transformer transformer)
          Writes Document to specified file using internal buffer.
 void writeDocumentToFile(Document doc, String file, OutputFormat outputFormat)
          Writes Document to specified file.
 void writeDocumentToFile(Document doc, String file, Properties outputProperties)
          Writes Document to specified file.
 void writeDocumentToFile(Document doc, String file, Transformer transformer)
          Writes Document to specified file.
 void writeDocumentToStream(Document doc, OutputStream os)
          Writes specified document into specified output stream.
 void writeDocumentToStream(Document doc, OutputStream os, OutputFormat outputFormat)
          Writes specified document into specified stream and specified output format.
 void writeDocumentToStream(Document doc, OutputStream os, Properties outputProperties)
          Writes specified document into specified stream and specified output format properties.
 void writeDocumentToStream(Document doc, OutputStream os, Transformer transformer)
          Writes specified document into specified stream and specified Transformer.
 void writeDocumentToStreamAndClose(Document doc, OutputStream os, boolean close)
          Writes specified document into specified output stream.
 void writeDocumentToStreamAndClose(Document doc, OutputStream os, boolean close, OutputFormat outputFormat)
          Writes specified document into specified stream and specified output format.
 void writeDocumentToStreamAndClose(Document doc, OutputStream os, boolean close, Properties outputProperties)
          Writes specified document into specified stream and specified output format properties.
 void writeDocumentToStreamAndClose(Document doc, OutputStream os, boolean close, Transformer transformer)
          Writes specified document into specified stream and specified Transformer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XMLUTILITIES_LOGGER_NAME

static final String XMLUTILITIES_LOGGER_NAME
Name of internal logger.


LOGGER

private static final Logger LOGGER
Internal logger.


schemaFactory

private final SchemaFactory schemaFactory
Stores schema factory.


documentBuilderFactory

private final DocumentBuilderFactory documentBuilderFactory
Stores document builder factory.


documentBuilder

private final DocumentBuilder documentBuilder
Stores document builder.


transformerFactory

private final TransformerFactory transformerFactory
Stores localTransformer factory.


transformer

private final Transformer transformer
Stores localTransformer.


xpathFactory

private final XPathFactory xpathFactory
Stores XPath factory.


xpath

private final XPath xpath
Stores XPath evaluator.


defaultNamespaceContext

private final NamespaceContext defaultNamespaceContext
Stores the default NamespaceContext.

Constructor Detail

XmlUtilities

public XmlUtilities()
             throws XmlUtilitiesException
Initializes XML Utilities. Creates new factories and new default instances.

Throws:
XmlUtilitiesException - on error

XmlUtilities

public XmlUtilities(DocumentBuilderFactory documentBuilderFactory,
                    DocumentBuilder documentBuilder,
                    SchemaFactory schemaFactory,
                    TransformerFactory transformerFactory,
                    Transformer transformer,
                    XPathFactory xpathFactory,
                    XPath xpath,
                    NamespaceContext defaultNamespaceContext)
             throws XmlUtilitiesException
Initializes XML Utilities. Creates new factories and new instances according to custom objects.

Parameters:
documentBuilderFactory - custom DocumentBuilderFactory
documentBuilder - custom DocumentBuilder
schemaFactory - custom SchemaFactory
transformerFactory - custom TransformerFactory
transformer - custom Transformer
xpathFactory - custom XPathFactory
xpath - custom XPath
defaultNamespaceContext - custom name spaces
Throws:
XmlUtilitiesException - on error
Method Detail

getSchemaFactory

public SchemaFactory getSchemaFactory()
Returns SchemaFactory object internally used by the XML Utilities.

Returns:
SchemaFactory object

getDocumentBuilderFactory

public DocumentBuilderFactory getDocumentBuilderFactory()
Returns DocumentBuilderFactory object internally used by the XML Utilities.

Returns:
DocumentBuilderFactory object

getDocumentBuilder

public DocumentBuilder getDocumentBuilder()
Returns DocumentBuilder object internally used by the XML Utilities.

Returns:
DocumentBuilder object

getTransformerFactory

public TransformerFactory getTransformerFactory()
Returns TransformerFactory object internally used by the XML Utilities.

Returns:
TransformerFactory object

getTransformer

public Transformer getTransformer()
Returns Transformer object internally used by the XML Utilities.

Returns:
Transformer object

getXPathFactory

public XPathFactory getXPathFactory()
Returns XPathFactory object internally used by the XML Utilities.

Returns:
XPathFactory object

getXPath

public XPath getXPath()
Returns XPath object internally used by the XML Utilities.

Returns:
XPath object

getDefaultNamespaceContext

public NamespaceContext getDefaultNamespaceContext()
Returns default NamespaceContext used by the XML Utilities.

Returns:
default NamespaceContenxt object

validateXmlUsingSchema

public String validateXmlUsingSchema(Source xmlDocument,
                                     Source xmlSchema)
                              throws XmlUtilitiesException
Validates XML Document against XML Schema.

Parameters:
xmlDocument - document to validate
xmlSchema - XMLSchema
Returns:
null if successful, string with error otherwise
Throws:
XmlUtilitiesException - on error

loadDocumentFromFile

public Document loadDocumentFromFile(String fileName)
                              throws XmlUtilitiesException
Loads XML from file specified with file name.

Parameters:
fileName - file to load
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromFile

public Document loadDocumentFromFile(String fileName,
                                     DocumentBuilder documentBuilder)
                              throws XmlUtilitiesException
Loads XML from file specified with file name.

Parameters:
fileName - file to load
documentBuilder - custom document builder
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromFile

public Document loadDocumentFromFile(File file)
                              throws XmlUtilitiesException
Loads XML from file specified with the File object.

Parameters:
file - file to load
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromFile

public Document loadDocumentFromFile(File file,
                                     DocumentBuilder documentBuilder)
                              throws XmlUtilitiesException
Loads XML from file specified with the file object.

Parameters:
file - file to load
documentBuilder - custom document builder
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromStream

public Document loadDocumentFromStream(InputStream is)
                                throws XmlUtilitiesException
loads XML from specified input stream. The stream is not being closed.

Parameters:
is - input stream
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromStream

public Document loadDocumentFromStream(InputStream is,
                                       DocumentBuilder documentBuilder)
                                throws XmlUtilitiesException
Loads XML from specified input stream. The stream is not being closed.

Parameters:
is - input stream
documentBuilder - custom Document Builder
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromStreamAndClose

public Document loadDocumentFromStreamAndClose(InputStream is,
                                               boolean close)
                                        throws XmlUtilitiesException
Loads XML from specified input stream and closes it if specified.

Parameters:
is - input stream
close - true to close input stream, false to leave it unclosed
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromStreamAndClose

public Document loadDocumentFromStreamAndClose(InputStream is,
                                               DocumentBuilder documentBuilder,
                                               boolean close)
                                        throws XmlUtilitiesException
Loads XML from specified input stream and closes it if specified.

Parameters:
is - input stream
documentBuilder - custom Document Builder
close - true to close input stream, false to leave it unclosed
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromClassLoader

public Document loadDocumentFromClassLoader(String resource,
                                            Class<?> fallbackClazz)
                                     throws XmlUtilitiesException
Loads document from ClassLoaders. The first of ContextClassLoader, fallBackClazz#getClassLoader() or SystemClassLoader is used whichever is find first.

Parameters:
resource - resource name to load from
fallbackClazz - ClassLoader to use if ContextClassLoader does not exist
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromClassLoader

public Document loadDocumentFromClassLoader(String resource,
                                            DocumentBuilder documentBuilder,
                                            Class<?> fallbackClazz)
                                     throws XmlUtilitiesException
Loads document from ClassLoaders. The first of ContextClassLoader, fallBackClazz#getClassLoader() or SystemClassLoader is used whichever is find first.

Parameters:
resource - resource name to load from
documentBuilder - custom DocumentBuilder
fallbackClazz - ClassLoader to use if ContextClassLoader does not exist
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromResource

public Document loadDocumentFromResource(String resource,
                                         Class<?> clazz)
                                  throws XmlUtilitiesException
Loads Document from resource from given class.

Parameters:
resource - resource to load
clazz - class to use
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromResource

public Document loadDocumentFromResource(String resource,
                                         DocumentBuilder documentBuilder,
                                         Class<?> clazz)
                                  throws XmlUtilitiesException
Loads Document from resource from given class.

Parameters:
resource - resource to load
documentBuilder - custom DocumentBuilder
clazz - class to use
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromResource

public Document loadDocumentFromResource(String resource,
                                         ClassLoader classLoader)
                                  throws XmlUtilitiesException
Loads document from resource using specified ClassLoader.

Parameters:
resource - resource to load
classLoader - ClassLoader to use
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromResource

public Document loadDocumentFromResource(String resource,
                                         DocumentBuilder documentBuilder,
                                         ClassLoader classLoader)
                                  throws XmlUtilitiesException
Loads document from resource using specified ClassLoader.

Parameters:
resource - resource to load
documentBuilder - custom DocumentBuilder
classLoader - ClassLoader to use
Returns:
Document object
Throws:
XmlUtilitiesException - on error

loadDocumentFromString

public Document loadDocumentFromString(String source)
                                throws XmlUtilitiesException
Loads document from String into the Document.

Parameters:
source - source XML
Returns:
resulting XML
Throws:
XmlUtilitiesException - on error

loadDocumentFromString

public Document loadDocumentFromString(String source,
                                       DocumentBuilder documentBuilder)
                                throws XmlUtilitiesException
Loads document from String into the Document.

Parameters:
source - source XML
documentBuilder - custom document builder
Returns:
resulting XML
Throws:
XmlUtilitiesException - on error

documentToString

public String documentToString(Document source)
                        throws XmlUtilitiesException
Converts XML Document into String.

Parameters:
source - Document to convert
Returns:
XML in the String
Throws:
XmlUtilitiesException - on error

documentToString

public String documentToString(Document source,
                               OutputFormat outputFormat)
                        throws XmlUtilitiesException
Converts XML Document into String.

Parameters:
source - Document to convert
outputFormat - output format configuration
Returns:
XML in the String
Throws:
XmlUtilitiesException - on error

documentToString

public String documentToString(Document source,
                               Properties outputProperties)
                        throws XmlUtilitiesException
Converts XML Document into String.

Parameters:
source - Document to convert
outputProperties - output properties (see OutputFormat)
Returns:
XML in the String
Throws:
XmlUtilitiesException - on error

sourceToString

public String sourceToString(Source source)
                      throws XmlUtilitiesException
Converts XML Source into String.

Parameters:
source - Document to convert
Returns:
XML in the String
Throws:
XmlUtilitiesException - on error

sourceToString

public String sourceToString(Source source,
                             OutputFormat outputFormat)
                      throws XmlUtilitiesException
Converts XML Source into String.

Parameters:
source - Document to convert
outputFormat - output format configuration
Returns:
XML in the String
Throws:
XmlUtilitiesException - on error

sourceToString

public String sourceToString(Source source,
                             Properties outputProperties)
                      throws XmlUtilitiesException
Converts XML Source into String.

Parameters:
source - Document to convert
outputProperties - output properties (see OutputFormat)
Returns:
XML in the String
Throws:
XmlUtilitiesException - on error

evaluateXPath

public NodeList evaluateXPath(String query,
                              Node context)
                       throws XmlUtilitiesException
Evaluates specified XPath expression on specified context node.

Parameters:
query - XPath expression
context - context node
Returns:
NodeList or null if no matches
Throws:
XmlUtilitiesException - on error

evaluateXPath

public NodeList evaluateXPath(String query,
                              Node context,
                              NamespaceContext namespaces)
                       throws XmlUtilitiesException
Evaluates specified XPath expression on specified context node.

Parameters:
query - XPath expression
context - context node
namespaces - name space context
Returns:
NodeList or null if no matches
Throws:
XmlUtilitiesException - on error

evaluateXPath

public <E extends Node> NodeListCollection<E> evaluateXPath(String query,
                                                            Node context,
                                                            Class<E> elementType)
                                                 throws XmlUtilitiesException
Evaluates specified XPath expression on specified context node and returns results as NodeListCollection of specified element types. This method never returns null.

Type Parameters:
E - type of element
Parameters:
query - XPath expression
context - context node
elementType - class type of element
Returns:
NodeListCollection of element type or empty list if no matches.
Throws:
XmlUtilitiesException - on error

evaluateXPath

public <E extends Node> NodeListCollection<E> evaluateXPath(String query,
                                                            Node context,
                                                            NamespaceContext namespaces,
                                                            Class<E> elementType)
                                                 throws XmlUtilitiesException
Evaluates specified XPath expression on specified context node and returns results as NodeListCollection of specified element types. This method never returns null.

Type Parameters:
E - type of element
Parameters:
query - XPath expression
context - context node
namespaces - name space context
elementType - class type of element
Returns:
NodeListCollection of element type or empty list if no matches.
Throws:
XmlUtilitiesException - on error

getFirstNodeForXPath

public Node getFirstNodeForXPath(String query,
                                 Node context)
                          throws XmlUtilitiesException
Evaluates specified XPath expression and returns first Node if XPath has matches.

Parameters:
query - XPath expression
context - context node
Returns:
first node or null
Throws:
XmlUtilitiesException - on error

getFirstNodeForXPath

public Node getFirstNodeForXPath(String query,
                                 Node context,
                                 NamespaceContext namespaces)
                          throws XmlUtilitiesException
Evaluates specified XPath expression and returns first Node if XPath has matches.

Parameters:
query - XPath expression
context - context node
namespaces - name space context
Returns:
first node or null
Throws:
XmlUtilitiesException - on error

getFirstNodeForXPath

public <E extends Node> E getFirstNodeForXPath(String query,
                                               Node context,
                                               Class<E> elementType)
                                    throws XmlUtilitiesException
Evaluates specified XPath expression and returns first Node as specified element type if XPath has matches.

Type Parameters:
E - type of element
Parameters:
query - XPath expression
context - context node
elementType - class type of element
Returns:
first node as specified type or null
Throws:
XmlUtilitiesException - on error

getFirstNodeForXPath

public <E extends Node> E getFirstNodeForXPath(String query,
                                               Node context,
                                               NamespaceContext namespaces,
                                               Class<E> elementType)
                                    throws XmlUtilitiesException
Evaluates specified XPath expression and returns first Node as specified element type if XPath has matches.

Type Parameters:
E - type of element
Parameters:
query - XPath expression
context - context node
namespaces - name space context
elementType - class type of element
Returns:
first node as specified type or null
Throws:
XmlUtilitiesException - on error

transformToString

public String transformToString(Source xsltTemplate,
                                Source document,
                                Map<String,Object> parameters)
                         throws XmlUtilitiesException
Transforms specified XML source using specified XSLT template.

Parameters:
xsltTemplate - template to use
document - source XML document
parameters - parameters to propagate to the localTransformer
Returns:
resulting XML in the String
Throws:
XmlUtilitiesException - on error

transformToString

public String transformToString(Templates xsltTemplate,
                                Source document,
                                Map<String,Object> parameters)
                         throws XmlUtilitiesException
Transforms specified XML source using specified XSLT (compiled) template.

Parameters:
xsltTemplate - template to use
document - source XML document to transform
parameters - parameters to propagate to the localTransformer
Returns:
resulting XML in the String
Throws:
XmlUtilitiesException - on error

transformToString

public String transformToString(Templates xsltTemplate,
                                Source document)
                         throws XmlUtilitiesException
Transforms specified XML source using specified XSLT (compiled) template.

Parameters:
xsltTemplate - template to use
document - source XML document to transform
Returns:
resulting XML in the String
Throws:
XmlUtilitiesException - on error

transformToString

public String transformToString(Source xsltTemplate,
                                Source document)
                         throws XmlUtilitiesException
Transforms specified XML document using specified XSLT template.

Parameters:
xsltTemplate - XSLT template
document - source XML document
Returns:
resulting XML document in the String
Throws:
XmlUtilitiesException - on error

transformToDocument

public Document transformToDocument(Source xsltTemplate,
                                    Source document)
                             throws XmlUtilitiesException
Transforms specified XML document using specified XSLT template.

Parameters:
xsltTemplate - XSLT template
document - source XML document
Returns:
resulting XML document in the Document
Throws:
XmlUtilitiesException - on error

transformToDocument

public Document transformToDocument(Templates xsltTemplate,
                                    Source document)
                             throws XmlUtilitiesException
Transforms specified XML document using XSLT (compiled) template.

Parameters:
xsltTemplate - template to use
document - document to transform
Returns:
resulting XML document in the Document
Throws:
XmlUtilitiesException - on error

transformToDocument

public Document transformToDocument(Source xsltTemplate,
                                    Source document,
                                    Map<String,Object> parameters)
                             throws XmlUtilitiesException
Transforms specified XML document using specified XSLT template.

Parameters:
xsltTemplate - XSLT template
document - source XML document
parameters - parameters for the template
Returns:
resulting XML document in the Document
Throws:
XmlUtilitiesException - on error

transformToDocument

public Document transformToDocument(Templates xsltTemplate,
                                    Source document,
                                    Map<String,Object> parameters)
                             throws XmlUtilitiesException
Transforms specified XML using XSLT (compiled) template.

Parameters:
xsltTemplate - template to use
document - XML document to transform
parameters - parameters for the transformation
Returns:
resulting XML document in the Document
Throws:
XmlUtilitiesException - on error

writeDocumentToStream

public void writeDocumentToStream(Document doc,
                                  OutputStream os)
                           throws XmlUtilitiesException
Writes specified document into specified output stream.

Parameters:
doc - document
os - output stream
Throws:
XmlUtilitiesException - on error

writeDocumentToStream

public void writeDocumentToStream(Document doc,
                                  OutputStream os,
                                  OutputFormat outputFormat)
                           throws XmlUtilitiesException
Writes specified document into specified stream and specified output format.

Parameters:
doc - document
os - output stream
outputFormat - output format
Throws:
XmlUtilitiesException - on error

writeDocumentToStream

public void writeDocumentToStream(Document doc,
                                  OutputStream os,
                                  Properties outputProperties)
                           throws XmlUtilitiesException
Writes specified document into specified stream and specified output format properties.

Parameters:
doc - document
os - output stream
outputProperties - output format properties
Throws:
XmlUtilitiesException - on error

writeDocumentToStream

public void writeDocumentToStream(Document doc,
                                  OutputStream os,
                                  Transformer transformer)
                           throws XmlUtilitiesException
Writes specified document into specified stream and specified Transformer.

Parameters:
doc - document
os - output stream
transformer - Transformer to use
Throws:
XmlUtilitiesException - on error

writeDocumentToStreamAndClose

public void writeDocumentToStreamAndClose(Document doc,
                                          OutputStream os,
                                          boolean close)
                                   throws XmlUtilitiesException
Writes specified document into specified output stream.

Parameters:
doc - document
os - output stream
close - tells if stream should be closed
Throws:
XmlUtilitiesException - on error

writeDocumentToStreamAndClose

public void writeDocumentToStreamAndClose(Document doc,
                                          OutputStream os,
                                          boolean close,
                                          OutputFormat outputFormat)
                                   throws XmlUtilitiesException
Writes specified document into specified stream and specified output format.

Parameters:
doc - document
os - output stream
close - tells if stream should be closed
outputFormat - output format
Throws:
XmlUtilitiesException - on error

writeDocumentToStreamAndClose

public void writeDocumentToStreamAndClose(Document doc,
                                          OutputStream os,
                                          boolean close,
                                          Properties outputProperties)
                                   throws XmlUtilitiesException
Writes specified document into specified stream and specified output format properties.

Parameters:
doc - document
os - output stream
close - tells if stream should be closed
outputProperties - output format properties
Throws:
XmlUtilitiesException - on error

writeDocumentToStreamAndClose

public void writeDocumentToStreamAndClose(Document doc,
                                          OutputStream os,
                                          boolean close,
                                          Transformer transformer)
                                   throws XmlUtilitiesException
Writes specified document into specified stream and specified Transformer.

Parameters:
doc - document
os - output stream
close - tells if stream should be closed
transformer - Transformer to use
Throws:
XmlUtilitiesException - on error

writeDocumentToBufferedStreamAndClose

public void writeDocumentToBufferedStreamAndClose(Document doc,
                                                  OutputStream os,
                                                  Integer bufferSize)
                                           throws XmlUtilitiesException
Writes Document to stream using internal buffer and closes the stream.

Parameters:
doc - Document to write
os - target stream
bufferSize - specified buffer size, null for default
Throws:
XmlUtilitiesException - on error

writeDocumentToBufferedStreamAndClose

public void writeDocumentToBufferedStreamAndClose(Document doc,
                                                  OutputStream os,
                                                  Integer bufferSize,
                                                  OutputFormat outputFormat)
                                           throws XmlUtilitiesException
Writes Document to stream using internal buffer and closes the stream.

Parameters:
doc - Document to write
os - target stream
bufferSize - specified buffer size, null for default
outputFormat - output format
Throws:
XmlUtilitiesException - on error

writeDocumentToBufferedStreamAndClose

public void writeDocumentToBufferedStreamAndClose(Document doc,
                                                  OutputStream os,
                                                  Integer bufferSize,
                                                  Properties outputProperties)
                                           throws XmlUtilitiesException
Writes Document to stream using internal buffer and closes the stream.

Parameters:
doc - Document to write
os - target stream
bufferSize - specified buffer size, null for default
outputProperties - output format properties
Throws:
XmlUtilitiesException - on error

writeDocumentToBufferedStreamAndClose

public void writeDocumentToBufferedStreamAndClose(Document doc,
                                                  OutputStream os,
                                                  Integer bufferSize,
                                                  Transformer transformer)
                                           throws XmlUtilitiesException
Writes Document to stream using internal buffer and closes the stream.

Parameters:
doc - Document to write
os - target stream
bufferSize - specified buffer size, null for default
transformer - transformer
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file,
                                OutputFormat outputFormat)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
outputFormat - output format
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file,
                                Properties outputProperties)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
outputProperties - output format properties
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file,
                                Transformer transformer)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
transformer - transformer
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file,
                                Integer bufferSize)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file,
                                Integer bufferSize,
                                OutputFormat outputFormat)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
outputFormat - output format
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file,
                                Integer bufferSize,
                                Properties outputProperties)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
outputProperties - output format properties
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                String file,
                                Integer bufferSize,
                                Transformer transformer)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
transformer - transformer
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file,
                                OutputFormat outputFormat)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
outputFormat - output format
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file,
                                Properties outputProperties)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
outputProperties - output format properties
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file,
                                Transformer transformer)
                         throws XmlUtilitiesException
Writes Document to specified file.

Parameters:
doc - document
file - target file
transformer - transformer
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file,
                                Integer bufferSize)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file,
                                Integer bufferSize,
                                OutputFormat outputFormat)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
outputFormat - output format
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file,
                                Integer bufferSize,
                                Properties outputProperties)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
outputProperties - output format properties
Throws:
XmlUtilitiesException - on error

writeDocumentToFile

public void writeDocumentToFile(Document doc,
                                File file,
                                Integer bufferSize,
                                Transformer transformer)
                         throws XmlUtilitiesException
Writes Document to specified file using internal buffer.

Parameters:
doc - document
file - target file
bufferSize - buffer size or null for default
transformer - transformer
Throws:
XmlUtilitiesException - on error

disableLogging

public static void disableLogging()
Disables logging of XmlTools and XmlUtilities.


disableLogging0

static void disableLogging0()
Disables logging.


setLoggingLevel

public static void setLoggingLevel(Level newLevel)
Sets new logging level of XmlTools and XmlUtilities.

Parameters:
newLevel - level to set

setLoggingLevel0

static void setLoggingLevel0(Level newLevel)
Sets new logging level.

Parameters:
newLevel - level to set


Copyright © 2006–2017. All rights reserved.