it.imolinfo.jbi4corba.jbi.processor.transform
Class SourceTransformer

java.lang.Object
  extended by it.imolinfo.jbi4corba.jbi.processor.transform.SourceTransformer

public class SourceTransformer
extends Object

Taken from servicemix-core SourceTransformer and partially from StAXSoureTransformer class.

Author:
Marco Piraccini

Constructor Summary
SourceTransformer()
          Instantiates a new source transformer.
SourceTransformer(DocumentBuilderFactory documentBuilderFactory)
          Instantiates a new source transformer.
 
Method Summary
 String contentToString(javax.jbi.messaging.NormalizedMessage message)
          Converts the content of the given message to a String.
 Document createDocument()
          Creates the document.
 DocumentBuilder createDocumentBuilder()
          Creates the document builder.
 DocumentBuilderFactory createDocumentBuilderFactory()
          Creates the document builder factory.
protected  javax.xml.stream.XMLInputFactory createInputFactory()
          Creates the input factory.
 Transformer createTransfomer()
          Creates the transfomer.
 TransformerFactory createTransformerFactory()
          Creates the transformer factory.
 DocumentBuilderFactory getDocumentBuilderFactory()
          Gets the document builder factory.
 javax.xml.stream.XMLInputFactory getInputFactory()
          Gets the input factory.
 TransformerFactory getTransformerFactory()
          Gets the transformer factory.
 void setDocumentBuilderFactory(DocumentBuilderFactory documentBuilderFactory)
          Sets the document builder factory.
 void setTransformerFactory(TransformerFactory transformerFactory)
          Sets the transformer factory.
 Document toDOMDocument(Node node)
          Create a DOM document from the given Node.
 Document toDOMDocument(javax.jbi.messaging.NormalizedMessage message)
          Create a DOM document from the given normalized message.
 Document toDOMDocument(Source source)
          Create a DOM document from the given source.
 Element toDOMElement(Node node)
          Create a DOM element from the DOM node.
 Element toDOMElement(javax.jbi.messaging.NormalizedMessage message)
          Create a DOM element from the normalized message.
 Element toDOMElement(Source source)
          Create a DOM element from the given source.
 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.
 Node toDOMNode(Source source)
          Converts the given TRaX Source into a W3C DOM node.
 Node toDOMNodeFromSAX(SAXSource source)
          To DOM node from SAX.
 Source toDOMSource(javax.jbi.messaging.NormalizedMessage message)
          To DOM source.
 DOMSource toDOMSource(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).
 DOMSource toDOMSourceFromSAX(SAXSource source)
          To DOM source from SAX.
 DOMSource toDOMSourceFromStream(StreamSource source)
          To DOM source from stream.
 Reader toReaderFromSource(Source src)
          To reader from source.
 void toResult(Source source, Result result)
          Converts the given input Source into the required result.
 SAXSource toSAXSource(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).
 SAXSource toSAXSourceFromDOM(DOMSource source)
          To SAX source from DOM.
 SAXSource toSAXSourceFromStream(StreamSource source)
          To SAX source from stream.
 StreamSource toStreamSource(Source source)
          To stream source.
 StreamSource toStreamSourceFromDOM(DOMSource source)
          To stream source from DOM.
 StreamSource toStreamSourceFromSAX(SAXSource source)
          To stream source from SAX.
 String toString(Node node)
          Converts the given input Node into text.
 String toString(Source source)
          Converts the given input Source into text.
 javax.xml.stream.XMLStreamReader toXMLStreamReader(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(DocumentBuilderFactory documentBuilderFactory)
Instantiates a new source transformer.

Parameters:
documentBuilderFactory - the DocumentBuilderFactory
Method Detail

toResult

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

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

toString

public String toString(Source source)
                throws TransformerException
Converts the given input Source into text.

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

toString

public String toString(Node node)
                throws TransformerException
Converts the given input Node into text.

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

contentToString

public String contentToString(javax.jbi.messaging.NormalizedMessage message)
                       throws javax.jbi.messaging.MessagingException,
                              TransformerException,
                              ParserConfigurationException,
                              IOException,
                              SAXException
Converts the content of the given message to a String.

Parameters:
message - The message
Returns:
The message content as String
Throws:
SAXException - If some problem occurs
IOException - If some problem occurs
ParserConfigurationException - If some problem occurs
javax.jbi.messaging.MessagingException - If some problem occurs
TransformerException - If some problem occurs

toDOMSource

public DOMSource toDOMSource(Source source)
                      throws ParserConfigurationException,
                             IOException,
                             SAXException,
                             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:
ParserConfigurationException - If some problem occurs
IOException - If some problem occurs
SAXException - If some problem occurs
TransformerException - If some problem occurs

toDOMSource

public Source toDOMSource(javax.jbi.messaging.NormalizedMessage message)
                   throws javax.jbi.messaging.MessagingException,
                          TransformerException,
                          ParserConfigurationException,
                          IOException,
                          SAXException
To DOM source.

Parameters:
message - The NormalizedMessage
Returns:
the source
Throws:
javax.jbi.messaging.MessagingException - If some problem occurs
TransformerException - If some problem occurs
ParserConfigurationException - If some problem occurs
IOException - If some problem occurs
SAXException - If some problem occurs

toSAXSource

public SAXSource toSAXSource(Source source)
                      throws IOException,
                             SAXException,
                             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:
IOException - If some problem occurs
SAXException - If some problem occurs
TransformerException - If some problem occurs

toStreamSource

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

Parameters:
source - The Source
Returns:
the stream source
Throws:
TransformerException - If some problem occurs

toStreamSourceFromSAX

public StreamSource toStreamSourceFromSAX(SAXSource source)
                                   throws TransformerException
To stream source from SAX.

Parameters:
source - The Source
Returns:
the stream source
Throws:
TransformerException - If some problem occurs

toStreamSourceFromDOM

public StreamSource toStreamSourceFromDOM(DOMSource source)
                                   throws TransformerException
To stream source from DOM.

Parameters:
source - The DOMSource
Returns:
the stream source
Throws:
TransformerException - If some problem occurs

toSAXSourceFromStream

public SAXSource toSAXSourceFromStream(StreamSource source)
To SAX source from stream.

Parameters:
source - The Source
Returns:
the SAX source

toReaderFromSource

public Reader toReaderFromSource(Source src)
                          throws TransformerException
To reader from source.

Parameters:
src - The source
Returns:
the reader
Throws:
TransformerException - If some problem occurs

toDOMSourceFromStream

public DOMSource toDOMSourceFromStream(StreamSource source)
                                throws ParserConfigurationException,
                                       IOException,
                                       SAXException
To DOM source from stream.

Parameters:
source - The stream source
Returns:
the DOM source
Throws:
ParserConfigurationException - If some problem occurs
IOException - If some problem occurs
SAXException - If some problem occurs

toSAXSourceFromDOM

public SAXSource toSAXSourceFromDOM(DOMSource source)
                             throws TransformerException
To SAX source from DOM.

Parameters:
source - The DOMSource
Returns:
the SAX source
Throws:
TransformerException - If some problem occurs

toDOMSourceFromSAX

public DOMSource toDOMSourceFromSAX(SAXSource source)
                             throws IOException,
                                    SAXException,
                                    ParserConfigurationException,
                                    TransformerException
To DOM source from SAX.

Parameters:
source - The source
Returns:
the DOM source
Throws:
IOException - If some problem occurs
SAXException - If some problem occurs
ParserConfigurationException - If some problem occurs
TransformerException - If some problem occurs

toDOMNodeFromSAX

public Node toDOMNodeFromSAX(SAXSource source)
                      throws ParserConfigurationException,
                             IOException,
                             SAXException,
                             TransformerException
To DOM node from SAX.

Parameters:
source - The Source
Returns:
the node
Throws:
ParserConfigurationException - If some problem occurs
IOException - If some problem occurs
SAXException - If some problem occurs
TransformerException - If some problem occurs

toDOMNode

public Node toDOMNode(Source source)
               throws TransformerException,
                      ParserConfigurationException,
                      IOException,
                      SAXException
Converts the given TRaX Source into a W3C DOM node.

Parameters:
source - The source
Returns:
The Node
Throws:
SAXException - If some problem occurs
IOException - If some problem occurs
ParserConfigurationException - If some problem occurs
TransformerException - If some problem occurs

toDOMNode

public Node toDOMNode(javax.jbi.messaging.NormalizedMessage message)
               throws javax.jbi.messaging.MessagingException,
                      TransformerException,
                      ParserConfigurationException,
                      IOException,
                      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:
SAXException - If some problem occurs
IOException - If some problem occurs
ParserConfigurationException - If some problem occurs
javax.jbi.messaging.MessagingException - If some problem occurs
TransformerException - If some problem occurs

toDOMElement

public Element toDOMElement(javax.jbi.messaging.NormalizedMessage message)
                     throws javax.jbi.messaging.MessagingException,
                            TransformerException,
                            ParserConfigurationException,
                            IOException,
                            SAXException
Create a DOM element from the normalized message.

Parameters:
message -
Returns:
The DOM element
Throws:
javax.jbi.messaging.MessagingException - If some problem occurs
TransformerException - If some problem occurs
ParserConfigurationException - If some problem occurs
IOException
SAXException

toDOMElement

public Element toDOMElement(Source source)
                     throws TransformerException,
                            ParserConfigurationException,
                            IOException,
                            SAXException
Create a DOM element from the given source.

Parameters:
source - The Source
Returns:
The DOM element
Throws:
TransformerException - If some problem occurs
ParserConfigurationException - If some problem occurs
IOException - If some problem occurs
SAXException - If some problem occurs

toDOMElement

public Element toDOMElement(Node node)
                     throws 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:
TransformerException - If some problem occurs

toDOMDocument

public Document toDOMDocument(javax.jbi.messaging.NormalizedMessage message)
                       throws javax.jbi.messaging.MessagingException,
                              TransformerException,
                              ParserConfigurationException,
                              IOException,
                              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
TransformerException - If some problem occurs
ParserConfigurationException - If some problem occurs
IOException - If some problem occurs
SAXException - If some problem occurs

toDOMDocument

public Document toDOMDocument(Source source)
                       throws TransformerException,
                              ParserConfigurationException,
                              IOException,
                              SAXException
Create a DOM document from the given source.

Parameters:
source - The Source
Returns:
The DOM document
Throws:
TransformerException - If some problem occurs
ParserConfigurationException - If some problem occurs
IOException - If some problem occurs
SAXException - If some problem occurs

toDOMDocument

public Document toDOMDocument(Node node)
                       throws ParserConfigurationException,
                              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:
ParserConfigurationException - If some problem occurs
TransformerException - If some problem occurs

getDocumentBuilderFactory

public DocumentBuilderFactory getDocumentBuilderFactory()
Gets the document builder factory.

Returns:
the document builder factory

setDocumentBuilderFactory

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

Parameters:
documentBuilderFactory - the new document builder factory

createDocumentBuilderFactory

public DocumentBuilderFactory createDocumentBuilderFactory()
Creates the document builder factory.

Returns:
the document builder factory

createDocumentBuilder

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

Returns:
the document builder
Throws:
ParserConfigurationException - If some problem occurs

createDocument

public Document createDocument()
                        throws ParserConfigurationException
Creates the document.

Returns:
the document
Throws:
ParserConfigurationException - If some problem occurs

getTransformerFactory

public TransformerFactory getTransformerFactory()
Gets the transformer factory.

Returns:
the transformer factory

setTransformerFactory

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

Parameters:
transformerFactory - the new transformer factory

createTransfomer

public Transformer createTransfomer()
                             throws TransformerConfigurationException
Creates the transfomer.

Returns:
the transformer
Throws:
TransformerConfigurationException - If some problem occurs

createTransformerFactory

public TransformerFactory createTransformerFactory()
Creates the transformer factory.

Returns:
the transformer factory

toXMLStreamReader

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

Parameters:
source - The Source
Returns:
the XML stream reader
Throws:
javax.xml.stream.XMLStreamException - If some problem occurs
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 © 2005-2010 Imola Informatica. All Rights Reserved.