org.ow2.petals.component.framework.util
Class SourceUtil

java.lang.Object
  extended by org.ow2.petals.component.framework.util.SourceUtil

public class SourceUtil
extends java.lang.Object

Sample class used to manage the mapping between javax.xml.transform.Source from String. the mapping is a quicly "string" -> "string" conversion.

Author:
alouis - eBM WebSourcing, fgardes - eBM WebSourcing, noddoux - eBM WebSourcing

Constructor Summary
SourceUtil()
          Creates a new instance of SourceUtil
 
Method Summary
static org.w3c.dom.Document createDocument(javax.xml.transform.Source source)
          Create a Document from a Source.
static org.w3c.dom.Document createDocument(javax.xml.transform.Source source, boolean forkSource)
          Create a Document from a Source.
static javax.xml.transform.dom.DOMSource createDOMSource(org.w3c.dom.Document document)
          Create a DOM Source from the DOM document.
static org.w3c.dom.Document createSoapFaultDocument(java.lang.Throwable e, javax.xml.namespace.QName errorCode)
           Creates an SOAP fault, as a DOM document, according to provided exception and code:
<s:Fault xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <faultcode>{org.objectweb.petals}ERROR</faultcode>
   <faultstring>mesage</faultstring>
   <faultactor>component</faultactor>
   <detail>
      ...
   </detail>
<s:Fault>
static javax.xml.transform.Source createSource(java.lang.String message)
          Create a Source from the String.
static javax.xml.transform.Source createSource(java.lang.String message, java.lang.String charFormat)
          Create a Source from the String with a specified encoding format.
static javax.xml.transform.stream.StreamSource createStreamSource(org.w3c.dom.Document document)
          Create a Stream Source from the DOM document.
static java.lang.String createString(javax.xml.transform.Source source)
          Create a String from a Source.
-If the Source is a StreamSource, the source would be still available.
static java.lang.String createString(javax.xml.transform.Source source, boolean forkSource)
          Create a String from a Source.
-If the Source is a StreamSource and forkSource is set to true, the source would be still available.
static boolean isDOM3(org.w3c.dom.Document document)
          Test if the document is a DOM3 document
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceUtil

public SourceUtil()
Creates a new instance of SourceUtil

Method Detail

createDocument

public static final org.w3c.dom.Document createDocument(javax.xml.transform.Source source)
                                                 throws org.ow2.petals.component.framework.api.exception.PEtALSCDKException
Create a Document from a Source.
-If the Source is a StreamSource, the source would be still available.
-If the Source is a DomSource and contains a Document, the returned document is a clone of this document.

Parameters:
source - the Source
Returns:
the DOM document built from the Source
Throws:
org.ow2.petals.component.framework.api.exception.PEtALSCDKException

createDocument

public static final org.w3c.dom.Document createDocument(javax.xml.transform.Source source,
                                                        boolean forkSource)
                                                 throws org.ow2.petals.component.framework.api.exception.PEtALSCDKException
Create a Document from a Source.
-If the Source is a StreamSource and forkSource is set to true, the source would be still available. Otherwise the source is no more available.
If the Source is a DomSource and contains a Document and forkSource is set to true, the returned document is a clone of this document. Otherwise the original Document is returned.

Parameters:
source - the Source
forkSource - true to fork the content of the source if necessary
Returns:
a DOM document
Throws:
org.ow2.petals.component.framework.api.exception.PEtALSCDKException

createDOMSource

public static final javax.xml.transform.dom.DOMSource createDOMSource(org.w3c.dom.Document document)
Create a DOM Source from the DOM document.

Parameters:
document - A DOM document
Returns:
the DOM source built from the DOM document

createSoapFaultDocument

public static final org.w3c.dom.Document createSoapFaultDocument(java.lang.Throwable e,
                                                                 javax.xml.namespace.QName errorCode)

Creates an SOAP fault, as a DOM document, according to provided exception and code:
<s:Fault xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <faultcode>{org.objectweb.petals}ERROR</faultcode>
   <faultstring>mesage</faultstring>
   <faultactor>component</faultactor>
   <detail>
      ...
   </detail>
<s:Fault>

If the provided exception is an instance of DocumentException:

If the provided exception is an instance of FaultException:

otherwise:

Parameters:
e - An exception used to provide faultstring and detail
errorCode - The QName of the fault code. It is not used if the exception is an instance of FaultException or DocumentException.
Returns:
A Document containing the Soap Fault

createSource

public static final javax.xml.transform.Source createSource(java.lang.String message)
                                                     throws org.ow2.petals.component.framework.api.exception.PEtALSCDKException
Create a Source from the String. The message must be a valid XML String. If an encoding is specified in the XML String header it is used to create the XML bytes stream, otherwise the default JVM encoding is used.

Parameters:
message - a valid XML String
Returns:
the Source built from the XML String
Throws:
org.ow2.petals.component.framework.api.exception.PEtALSCDKException - if an error occurs during Source creation

createSource

public static final javax.xml.transform.Source createSource(java.lang.String message,
                                                            java.lang.String charFormat)
                                                     throws org.ow2.petals.component.framework.api.exception.PEtALSCDKException
Create a Source from the String with a specified encoding format. The message must be a valid XML String. The encoding must match the XML declaration in the message.

Parameters:
message - a valid XML String
charFormat - the encoding format, must be non null
Returns:
the Source built from the XML String
Throws:
org.ow2.petals.component.framework.api.exception.PEtALSCDKException - if an error occurs during Source creation

createStreamSource

public static final javax.xml.transform.stream.StreamSource createStreamSource(org.w3c.dom.Document document)
                                                                        throws org.ow2.petals.component.framework.api.exception.PEtALSCDKException
Create a Stream Source from the DOM document.

Parameters:
document - A DOM document
Returns:
the Stream source built from the DOM document
Throws:
org.ow2.petals.component.framework.api.exception.PEtALSCDKException

createString

public static final java.lang.String createString(javax.xml.transform.Source source)
                                           throws org.ow2.petals.component.framework.api.exception.PEtALSCDKException
Create a String from a Source.
-If the Source is a StreamSource, the source would be still available.

Parameters:
source - the Source
Returns:
the String built from the Source
Throws:
org.ow2.petals.component.framework.api.exception.PEtALSCDKException

createString

public static final java.lang.String createString(javax.xml.transform.Source source,
                                                  boolean forkSource)
                                           throws org.ow2.petals.component.framework.api.exception.PEtALSCDKException
Create a String from a Source.
-If the Source is a StreamSource and forkSource is set to true, the source would be still available. Otherwise the source is no more available.

Parameters:
source - the Source
Returns:
the String built from the Source
Throws:
org.ow2.petals.component.framework.api.exception.PEtALSCDKException

isDOM3

public static final boolean isDOM3(org.w3c.dom.Document document)
Test if the document is a DOM3 document

Parameters:
document - the document to test
Returns:
true if the document is DOM3, false else


Copyright © 2005-2011 Petals Link (EBM Websourcing). All Rights Reserved.