Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.views.xslt
Class XSLTResult

    java.lang.Object
      org.apache.struts2.views.xslt.XSLTResult

All Implemented Interfaces:
  Result, java.io.Serializable

    public class XSLTResult

extends java.lang.Object
implements Result

XSLTResult uses XSLT to transform an action object to XML. The recent version has been specifically modified to deal with Xalan flaws. When using Xalan you may notice that even though you have a very minimal stylesheet like this one

     <xsl:template match="/result">
       <result/>
     </xsl:template>

Xalan would still iterate through every property of your action and all its descendants.

If you had double-linked objects, Xalan would work forever analysing an infinite object tree. Even if your stylesheet was not constructed to process them all. It's because the current Xalan eagerly and extensively converts everything to its internal DTM model before further processing.

That's why there's a loop eliminator added that works by indexing every object-property combination during processing. If it notices that some object's property was already walked through, it doesn't go any deeper. Say you have two objects, x and y, with the following properties set (pseudocode):

     x.y = y;
     and
     y.x = x;
     action.x=x;

Due to that modification, the resulting XML document based on x would be:

     <result>
       <x>
         <y/>
       </x>
     </result>

Without it there would be endless x/y/x/y/x/y/... elements.

The XSLTResult code tries also to deal with the fact that DTM model is built in a manner that children are processed before siblings. The result is that if there is object x that is both set in action's x property, and very deeply under action's a property then it would only appear under a, not under x. That's not what we expect, and that's why XSLTResult allows objects to repeat in various places to some extent.

Sometimes the object mesh is still very dense and you may notice that even though you have a relatively simple stylesheet, execution takes a tremendous amount of time. To help you to deal with that obstacle of Xalan, you may attach regexp filters to elements paths (xpath).

Note: In your .xsl file the root match must be named `result`.
This example will output the username by using `getUsername` on your action class:

     <xsl:template match="result">
       <html>
       <body>
       Hello <xsl:value-of select="username"/> how are you?
       </body>
       </html>
     </xsl:template>

In the following example the XSLT result would only walk through action's properties without their childs. It would also skip every property that has "hugeCollection" in their name. Element's path is first compared to excludingPattern - if it matches it's no longer processed. Then it is compared to matchingPattern and processed only if there's a match.

     <result name="success" type="xslt">
       <param name="location">foo.xslt</param>
       <param name="matchingPattern">^/result/[^/*]$</param>
       <param name="excludingPattern">.*(hugeCollection).*</param>
     </result>

In the following example the XSLT result would use the action's user property instead of the action as it's base document and walk through it's properties. The exposedValue uses an ognl expression to derive it's value.

     <result name="success" type="xslt">
       <param name="location">foo.xslt</param>
       <param name="exposedValue">user$</param>
     </result>

* This result type takes the following parameters:

- location (default) - the location to go to after execution.
- parse - true by default. If set to false, the location param will not be parsed for Ognl expressions.

`struts.properties` related configuration:

- struts.xslt.nocache - Defaults to false. If set to true, disables stylesheet caching. Good for development, bad for production.

Example:

     <result name="success" type="xslt">foo.xslt</result>

See Also:
  Serialized Form

Field Summary
`static java.lang.String` | `DEFAULT_PARAM` 'stylesheetLocation' parameter.
`protected boolean` | `noCache` Determines whether or not the result should allow caching.

Constructor Summary
`XSLTResult()`
`XSLTResult(java.lang.String stylesheetLocation)`

Method Summary
`void` | `execute(ActionInvocation invocation)`
`protected AdapterFactory` | `getAdapterFactory()`
`protected javax.xml.transform.Source` | `getDOMSourceForStack(java.lang.Object value)`
`java.lang.String` | `getExcludingPattern()` Deprecated. Since 2.1.1
`java.lang.String` | `getExposedValue()`
`java.lang.String` | `getMatchingPattern()` Deprecated. Since 2.1.1
`java.lang.String` | `getStylesheetLocation()`
`protected javax.xml.transform.Templates` | `getTemplates(java.lang.String path)`
`protected javax.xml.transform.URIResolver` | `getURIResolver()` Get the URI Resolver to be called by the processor when it encounters an xsl:include, xsl:import, or document() function.
`protected void` | `setAdapterFactory(AdapterFactory adapterFactory)`
`void` | `setExcludingPattern(java.lang.String excludingPattern)` Deprecated. Since 2.1.1
`void` | `setExposedValue(java.lang.String exposedValue)`
`void` | `setLocation(java.lang.String location)` Deprecated. Use #setStylesheetLocation(String)
`void` | `setMatchingPattern(java.lang.String matchingPattern)` Deprecated. Since 2.1.1
`void` | `setNoCache(java.lang.String val)`
`void` | `setParse(boolean parse)` If true, parse the stylesheet location for OGNL expressions.
`void` | `setStylesheetLocation(java.lang.String location)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_PARAM

    public static final java.lang.String DEFAULT_PARAM

  'stylesheetLocation' parameter. Points to the xsl.

  See Also:
    Constant Field Values

### noCache

    protected boolean noCache

  Determines whether or not the result should allow caching.

Constructor Detail

### XSLTResult

    public XSLTResult()

### XSLTResult

    public XSLTResult(java.lang.String stylesheetLocation)

Method Detail

### setNoCache

    public void setNoCache(java.lang.String val)

### setLocation

    public void setLocation(java.lang.String location)

  Deprecated. Use #setStylesheetLocation(String)

### setStylesheetLocation

    public void setStylesheetLocation(java.lang.String location)

### getStylesheetLocation

    public java.lang.String getStylesheetLocation()

### getExposedValue

    public java.lang.String getExposedValue()

### setExposedValue

    public void setExposedValue(java.lang.String exposedValue)

### getMatchingPattern

    public java.lang.String getMatchingPattern()

  Deprecated. Since 2.1.1

### setMatchingPattern

    public void setMatchingPattern(java.lang.String matchingPattern)

  Deprecated. Since 2.1.1

### getExcludingPattern

    public java.lang.String getExcludingPattern()

  Deprecated. Since 2.1.1

### setExcludingPattern

    public void setExcludingPattern(java.lang.String excludingPattern)

  Deprecated. Since 2.1.1

### setParse

    public void setParse(boolean parse)

  If true, parse the stylesheet location for OGNL expressions.

  Parameters:
    `parse` -

### execute

    public void execute(ActionInvocation invocation)
                 throws java.lang.Exception

  Specified by:
    `execute` in interface `Result`
  Throws:
    `java.lang.Exception`

### getAdapterFactory

    protected AdapterFactory getAdapterFactory()

### setAdapterFactory

    protected void setAdapterFactory(AdapterFactory adapterFactory)

### getURIResolver

    protected javax.xml.transform.URIResolver getURIResolver()

  Get the URI Resolver to be called by the processor when it encounters an xsl:include, xsl:import, or document() function. The default is an instance of ServletURIResolver, which operates relative to the servlet context.

### getTemplates

    protected javax.xml.transform.Templates getTemplates(java.lang.String path)
                                                  throws javax.xml.transform.TransformerException,
                                                         java.io.IOException

  Throws:
    `javax.xml.transform.TransformerException`
    `java.io.IOException`

### getDOMSourceForStack

    protected javax.xml.transform.Source getDOMSourceForStack(java.lang.Object value)
                                                       throws java.lang.IllegalAccessException,
                                                              java.lang.InstantiationException

  Throws:
    `java.lang.IllegalAccessException`
    `java.lang.InstantiationException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.