Class XsltView
- All Implemented Interfaces:
- Aware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- ServletContextAware,- View
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 Spring 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.
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller
- 
Field SummaryFields inherited from class org.springframework.web.servlet.view.AbstractViewDEFAULT_CONTENT_TYPEFields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.servlet.ViewPATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected final voidconfigureIndentation(Transformer transformer) Configure the indentation settings for the suppliedTransformer.protected voidconfigureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) Configure the suppliedHttpServletResponse.protected voidconfigureTransformer(Map<String, Object> model, HttpServletResponse response, Transformer transformer) Configure the suppliedTransformerinstance.protected SourceconvertSource(Object sourceObject) protected final voidcopyModelParameters(Map<String, Object> model, Transformer transformer) Copy all entries from the supplied Map into theparameter setof the suppliedTransformer.protected final voidcopyOutputProperties(Transformer transformer) Copy the configured outputProperties, if any, into theoutput property setof the suppliedTransformer.protected ResultcreateResult(HttpServletResponse response) Create the XSLTResultused to render the result of the transformation.protected TransformercreateTransformer(Templates templates) Create theTransformerinstance used to prefer the XSLT transformation.protected Class<?>[]protected SourceGet the XSLTSourcefor the XSLT template under theconfigured URL.protected final TransformerFactoryReturn the TransformerFactory that this XsltView uses.protected voidInitialize this XsltView's TransformerFactory.protected SourcelocateSource(Map<String, Object> model) Locate theSourceobject in the supplied model, converting objects as required.protected TransformerFactorynewTransformerFactory(Class<? extends TransformerFactory> transformerFactoryClass) Instantiate a new TransformerFactory for this view.protected voidrenderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) Subclasses must implement this method to actually render the view.voidsetCacheTemplates(boolean cacheTemplates) Turn on/off the caching of the XSLTTemplatesinstance.voidsetErrorListener(ErrorListener errorListener) Set an implementation of theErrorListenerinterface for custom handling of transformation errors and warnings.voidsetIndent(boolean indent) Set whether the XSLT transformer may add additional whitespace when outputting the result tree.voidsetOutputProperties(Properties outputProperties) Set arbitrary transformer output properties to be applied to the stylesheet.voidsetSourceKey(String sourceKey) Set the name of the model attribute that represents the XSLT Source.voidsetTransformerFactoryClass(Class<? extends TransformerFactory> transformerFactoryClass) Specify the XSLT TransformerFactory class to use.voidsetUriResolver(URIResolver uriResolver) Set the URIResolver used in the transform.Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedViewafterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toStringMethods inherited from class org.springframework.web.servlet.view.AbstractViewaddStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponseMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Constructor Details- 
XsltViewpublic XsltView()
 
- 
- 
Method Details- 
setTransformerFactoryClassSpecify the XSLT TransformerFactory class to use.The default constructor of the specified class will be called to build the TransformerFactory for this view. 
- 
setSourceKey
- 
setUriResolverSet the URIResolver used in the transform.The URIResolver handles calls to the XSLT document()function.
- 
setErrorListenerSet an implementation of theErrorListenerinterface for custom handling of transformation errors and warnings.If not set, a default SimpleTransformErrorListeneris used that simply logs warnings using the logger instance of the view class, and rethrows errors to discontinue the XML transformation.- See Also:
 
- 
setIndentpublic void setIndent(boolean indent) Set whether the XSLT transformer may add additional whitespace when outputting the result tree.Default is true(on); set this tofalse(off) to not specify an "indent" key, leaving the choice up to the stylesheet.- See Also:
 
- 
setOutputPropertiesSet arbitrary transformer output properties to be applied to the stylesheet.Any values specified here will override defaults that this view sets programmatically. 
- 
setCacheTemplatespublic void setCacheTemplates(boolean cacheTemplates) Turn on/off the caching of the XSLTTemplatesinstance.The default value is "true". Only set this to "false" in development, where caching does not seriously impact performance. 
- 
initApplicationContextInitialize this XsltView's TransformerFactory.- Overrides:
- initApplicationContextin class- ApplicationObjectSupport
- Throws:
- ApplicationContextException- in case of initialization errors
- BeansException- if thrown by ApplicationContext methods
- See Also:
 
