it.imolinfo.jbi4ejb.processor.transform
Class SourceTransformer

java.lang.Object
  extended by it.imolinfo.jbi4ejb.processor.transform.SourceTransformer

public class SourceTransformer
extends java.lang.Object

Taken from servicemix-core SourceTransformer and partially from StAXSoureTransformer class. // TODO AddStaxSource support

Author:
Marco Piraccini

Constructor Summary
SourceTransformer()
          Instantiates a new source transformer.
SourceTransformer(javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory)
          Instantiates a new source transformer.
 
Method Summary
 java.lang.String contentToString(javax.jbi.messaging.NormalizedMessage message)
          Converts the content of the given message to a String.
 org.w3c.dom.Document createDocument()
          Creates the document.
 javax.xml.parsers.DocumentBuilder createDocumentBuilder()
          Creates the document builder.
 javax.xml.parsers.DocumentBuilderFactory createDocumentBuilderFactory()
          Creates the document builder factory.
protected  javax.xml.stream.XMLInputFactory createInputFactory()
          Creates the input factory.
 javax.xml.transform.Transformer createTransfomer()
          Creates the transfomer.
 javax.xml.transform.TransformerFactory createTransformerFactory()
          Creates the transformer factory.
 javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
          Gets the document builder factory.
 javax.xml.stream.XMLInputFactory getInputFactory()
          Gets the input factory.
 javax.xml.transform.TransformerFactory getTransformerFactory()
          Gets the transformer factory.
 void setDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory)
          Sets the document builder factory.
 void setTransformerFactory(javax.xml.transform.TransformerFactory transformerFactory)
          Sets the transformer factory.
 org.w3c.dom.Document toDOMDocument(org.w3c.dom.Node node)
          Create a DOM document from the given Node.
 org.w3c.dom.Document toDOMDocument(javax.jbi.messaging.NormalizedMessage message)
          Create a DOM document from the given normalized message.
 org.w3c.dom.Document toDOMDocument(javax.xml.transform.Source source)
          Create a DOM document from the given source.
 org.w3c.dom.Element toDOMElement(org.w3c.dom.Node node)
          Create a DOM element from the DOM node.
 org.w3c.dom.Element toDOMElement(javax.jbi.messaging.NormalizedMessage message)
          Create a DOM element from the normalized message.
 org.w3c.dom.Element toDOMElement(javax.xml.transform.Source source)
          Create a DOM element from the given source.
 org.w3c.dom.Node toDOMNode(javax.jbi.messaging.NormalizedMessage message)
          Avoids multple parsing to DOM by caching the DOM representation in the message as a property so future calls will avoid the reparse - and avoid issues with stream based Source instances.
 org.w3c.dom.Node toDOMNode(javax.xml.transform.Source source)
          Converts the given TRaX Source into a W3C DOM node.
 org.w3c.dom.Node toDOMNodeFromSAX(javax.xml.transform.sax.SAXSource source)
          To DOM node from SAX.
 javax.xml.transform.Source toDOMSource(javax.jbi.messaging.NormalizedMessage message)
          To DOM source.
 javax.xml.transform.dom.DOMSource toDOMSource(javax.xml.transform.Source source)
          Converts the source instance to a DOMSource or returns null if the conversion is not supported (making it easy to derive from this class to add new kinds of conversion).
 javax.xml.transform.dom.DOMSource toDOMSourceFromSAX(javax.xml.transform.sax.SAXSource source)
          To DOM source from SAX.
 javax.xml.transform.dom.DOMSource toDOMSourceFromStream(javax.xml.transform.stream.StreamSource source)
          To DOM source from stream.
 java.io.Reader toReaderFromSource(javax.xml.transform.Source src)
          To reader from source.
 void toResult(javax.xml.transform.Source source, javax.xml.transform.Result result)
          Converts the given input Source into the required result.
 javax.xml.transform.sax.SAXSource toSAXSource(javax.xml.transform.Source source)
          Converts the source instance to a SAXSource or returns null if the conversion is not supported (making it easy to derive from this class to add new kinds of conversion).
 javax.xml.transform.sax.SAXSource toSAXSourceFromDOM(javax.xml.transform.dom.DOMSource source)
          To SAX source from DOM.
 javax.xml.transform.sax.SAXSource toSAXSourceFromStream(javax.xml.transform.stream.StreamSource source)
          To SAX source from stream.
 javax.xml.transform.stream.StreamSource toStreamSource(javax.xml.transform.Source source)
          To stream source.
 javax.xml.transform.stream.StreamSource toStreamSourceFromDOM(javax.xml.transform.dom.DOMSource source)
          To stream source from DOM.
 javax.xml.transform.stream.StreamSource toStreamSourceFromSAX(javax.xml.transform.sax.SAXSource source)
          To stream source from SAX.
 java.lang.String toString(org.w3c.dom.Node node)
          Converts the given input Node into text.
 java.lang.String toString(javax.xml.transform.Source source)
          Converts the given input Source into text.
 javax.xml.stream.XMLStreamReader toXMLStreamReader(javax.xml.transform.Source source)
          To XML stream reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceTransformer

