org.mule.transformers.xml
Class XsltTransformer

java.lang.Object
  extended by org.mule.transformers.AbstractTransformer
      extended by org.mule.transformers.xml.AbstractXmlTransformer
          extended by org.mule.transformers.xml.XsltTransformer
All Implemented Interfaces:
Cloneable, Initialisable, UMOBaseTransformer, UMOTransformer

public class XsltTransformer
extends AbstractXmlTransformer

XsltTransformer performs an XSLT transform on a DOM (or other XML-ish) object.


Nested Class Summary
protected  class XsltTransformer.DefaultErrorListener
           
protected  class XsltTransformer.PooledXsltTransformerFactory
           
 
Nested classes/interfaces inherited from class org.mule.transformers.xml.AbstractXmlTransformer
AbstractXmlTransformer.ResultHolder
 
Field Summary
protected  GenericObjectPool transformerPool
           
 
Fields inherited from class org.mule.transformers.AbstractTransformer
DEFAULT_TRUNCATE_LENGTH, endpoint, logger, name, nextTransformer, returnClass, sourceTypes
 
Constructor Summary
XsltTransformer()
           
 
Method Summary
 Object clone()
           
 Object doTransform(Object src, String encoding)
          Transform, using XSLT, a XML String to another String.
protected  Object evaluateTransformParameter(String name, Object value)
           Returns the value to be set for the parameter.
 int getMaxActiveTransformers()
           
 int getMaxIdleTransformers()
           
protected  StreamSource getStreamSource()
          Returns the StreamSource corresponding to xslFile
 Map getTransformParameters()
          Gets the parameters to be used when applying the transformation
 String getXslFile()
           
 String getXslt()
           
 String getXslTransformerFactory()
          Returns the name of the currently configured javax.xml.transform.Transformer factory class used to create XSLT Transformers.
 void initialise()
          Template method were deriving classes can do any initialisation after the properties have been set on this transformer
 void setMaxActiveTransformers(int maxActiveTransformers)
          Sets the the current maximum number of idle transformer objects allowed in the pool
 void setMaxIdleTransformers(int maxIdleTransformers)
          Sets the the current maximum number of idle transformer objects allowed in the pool
 void setTransformParameters(Map transformParameters)
          Sets the parameters to be used when applying the transformation
 void setXslFile(String xslFile)
           
 void setXslt(String xslt)
           
 void setXslTransformerFactory(String xslTransformerFactory)
          Configures the javax.xml.transform.Transformer factory class
 
Methods inherited from class org.mule.transformers.xml.AbstractXmlTransformer
convertToBytes, convertToText, convertToText, getOutputEncoding, getResultHolder, getXmlSource, setOutputEncoding
 
Methods inherited from class org.mule.transformers.AbstractTransformer
checkReturnClass, generateTransformerName, getEndpoint, getFinalReturnClass, getName, getNextTransformer, getReturnClass, isAcceptNull, isIgnoreBadInput, isSourceTypeSupported, isSourceTypeSupported, nextTransform, registerSourceType, setEndpoint, setIgnoreBadInput, setName, setNextTransformer, setReturnClass, toString, transform, unregisterSourceType
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

transformerPool

protected final GenericObjectPool transformerPool
Constructor Detail

XsltTransformer

public XsltTransformer()
Method Detail

initialise

public void initialise()
                throws InitialisationException
Description copied from class: AbstractTransformer
Template method were deriving classes can do any initialisation after the properties have been set on this transformer

Specified by:
initialise in interface Initialisable
Overrides:
initialise in class AbstractTransformer
Throws:
InitialisationException - if a fatal error occurs causing the Mule instance to shutdown
RecoverableException - if an error occurs that can be recovered from
See Also:
Initialisable.initialise()

doTransform

public Object doTransform(Object src,
                          String encoding)
                   throws TransformerException
Transform, using XSLT, a XML String to another String.

Specified by:
doTransform in class AbstractTransformer
Parameters:
src - The source XML (String, byte[], DOM, etc.)
Returns:
The result String (or DOM)
Throws:
TransformerException

getXslTransformerFactory

public String getXslTransformerFactory()
Returns the name of the currently configured javax.xml.transform.Transformer factory class used to create XSLT Transformers.

Returns:
a TransformerFactory class name or null if none has been configured

setXslTransformerFactory

public void setXslTransformerFactory(String xslTransformerFactory)
Configures the javax.xml.transform.Transformer factory class

Parameters:
xslTransformerFactory - the name of the TransformerFactory class to use

getXslFile

public String getXslFile()
Returns:
Returns the xslFile.

setXslFile

public void setXslFile(String xslFile)
Parameters:
xslFile - The xslFile to set.

getXslt

public String getXslt()

setXslt

public void setXslt(String xslt)

getStreamSource

protected StreamSource getStreamSource()
                                throws InitialisationException
Returns the StreamSource corresponding to xslFile

Returns:
The StreamSource
Throws:
InitialisationException

clone

public Object clone()
             throws CloneNotSupportedException
Specified by:
clone in interface UMOBaseTransformer
Overrides:
clone in class AbstractTransformer
Throws:
CloneNotSupportedException

getMaxActiveTransformers

public int getMaxActiveTransformers()
Returns:
The current maximum number of allowable idle transformer objects in the pool

setMaxActiveTransformers

public void setMaxActiveTransformers(int maxActiveTransformers)
Sets the the current maximum number of idle transformer objects allowed in the pool

Parameters:
maxActiveTransformers - New maximum size to set

getMaxIdleTransformers

public int getMaxIdleTransformers()
Returns:
The current maximum number of allowable idle transformer objects in the pool

setMaxIdleTransformers

public void setMaxIdleTransformers(int maxIdleTransformers)
Sets the the current maximum number of idle transformer objects allowed in the pool

Parameters:
maxIdleTransformers - New maximum size to set

getTransformParameters

public Map getTransformParameters()
Gets the parameters to be used when applying the transformation

Returns:
a map of the parameter names and associated values
See Also:
Transformer.setParameter(java.lang.String, java.lang.Object)

setTransformParameters

public void setTransformParameters(Map transformParameters)
Sets the parameters to be used when applying the transformation

Parameters:
transformParameters - a map of the parameter names and associated values
See Also:
Transformer.setParameter(java.lang.String, java.lang.Object)

evaluateTransformParameter

protected Object evaluateTransformParameter(String name,
                                            Object value)
                                     throws TransformerException

Returns the value to be set for the parameter. This method is called for each parameter before it is set on the transformer. The purpose of this method is to allow dynamic parameters related to the event (usually message properties) to be used. Any attribute of the current UMOEventContext can be accessed using JXPath.

For example: If the current event's message has a property named "myproperty", to pass this in you would set the transform parameter's value to be "#getProperty(message,'myproperty')".

Example Configuration:

  <transformer name="MyXsltTransformer" className="org.mule.transformers.xml.XsltTransformer"&gt
      <properties>
          <property name="xslFile" value="myXslFile.xsl"/&gt
          <map name="transformParameters"&gt
              <property name="myParameter" value="#getProperty(message,'myproperty')"/&gt
          </map&gt
      </properties&gt
  </transformer&gt
 

Only parameter values that begin with # are evalued in this maner. Values that do not start with # are returned as is. Values that start with ## are returned as is starting from the second character. For example "##myparameter" would be passed into the transformer as "#myparameter"

This method may be overloaded by a sub class to provide a different dynamic parameter implementation.

Parameters:
name - the name of the parameter
value - the value of the paramter
Returns:
the object to be set as the parameter value
Throws:
TransformerException


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.