- 
newTransformerFactoryprotected 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. - Parameters:
- transformerFactoryClass- the specified factory class (if any)
- Returns:
- the new TransactionFactory instance
- See Also:
 
- 
getTransformerFactoryReturn the TransformerFactory that this XsltView uses.- Returns:
- the TransformerFactory (never null)
 
- 
renderMergedOutputModelprotected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws ExceptionDescription copied from class:AbstractViewSubclasses 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. - Specified by:
- renderMergedOutputModelin class- AbstractView
- Parameters:
- model- combined output Map (never- null), with dynamic values taking precedence over static attributes
- request- current HTTP request
- response- current HTTP response
- Throws:
- Exception- if rendering failed
 
- 
createResultCreate the XSLTResultused to render the result of the transformation.The default implementation creates a StreamResultwrapping the supplied HttpServletResponse'sOutputStream.- Parameters:
- response- current HTTP response
- Returns:
- the XSLT Result to use
- Throws:
- Exception- if the Result cannot be built
 
- 
locateSourceLocate the Sourceobject in the supplied model, converting objects as required. The default implementation first attempts to look under the configuredsource key, if any, before attempting to locate an object ofsupported type.- Parameters:
- model- the merged model Map
- Returns:
- the XSLT Source object (or nullif none found)
- Throws:
- Exception- if an error occurred during locating the source
- See Also:
 
- 
getSourceTypesReturn the array ofClassesthat are supported when converting to an XSLTSource.Currently supports Source,Document,Node,Reader,InputStreamandResource.- Returns:
- the supported source types
 
- 
convertSource- Parameters:
- sourceObject- the original source object
- Returns:
- the adapted XSLT Source
- Throws:
- IllegalArgumentException- if the given Object is not of a supported type
- Exception
 
- 
configureTransformerprotected void configureTransformer(Map<String, Object> model, HttpServletResponse response, Transformer transformer) Configure the suppliedTransformerinstance.The default implementation copies parameters from the model into the Transformer's parameter set. This implementation also copies theoutput propertiesinto theTransformeroutput properties. Indentation properties are set as well.- Parameters:
- model- merged output Map (never- null)
- response- current HTTP response
- transformer- the target transformer
- See Also:
 
- 
configureIndentationConfigure the indentation settings for the suppliedTransformer.- Parameters:
- transformer- the target transformer
- See Also:
 
- 
copyOutputPropertiesCopy the configured outputProperties, if any, into theoutput property setof the suppliedTransformer.- Parameters:
- transformer- the target transformer
 
- 
copyModelParametersCopy all entries from the supplied Map into theparameter setof the suppliedTransformer.- Parameters:
- model- merged output Map (never- null)
- transformer- the target transformer
 
- 
configureResponseprotected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) Configure the suppliedHttpServletResponse.The default implementation of this method sets the content typeandencodingfrom the "media-type" and "encoding" output properties specified in theTransformer.- Parameters:
- model- merged output Map (never- null)
- response- current HTTP response
- transformer- the target transformer
 
- 
createTransformerprotected Transformer createTransformer(Templates templates) throws TransformerConfigurationException Create theTransformerinstance used to prefer the XSLT transformation.The default implementation simply calls Templates.newTransformer(), and configures theTransformerwith the customURIResolverif specified.- Parameters:
- templates- the XSLT Templates instance to create a Transformer for
- Returns:
- the Transformer object
- Throws:
- TransformerConfigurationException- in case of creation failure
 
- 
getStylesheetSourceGet the XSLTSourcefor the XSLT template under theconfigured URL.- Returns:
- the Source object
 
 
-