org.milyn.templating.xslt
Class XslContentHandlerFactory

java.lang.Object
  extended by org.milyn.templating.xslt.XslContentHandlerFactory
All Implemented Interfaces:
ContentHandler, ContentHandlerFactory

@Resource(type="xsl")
public class XslContentHandlerFactory
extends Object
implements ContentHandlerFactory

XSL DOMElementVisitor Creator class.

Creates DOMElementVisitor instances for performing node/element level XSL templating (aka XSLT).

Template application can be done in a synchronized or unsynchronized fashion by setting the system property "org.milyn.templating.xslt.synchronized". According to the spec, this should not be necessary. However, Xalan 2.7.0 (for one) has a bug which results in unsynchronized template application causing invalid transforms.

Targeting "xsl" Templates

The following is the basic configuration specification for XSL resources:
 <resource-config selector="target-element">
     <resource>XSL Resource - Inline or URI</resource>

     <!-- (Optional) The action to be applied on the template content. Should the content
          generated by the template:
          1. replace ("replace") the target element, or
          2. be added to ("addto") the target element, or
          3. be inserted before ("insertbefore") the target element, or
          4. be inserted after ("insertafter") the target element.
          5. be bound to ("bindto") a BeanContext variable named by the "bindId" param.
          Default "replace".-->
     <param name="action">replace/addto/insertbefore/insertafter/bindto</param>

     <!-- (Optional) Is this XSL template resource a complete XSL template, or just a "Templatelet".
          Only relevant for inlined XSL resources.  URI based resource are always assumed to NOT be templatelets.
          Default "false" (for inline resources).-->
     <param name="is-xslt-templatelet">true/false</param>

     <!-- (Optional) Should the template be applied before (true) or
             after (false) Smooks visits the child elements of the target element.
             Default "false".-->
     <param name="applyTemplateBefore">true/false</param>

     <!-- (Optional) The name of the OutputStreamResource
             to which the result should be written. If set, the "action" param is ignored. -->
     <param name="outputStreamResource">xyzResource</param>

     <!-- (Optional) Template encoding.
          Default "UTF-8".-->
     <param name="encoding">encoding</param>

     <!-- (Optional) bindId when "action" is "bindto".
     <param name="bindId">xxxx</param>

     <!-- (Optional) Fail on XSL Transformer Warning.
          Default "true".-->
     <param name="failOnWarning">false</param> <!-- Default "true" -->

 </resource-config>
 

Example - URI based XSLT spec:

 <resource-config selector="target-element">
     <!-- 1. See URIResourceLocator -->
     <resource>/com/acme/order-transform.xsl</resource>
 </resource-config>
 

Example - Inlined XSLT spec:

 <resource-config selector="target-element">
     <!-- 1. Note how we have to specify the resource type when it's inlined. -->
     <!-- 2. Note how the inlined XSLT is wrapped as an XML Comment. CDATA Section wrapping also works. -->
     <!-- 3. Note if the inlined XSLT is a templatelet, is-xslt-templatelet=true must be specified. -->
     <resource type="xsl">
         <!--
            Inline XSLT....
         -->
     </resource>
     <param name="is-xslt-templatelet">true</param>
 </resource-config>
 

Templatelets

Templatelets are a convenient way of specifying an XSL Stylesheet. When using "Templatelets", you simply specify the body of an XSL template. This creator then wraps that body to make a complete XSL Stylesheet with a single template matched to the element targeted by the Smooks resource configuration in question. This feature only applies to inlined XSL resources and in this case, it's OFF by default. To use this feature, you must specify the "is-xslt-templatelet" parameter with a value of "true".

This feature will not work in all situations since you'll often need to specify a full stylesheet in order to specify namespaces etc. It's just here for convenience.

See the template used to wrap the templatelet.

JavaBean Support

Support for injection of JavaBean values populated by the Smooks JavaBean Cartridge is supported through the Xalan extension XalanJavabeanExtension.

Author:
tom.fennelly@gmail.com

Field Summary
static String IS_XSLT_TEMPLATELET
          Parameter name for templating feature.
static String ORG_MILYN_TEMPLATING_XSLT_SYNCHRONIZED
          Synchonized template application system property key.
 
Fields inherited from interface org.milyn.delivery.ContentHandlerFactory
PARAM_RESTYPE
 
Constructor Summary
XslContentHandlerFactory()
           
 
Method Summary
 ContentHandler create(SmooksResourceConfiguration resourceConfig)
          Create an XSL based ContentHandler instance ie from an XSL byte streamResult.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_XSLT_TEMPLATELET

public static final String IS_XSLT_TEMPLATELET
Parameter name for templating feature.

See Also:
Constant Field Values

ORG_MILYN_TEMPLATING_XSLT_SYNCHRONIZED

public static final String ORG_MILYN_TEMPLATING_XSLT_SYNCHRONIZED
Synchonized template application system property key.

See Also:
Constant Field Values
Constructor Detail

XslContentHandlerFactory

public XslContentHandlerFactory()
Method Detail

create

public ContentHandler create(SmooksResourceConfiguration resourceConfig)
                      throws SmooksConfigurationException,
                             InstantiationException
Create an XSL based ContentHandler instance ie from an XSL byte streamResult.

Specified by:
create in interface ContentHandlerFactory
Parameters:
resourceConfig - The SmooksResourceConfiguration for the XSL ContentHandler to be created.
Returns:
XSL ContentHandler instance.
Throws:
SmooksConfigurationException
InstantiationException
See Also:
JavaContentHandlerFactory


Copyright © 2014. All Rights Reserved.