public SourceTransformer()
Instantiates a new source transformer.


SourceTransformer

public SourceTransformer(javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory)
Instantiates a new source transformer.

Parameters:
documentBuilderFactory - the DocumentBuilderFactory
Method Detail

toResult

public void toResult(javax.xml.transform.Source source,
                     javax.xml.transform.Result result)
              throws javax.xml.transform.TransformerException
Converts the given input Source into the required result.

Parameters:
source - the source to transform
result - the result of the transformation
Throws:
javax.xml.transform.TransformerException - if some transformation error occurs

toString

public java.lang.String toString(javax.xml.transform.Source source)
                          throws javax.xml.transform.TransformerException
Converts the given input Source into text.

Parameters:
source - the source
Returns:
The String verions of the source
Throws:
javax.xml.transform.TransformerException - if some transformation error occurs

toString

public java.lang.String toString(org.w3c.dom.Node node)
                          throws javax.xml.transform.TransformerException
Converts the given input Node into text.

Parameters:
node - the Dom node
Returns:
The Node as a String
Throws:
javax.xml.transform.TransformerException - if some transformation error occurs

contentToString

public java.lang.String contentToString(javax.jbi.messaging.NormalizedMessage message)
                                 throws javax.jbi.messaging.MessagingException,
                                        javax.xml.transform.TransformerException,
                                        javax.xml.parsers.ParserConfigurationException,
                                        java.io.IOException,
                                        org.xml.sax.SAXException
Converts the content of the given message to a String.

Parameters:
message - The message
Returns:
The message content as String
Throws:
org.xml.sax.SAXException - If some problem occurs
java.io.IOException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
javax.jbi.messaging.MessagingException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

toDOMSource

public javax.xml.transform.dom.DOMSource toDOMSource(javax.xml.transform.Source source)
                                              throws javax.xml.parsers.ParserConfigurationException,
                                                     java.io.IOException,
                                                     org.xml.sax.SAXException,
                                                     javax.xml.transform.TransformerException
Converts the source instance to a DOMSource or returns null if the conversion is not supported (making it easy to derive from this class to add new kinds of conversion).

Parameters:
source - The source to transform
Returns:
The DOMSource from the source.
Throws:
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

toDOMSource

public javax.xml.transform.Source toDOMSource(javax.jbi.messaging.NormalizedMessage message)
                                       throws javax.jbi.messaging.MessagingException,
                                              javax.xml.transform.TransformerException,
                                              javax.xml.parsers.ParserConfigurationException,
                                              java.io.IOException,
                                              org.xml.sax.SAXException
To DOM source.

Parameters:
message - The NormalizedMessage
Returns:
the source
Throws:
javax.jbi.messaging.MessagingException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs

toSAXSource

public javax.xml.transform.sax.SAXSource toSAXSource(javax.xml.transform.Source source)
                                              throws java.io.IOException,
                                                     org.xml.sax.SAXException,
                                                     javax.xml.transform.TransformerException
Converts the source instance to a SAXSource or returns null if the conversion is not supported (making it easy to derive from this class to add new kinds of conversion).

Parameters:
source - The source to transform
Returns:
the SAXSource from the Source
Throws:
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

toStreamSource

public javax.xml.transform.stream.StreamSource toStreamSource(javax.xml.transform.Source source)
                                                       throws javax.xml.transform.TransformerException
To stream source.

Parameters:
source - The Source
Returns:
the stream source
Throws:
javax.xml.transform.TransformerException - If some problem occurs

toStreamSourceFromSAX

public javax.xml.transform.stream.StreamSource toStreamSourceFromSAX(javax.xml.transform.sax.SAXSource source)
                                                              throws javax.xml.transform.TransformerException
To stream source from SAX.

Parameters:
source - The Source
Returns:
the stream source
Throws:
javax.xml.transform.TransformerException - If some problem occurs

toStreamSourceFromDOM

public javax.xml.transform.stream.StreamSource toStreamSourceFromDOM(javax.xml.transform.dom.DOMSource source)
                                                              throws javax.xml.transform.TransformerException
