org.apache.commons.jelly.tags.xml
Class TransformTag

java.lang.Object
  extended byorg.apache.commons.jelly.TagSupport
      extended byorg.apache.commons.jelly.tags.xml.ParseTagSupport
          extended byorg.apache.commons.jelly.tags.xml.ParseTag
              extended byorg.apache.commons.jelly.tags.xml.TransformTag
All Implemented Interfaces:
org.apache.commons.jelly.Tag

public class TransformTag
extends ParseTag

A tag which parses some XML, applies an xslt transform to it and defines a variable with the transformed Document. The XML can either be specified as its body or can be passed in via the xml property which can be a Reader, InputStream, URL or String URI. The XSL can be passed in via the xslt property which can be a Reader, InputStream, URL or String URI.

Version:
$Revision: 155420 $
Author:
Robert Leftwich

Nested Class Summary
private  class TransformTag.TagBodyInputSource
          A marker class used by the TagBodyXMLReader as a sanity check (i.e.
private  class TransformTag.TagBodyXMLReader
          A helper class that converts a transform tag body to an XMLReader to hide the details of where the input for the transform is obtained
 
Field Summary
private static java.lang.String LEXICAL_HANDLER_PROPERTY
          Propert name for lexical handler
private static org.apache.commons.logging.Log log
          The Log to which logging calls will be made.
private  javax.xml.transform.sax.SAXTransformerFactory tf
          The xsl transformer factory
private  javax.xml.transform.sax.TransformerHandler transformerHandler
          the transformer handler, doing the real work
private  java.lang.Object xslt
          The xslt to parse, either a String URI, a Reader or InputStream
 
Fields inherited from class org.apache.commons.jelly.tags.xml.ParseTag
 
Fields inherited from class org.apache.commons.jelly.tags.xml.ParseTagSupport
 
Fields inherited from class org.apache.commons.jelly.TagSupport
body, context, hasTrimmed, parent, shouldTrim
 
Constructor Summary
TransformTag()
          Constructor for TransformTag.
 
Method Summary
protected  javax.xml.transform.Result createSAXResult(org.apache.commons.jelly.XMLOutput output)
          Factory method to create a new SAXResult for the given XMLOutput so that the output of an XSLT transform will go directly into the XMLOutput that we are given.
protected  javax.xml.transform.URIResolver createURIResolver()
          Creates a new URI Resolver so that URIs inside the XSLT document can be resolved using the JellyContext
protected  org.xml.sax.XMLReader createXMLReader()
          Factory method to create a new XMLReader for this tag so that the input of the XSLT transform comes from either the xml var, the nested tag or the tag body.
private  void doNestedParamTag(org.apache.commons.jelly.XMLOutput output)
          Helper method to run any nested param tags
 void doTag(org.apache.commons.jelly.XMLOutput output)
          Process this tag instance
protected  org.xml.sax.InputSource getInputSourceFromObj(java.lang.Object sourceObj)
          Helper method to get an xml input source for the supplied object
protected  javax.xml.transform.sax.SAXSource getObjAsSAXSource(java.lang.Object saxSourceObj)
          Helper method to convert the specified object to a SAX source
protected  org.xml.sax.InputSource getXMLInputSource()
          Helper method to get the appropriate xml input source so that the input of the XSLT transform comes from either the xml var, the nested tag or the tag body.
 java.lang.Object getXslt()
          Gets the source of the XSL which is either a String URI, Reader or InputStream
 void setParameterValue(java.lang.String name, java.lang.Object value)
           
 void setXslt(java.lang.Object xslt)
          Sets the source of the XSL which is either a String URI, Reader or InputStream
 
Methods inherited from class org.apache.commons.jelly.tags.xml.ParseTag
createSAXReader, getValidate, getXml, getXmlDocument, setValidate, setXml
 
Methods inherited from class org.apache.commons.jelly.tags.xml.ParseTagSupport
getSAXReader, getText, getVar, parse, parseBody, parseText, setSAXReader, setText, setVar
 
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log
The Log to which logging calls will be made.


LEXICAL_HANDLER_PROPERTY

private static final java.lang.String LEXICAL_HANDLER_PROPERTY
Propert name for lexical handler

See Also:
Constant Field Values

xslt

private java.lang.Object xslt
The xslt to parse, either a String URI, a Reader or InputStream


tf

private javax.xml.transform.sax.SAXTransformerFactory tf
The xsl transformer factory


transformerHandler

private javax.xml.transform.sax.TransformerHandler transformerHandler
the transformer handler, doing the real work

Constructor Detail

TransformTag

public TransformTag()
Constructor for TransformTag.

Method Detail

doTag

public void doTag(org.apache.commons.jelly.XMLOutput output)
           throws org.apache.commons.jelly.MissingAttributeException,
                  org.apache.commons.jelly.JellyTagException
Process this tag instance

Specified by:
doTag in interface org.apache.commons.jelly.Tag
Overrides:
doTag in class ParseTag
Parameters:
output - The pipeline for xml events
Throws:
java.lang.Exception - - when required attributes are missing
org.apache.commons.jelly.MissingAttributeException
org.apache.commons.jelly.JellyTagException

getXslt

public java.lang.Object getXslt()
Gets the source of the XSL which is either a String URI, Reader or InputStream


setXslt

public void setXslt(java.lang.Object xslt)
Sets the source of the XSL which is either a String URI, Reader or InputStream

Parameters:
xslt - The source of the xslt

setParameterValue

public void setParameterValue(java.lang.String name,
                              java.lang.Object value)

createURIResolver

protected javax.xml.transform.URIResolver createURIResolver()
Creates a new URI Resolver so that URIs inside the XSLT document can be resolved using the JellyContext

Returns:
a URI Resolver for the JellyContext

createSAXResult

protected javax.xml.transform.Result createSAXResult(org.apache.commons.jelly.XMLOutput output)
Factory method to create a new SAXResult for the given XMLOutput so that the output of an XSLT transform will go directly into the XMLOutput that we are given.

Parameters:
output - The destination of the transform output
Returns:
A SAXResult for the transfrom output

createXMLReader

protected org.xml.sax.XMLReader createXMLReader()
                                         throws org.xml.sax.SAXException
Factory method to create a new XMLReader for this tag so that the input of the XSLT transform comes from either the xml var, the nested tag or the tag body.

Returns:
XMLReader for the transform input
Throws:
org.xml.sax.SAXException - If the value of the "org.xml.sax.driver" system property is null, or if the class cannot be loaded and instantiated.

getXMLInputSource

protected org.xml.sax.InputSource getXMLInputSource()
Helper method to get the appropriate xml input source so that the input of the XSLT transform comes from either the xml var, the nested tag or the tag body.

Returns:
InputSource for the transform input

getObjAsSAXSource

protected javax.xml.transform.sax.SAXSource getObjAsSAXSource(java.lang.Object saxSourceObj)
Helper method to convert the specified object to a SAX source

Returns:
SAXSource from the source object or null

getInputSourceFromObj

protected org.xml.sax.InputSource getInputSourceFromObj(java.lang.Object sourceObj)
Helper method to get an xml input source for the supplied object

Returns:
InputSource for the object or null

doNestedParamTag

private void doNestedParamTag(org.apache.commons.jelly.XMLOutput output)
                       throws org.apache.commons.jelly.JellyTagException
Helper method to run any nested param tags

Parameters:
output - The destination for any SAX output (not actually used)
Throws:
org.apache.commons.jelly.JellyTagException