类 XsltView

java.lang.Object
cn.taketoday.context.support.ApplicationObjectSupport
所有已实现的接口:
cn.taketoday.beans.factory.Aware, cn.taketoday.beans.factory.BeanNameAware, cn.taketoday.beans.factory.InitializingBean, cn.taketoday.context.ApplicationContextAware, View

public class XsltView extends AbstractUrlBasedView
XSLT-driven View that allows for response context to be rendered as the result of an XSLT transformation.

The XSLT Source object is supplied as a parameter in the model and then detected during response rendering. Users can either specify a specific entry in the model via the sourceKey property or have Framework locate the Source object. This class also provides basic conversion of objects into Source implementations. See here for more details.

All model parameters are passed to the XSLT Transformer as parameters. In addition the user can configure output properties to be passed to the Transformer.

从以下版本开始:
4.0
作者:
Rob Harrop, Juergen Hoeller
  • 字段详细资料

    • transformerFactoryClass

      @Nullable private Class<? extends TransformerFactory> transformerFactoryClass
    • sourceKey

      @Nullable private String sourceKey
    • uriResolver

      @Nullable private URIResolver uriResolver
    • errorListener

      private ErrorListener errorListener
    • indent

      private boolean indent
    • outputProperties

      @Nullable private Properties outputProperties
    • cacheTemplates

      private boolean cacheTemplates
    • transformerFactory

      @Nullable private TransformerFactory transformerFactory
    • cachedTemplates

      @Nullable private Templates cachedTemplates
  • 构造器详细资料

    • XsltView

      public XsltView()
  • 方法详细资料

    • setTransformerFactoryClass

      public void setTransformerFactoryClass(Class<? extends TransformerFactory> transformerFactoryClass)
      Specify the XSLT TransformerFactory class to use.

      The default constructor of the specified class will be called to build the TransformerFactory for this view.

    • setSourceKey

      public void setSourceKey(String sourceKey)
      Set the name of the model attribute that represents the XSLT Source. If not specified, the model map will be searched for a matching value type.

      The following source types are supported out of the box: Source, Document, Node, Reader, InputStream and Resource.

      另请参阅:
    • setUriResolver

      public void setUriResolver(URIResolver uriResolver)
      Set the URIResolver used in the transform.

      The URIResolver handles calls to the XSLT document() function.

    • setErrorListener

      public void setErrorListener(@Nullable ErrorListener errorListener)
      Set an implementation of the ErrorListener interface for custom handling of transformation errors and warnings.

      If not set, a default SimpleTransformErrorListener is used that simply logs warnings using the logger instance of the view class, and rethrows errors to discontinue the XML transformation.

      另请参阅:
    • setIndent

      public void setIndent(boolean indent)
      Set whether the XSLT transformer may add additional whitespace when outputting the result tree.

      Default is true (on); set this to false (off) to not specify an "indent" key, leaving the choice up to the stylesheet.

      另请参阅:
    • setOutputProperties

      public void setOutputProperties(Properties outputProperties)
      Set arbitrary transformer output properties to be applied to the stylesheet.

      Any values specified here will override defaults that this view sets programmatically.

      另请参阅:
    • setCacheTemplates

      public void setCacheTemplates(boolean cacheTemplates)
      Turn on/off the caching of the XSLT Templates instance.

      The default value is "true". Only set this to "false" in development, where caching does not seriously impact performance.

    • initApplicationContext

      protected void initApplicationContext() throws cn.taketoday.beans.BeansException
      Initialize this XsltView's TransformerFactory.
      覆盖:
      initApplicationContext 在类中 cn.taketoday.context.support.ApplicationObjectSupport
      抛出:
      cn.taketoday.beans.BeansException
    • newTransformerFactory

      protected TransformerFactory newTransformerFactory(@Nullable Class<? extends TransformerFactory> transformerFactoryClass)
      Instantiate a new TransformerFactory for this view.

      The default implementation simply calls TransformerFactory.newInstance(). If a "transformerFactoryClass" has been specified explicitly, the default constructor of the specified class will be called instead.

      Can be overridden in subclasses.

      参数:
      transformerFactoryClass - the specified factory class (if any)
      返回:
      the new TransactionFactory instance
      另请参阅:
    • getTransformerFactory

      protected final TransformerFactory getTransformerFactory()
      Return the TransformerFactory that this XsltView uses.
      返回:
      the TransformerFactory (never null)
    • renderMergedOutputModel

      protected void renderMergedOutputModel(Map<String,Object> model, RequestContext request) throws Exception
      从类复制的说明: AbstractView
      Subclasses must implement this method to actually render the view.

      The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.

      指定者:
      renderMergedOutputModel 在类中 AbstractView
      参数:
      model - combined output Map (never null), with dynamic values taking precedence over static attributes
      request - current HTTP request context
      抛出:
      Exception - if rendering failed
    • createResult

      protected Result createResult(RequestContext response) throws Exception
      Create the XSLT Result used to render the result of the transformation.

      The default implementation creates a StreamResult wrapping the supplied RequestContext's OutputStream.

      参数:
      response - current HTTP response
      返回:
      the XSLT Result to use
      抛出:
      Exception - if the Result cannot be built
    • locateSource

      @Nullable protected Source locateSource(Map<String,Object> model) throws Exception

      Locate the Source object in the supplied model, converting objects as required. The default implementation first attempts to look under the configured source key, if any, before attempting to locate an object of supported type.

      参数:
      model - the merged model Map
      返回:
      the XSLT Source object (or null if none found)
      抛出:
      Exception - if an error occurred during locating the source
      另请参阅:
    • getSourceTypes

      protected Class<?>[] getSourceTypes()
      Return the array of Classes that are supported when converting to an XSLT Source.

      Currently supports Source, Document, Node, Reader, InputStream and Resource.

      返回:
      the supported source types
    • convertSource

      protected Source convertSource(Object sourceObject) throws Exception
      Convert the supplied Object into an XSLT Source if the Object type is supported.
      参数:
      sourceObject - the original source object
      返回:
      the adapted XSLT Source
      抛出:
      IllegalArgumentException - if the given Object is not of a supported type
      Exception
    • configureTransformer

      protected void configureTransformer(Map<String,Object> model, RequestContext response, Transformer transformer)
      Configure the supplied Transformer instance.

      The default implementation copies parameters from the model into the Transformer's parameter set. This implementation also copies the output properties into the Transformer output properties. Indentation properties are set as well.

      参数:
      model - merged output Map (never null)
      response - current HTTP response
      transformer - the target transformer
      另请参阅:
    • configureIndentation

      protected final void configureIndentation(Transformer transformer)
      Configure the indentation settings for the supplied Transformer.
      参数:
      transformer - the target transformer
      另请参阅:
      • TransformerUtils.enableIndenting(Transformer)
      • TransformerUtils.disableIndenting(Transformer)
    • copyOutputProperties

      protected final void copyOutputProperties(Transformer transformer)
      Copy the configured output Properties, if any, into the output property set of the supplied Transformer.
      参数:
      transformer - the target transformer
    • copyModelParameters

      protected final void copyModelParameters(Map<String,Object> model, Transformer transformer)
      Copy all entries from the supplied Map into the parameter set of the supplied Transformer.
      参数:
      model - merged output Map (never null)
      transformer - the target transformer
    • configureResponse

      protected void configureResponse(Map<String,Object> model, RequestContext response, Transformer transformer)
      Configure the supplied RequestContext.

      The default implementation of this method sets the content type from the "media-type" and "encoding" output properties specified in the Transformer.

      参数:
      model - merged output Map (never null)
      response - current HTTP response
      transformer - the target transformer
    • loadTemplates

      private Templates loadTemplates() throws cn.taketoday.context.ApplicationContextException
      Load the Templates instance for the stylesheet at the configured location.
      抛出:
      cn.taketoday.context.ApplicationContextException
    • createTransformer

      protected Transformer createTransformer(Templates templates) throws TransformerConfigurationException
      Create the Transformer instance used to prefer the XSLT transformation.

      The default implementation simply calls Templates.newTransformer(), and configures the Transformer with the custom URIResolver if specified.

      参数:
      templates - the XSLT Templates instance to create a Transformer for
      返回:
      the Transformer object
      抛出:
      TransformerConfigurationException - in case of creation failure
    • getStylesheetSource

      protected Source getStylesheetSource()
      Get the XSLT Source for the XSLT template under the configured URL.
      返回:
      the Source object
    • closeSourceIfNecessary

      private void closeSourceIfNecessary(@Nullable Source source)
      Close the underlying resource managed by the supplied Source if applicable.

      Only works for StreamSources.

      参数:
      source - the XSLT Source to close (may be null)