To stream source from DOM.

Parameters:
source - The DOMSource
Returns:
the stream source
Throws:
javax.xml.transform.TransformerException - If some problem occurs

toSAXSourceFromStream

public javax.xml.transform.sax.SAXSource toSAXSourceFromStream(javax.xml.transform.stream.StreamSource source)
To SAX source from stream.

Parameters:
source - The Source
Returns:
the SAX source

toReaderFromSource

public java.io.Reader toReaderFromSource(javax.xml.transform.Source src)
                                  throws javax.xml.transform.TransformerException
To reader from source.

Parameters:
src - The source
Returns:
the reader
Throws:
javax.xml.transform.TransformerException - If some problem occurs

toDOMSourceFromStream

public javax.xml.transform.dom.DOMSource toDOMSourceFromStream(javax.xml.transform.stream.StreamSource source)
                                                        throws javax.xml.parsers.ParserConfigurationException,
                                                               java.io.IOException,
                                                               org.xml.sax.SAXException
To DOM source from stream.

Parameters:
source - The stream source
Returns:
the DOM source
Throws:
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs

toSAXSourceFromDOM

public javax.xml.transform.sax.SAXSource toSAXSourceFromDOM(javax.xml.transform.dom.DOMSource source)
                                                     throws javax.xml.transform.TransformerException
To SAX source from DOM.

Parameters:
source - The DOMSource
Returns:
the SAX source
Throws:
javax.xml.transform.TransformerException - If some problem occurs

toDOMSourceFromSAX

public javax.xml.transform.dom.DOMSource toDOMSourceFromSAX(javax.xml.transform.sax.SAXSource source)
                                                     throws java.io.IOException,
                                                            org.xml.sax.SAXException,
                                                            javax.xml.parsers.ParserConfigurationException,
                                                            javax.xml.transform.TransformerException
To DOM source from SAX.

Parameters:
source - The source
Returns:
the DOM source
Throws:
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

toDOMNodeFromSAX

public org.w3c.dom.Node toDOMNodeFromSAX(javax.xml.transform.sax.SAXSource source)
                                  throws javax.xml.parsers.ParserConfigurationException,
                                         java.io.IOException,
                                         org.xml.sax.SAXException,
                                         javax.xml.transform.TransformerException
To DOM node from SAX.

Parameters:
source - The Source
Returns:
the node
Throws:
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

toDOMNode

public org.w3c.dom.Node toDOMNode(javax.xml.transform.Source source)
                           throws javax.xml.transform.TransformerException,
                                  javax.xml.parsers.ParserConfigurationException,
                                  java.io.IOException,
                                  org.xml.sax.SAXException
Converts the given TRaX Source into a W3C DOM node.

Parameters:
source - The source
Returns:
The Node
Throws:
org.xml.sax.SAXException - If some problem occurs
java.io.IOException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

toDOMNode

public org.w3c.dom.Node toDOMNode(javax.jbi.messaging.NormalizedMessage message)
                           throws javax.jbi.messaging.MessagingException,
                                  javax.xml.transform.TransformerException,
                                  javax.xml.parsers.ParserConfigurationException,
                                  java.io.IOException,
                                  org.xml.sax.SAXException
Avoids multple parsing to DOM by caching the DOM representation in the message as a property so future calls will avoid the reparse - and avoid issues with stream based Source instances.

Parameters:
message - the normalized message
Returns:
the W3C DOM node for this message
Throws:
org.xml.sax.SAXException - If some problem occurs
java.io.IOException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
javax.jbi.messaging.MessagingException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

toDOMElement

public org.w3c.dom.Element toDOMElement(javax.jbi.messaging.NormalizedMessage message)
                                 throws javax.jbi.messaging.MessagingException,
                                        javax.xml.transform.TransformerException,
                                        javax.xml.parsers.ParserConfigurationException,
                                        java.io.IOException,
                                        org.xml.sax.SAXException
Create a DOM element from the normalized message.

Parameters:
message -
Returns:
The DOM element
Throws:
javax.jbi.messaging.MessagingException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException
org.xml.sax.SAXException

toDOMElement

public org.w3c.dom.Element toDOMElement(javax.xml.transform.Source source)
                                 throws javax.xml.transform.TransformerException,
                                        javax.xml.parsers.ParserConfigurationException,
                                        java.io.IOException,
                                        org.xml.sax.SAXException
Create a DOM element from the given source.

Parameters:
source - The Source
Returns:
The DOM element
Throws:
javax.xml.transform.TransformerException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs

