类 XsltView
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
detectedduring response rendering. Users can either specify a specific entry in the model via thesourceKeyproperty or have Spring locate the Source object. This class also provides basic conversion of objects into Source implementations. Seeherefor more details.All model parameters are passed to the XSLT Transformer as parameters. In addition the user can configure
output propertiesto be passed to the Transformer.- 从以下版本开始:
- 2.0
- 作者:
- Rob Harrop, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.web.servlet.view.AbstractView
DEFAULT_CONTENT_TYPE
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
从接口继承的字段 org.springframework.web.servlet.View
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
构造器概要
构造器 构造器 说明 XsltView()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected 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 source)protected voidcopyModelParameters(Map<String,Object> model, Transformer transformer)Copy all entries from the supplied Map into theparameter setof the suppliedTransformer.protected 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<?>[]getSourceTypes()protected SourcegetStylesheetSource()Get the XSLTSourcefor the XSLT template under theconfigured URL.protected TransformerFactorygetTransformerFactory()Return the TransformerFactory that this XsltView uses.protected voidinitApplicationContext()Initialize 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.从类继承的方法 org.springframework.web.servlet.view.AbstractUrlBasedView
afterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toString
从类继承的方法 org.springframework.web.servlet.view.AbstractView
addStaticAttribute, 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, writeToResponse
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
构造器详细资料
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)
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 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.
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 tofalse(off) to not specify an "indent" key, leaving the choice up to the stylesheet.- 另请参阅:
OutputKeys.INDENT
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 XSLTTemplatesinstance.The default value is "true". Only set this to "false" in development, where caching does not seriously impact performance.
initApplicationContext
protected void initApplicationContext() throws BeansException
Initialize this XsltView's TransformerFactory.- 覆盖:
initApplicationContext在类中ApplicationObjectSupport- 抛出:
ApplicationContextException- in case of initialization errorsBeansException- if thrown by ApplicationContext methods- 另请参阅:
ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)
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
- 另请参阅:
setTransformerFactoryClass(java.lang.Class<? extends javax.xml.transform.TransformerFactory>),getTransformerFactory()
getTransformerFactory
protected final TransformerFactory getTransformerFactory()
Return the TransformerFactory that this XsltView uses.- 返回:
- the TransformerFactory (never
null)
renderMergedOutputModel
protected void renderMergedOutputModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception
从类复制的说明: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.
- 指定者:
renderMergedOutputModel在类中AbstractView- 参数:
model- combined output Map (nevernull), with dynamic values taking precedence over static attributesrequest- current HTTP requestresponse- current HTTP response- 抛出:
Exception- if rendering failed
createResult
protected Result createResult(HttpServletResponse response) throws Exception
Create the XSLTResultused to render the result of the transformation.The default implementation creates a
StreamResultwrapping the supplied HttpServletResponse'sOutputStream.- 参数:
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
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.- 参数:
model- the merged model Map- 返回:
- the XSLT Source object (or
nullif none found) - 抛出:
Exception- if an error occurred during locating the source- 另请参阅:
setSourceKey(java.lang.String),convertSource(java.lang.Object)
getSourceTypes
protected Class<?>[] getSourceTypes()
Return the array ofClassesthat are supported when converting to an XSLTSource.Currently supports
Source,Document,Node,Reader,InputStreamandResource.- 返回:
- the supported source types
convertSource
protected Source convertSource(Object source) throws Exception
- 参数:
source- the original source object- 返回:
- the adapted XSLT Source
- 抛出:
IllegalArgumentException- if the given Object is not of a supported typeException
configureTransformer
protected 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.- 参数:
model- merged output Map (nevernull)response- current HTTP responsetransformer- the target transformer- 另请参阅:
copyModelParameters(Map, Transformer),copyOutputProperties(Transformer),configureIndentation(Transformer)
configureIndentation
protected final void configureIndentation(Transformer transformer)
Configure the indentation settings for the suppliedTransformer.- 参数:
transformer- the target transformer- 另请参阅:
TransformerUtils.enableIndenting(javax.xml.transform.Transformer),TransformerUtils.disableIndenting(javax.xml.transform.Transformer)
copyOutputProperties
protected final void copyOutputProperties(Transformer transformer)
Copy the configured outputProperties, if any, into theoutput property setof the suppliedTransformer.- 参数:
transformer- the target transformer
copyModelParameters
protected final void copyModelParameters(Map<String,Object> model, Transformer transformer)
Copy all entries from the supplied Map into theparameter setof the suppliedTransformer.- 参数:
model- merged output Map (nevernull)transformer- the target transformer
configureResponse
protected 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.- 参数:
model- merged output Map (nevernull)response- current HTTP responsetransformer- the target transformer
createTransformer
protected 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.- 参数:
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 XSLTSourcefor the XSLT template under theconfigured URL.- 返回:
- the Source object