toDOMElement

public org.w3c.dom.Element toDOMElement(org.w3c.dom.Node node)
                                 throws javax.xml.transform.TransformerException
Create a DOM element from the DOM node. Simply cast if the node is an Element, or return the root element if it is a Document.

Parameters:
node - The DOM node
Returns:
The DOM element
Throws:
javax.xml.transform.TransformerException - If some problem occurs

toDOMDocument

public org.w3c.dom.Document toDOMDocument(javax.jbi.messaging.NormalizedMessage message)
                                   throws javax.jbi.messaging.MessagingException,
                                          javax.xml.transform.TransformerException,
                                          javax.xml.parsers.ParserConfigurationException,
                                          java.io.IOException,
                                          org.xml.sax.SAXException
Create a DOM document from the given normalized message.

Parameters:
message - The NormalizedMessage
Returns:
The Document
Throws:
javax.jbi.messaging.MessagingException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs

toDOMDocument

public org.w3c.dom.Document toDOMDocument(javax.xml.transform.Source source)
                                   throws javax.xml.transform.TransformerException,
                                          javax.xml.parsers.ParserConfigurationException,
                                          java.io.IOException,
                                          org.xml.sax.SAXException
Create a DOM document from the given source.

Parameters:
source - The Source
Returns:
The DOM document
Throws:
javax.xml.transform.TransformerException - If some problem occurs
javax.xml.parsers.ParserConfigurationException - If some problem occurs
java.io.IOException - If some problem occurs
org.xml.sax.SAXException - If some problem occurs

toDOMDocument

public org.w3c.dom.Document toDOMDocument(org.w3c.dom.Node node)
                                   throws javax.xml.parsers.ParserConfigurationException,
                                          javax.xml.transform.TransformerException
Create a DOM document from the given Node. If the node is an document, just cast it, if the node is an root element, retrieve its owner element or create a new document and import the node.

Parameters:
node - The Node
Returns:
The DOM document
Throws:
javax.xml.parsers.ParserConfigurationException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

getDocumentBuilderFactory

public javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
Gets the document builder factory.

Returns:
the document builder factory

setDocumentBuilderFactory

public void setDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory)
Sets the document builder factory.

Parameters:
documentBuilderFactory - the new document builder factory

createDocumentBuilderFactory

public javax.xml.parsers.DocumentBuilderFactory createDocumentBuilderFactory()
Creates the document builder factory.

Returns:
the document builder factory

createDocumentBuilder

public javax.xml.parsers.DocumentBuilder createDocumentBuilder()
                                                        throws javax.xml.parsers.ParserConfigurationException
Creates the document builder.

Returns:
the document builder
Throws:
javax.xml.parsers.ParserConfigurationException - If some problem occurs

createDocument

public org.w3c.dom.Document createDocument()
                                    throws javax.xml.parsers.ParserConfigurationException
Creates the document.

Returns:
the document
Throws:
javax.xml.parsers.ParserConfigurationException - If some problem occurs

getTransformerFactory

public javax.xml.transform.TransformerFactory getTransformerFactory()
Gets the transformer factory.

Returns:
the transformer factory

setTransformerFactory

public void setTransformerFactory(javax.xml.transform.TransformerFactory transformerFactory)
Sets the transformer factory.

Parameters:
transformerFactory - the new transformer factory

createTransfomer

public javax.xml.transform.Transformer createTransfomer()
                                                 throws javax.xml.transform.TransformerConfigurationException
Creates the transfomer.

Returns:
the transformer
Throws:
javax.xml.transform.TransformerConfigurationException - If some problem occurs

createTransformerFactory

public javax.xml.transform.TransformerFactory createTransformerFactory()
Creates the transformer factory.

Returns:
the transformer factory

toXMLStreamReader

public javax.xml.stream.XMLStreamReader toXMLStreamReader(javax.xml.transform.Source source)
                                                   throws javax.xml.stream.XMLStreamException,
                                                          javax.xml.transform.TransformerException
To XML stream reader.

Parameters:
source - The Source
Returns:
the XML stream reader
Throws:
javax.xml.stream.XMLStreamException - If some problem occurs
javax.xml.transform.TransformerException - If some problem occurs

createInputFactory

protected javax.xml.stream.XMLInputFactory createInputFactory()
Creates the input factory.

Returns:
the XML input factory

getInputFactory

public javax.xml.stream.XMLInputFactory getInputFactory()
Gets the input factory.

Returns:
the input factory


Copyright © 2007-2008 Imola Informatica. All Rights Reserved.