|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.servlet.view.AbstractView org.springframework.web.servlet.view.AbstractUrlBasedView org.springframework.web.servlet.view.xslt.XsltView
public class XsltView
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 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.
Field Summary |
---|
Fields inherited from class org.springframework.web.servlet.view.AbstractView |
---|
DEFAULT_CONTENT_TYPE |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
logger |
Constructor Summary | |
---|---|
XsltView()
|
Method Summary | |
---|---|
protected void |
configureIndentation(Transformer transformer)
Configure the indentation settings for the supplied Transformer . |
protected void |
configureResponse(Map model,
HttpServletResponse response,
Transformer transformer)
Configure the supplied HttpServletResponse . |
protected void |
configureTransformer(Map model,
HttpServletResponse response,
Transformer transformer)
Configure the supplied Transformer instance. |
protected Source |
convertSource(Object source)
Convert the supplied Object into an XSLT Source if the
Object type is supported . |
protected void |
copyModelParameters(Map model,
Transformer transformer)
Copy all entries from the supplied Map into the parameter set
of the supplied Transformer . |
protected void |
copyOutputProperties(Transformer transformer)
Copy the configured output Properties , if any, into the
output property set of the supplied
Transformer . |
protected Result |
createResult(HttpServletResponse response)
Create the XSLT Result used to render the result of the transformation. |
protected Transformer |
createTransformer(Templates templates)
Create the Transformer instance used to prefer the XSLT transformation. |
protected Class[] |
getSourceTypes()
Return the array of Classes that are supported when converting to an
XSLT Source . |
protected Source |
getStylesheetSource()
Get the XSLT Source for the XSLT template under the configured URL . |
protected TransformerFactory |
getTransformerFactory()
Return the TransformerFactory that this XsltView uses. |
protected void |
initApplicationContext()
Initialize this XsltView's TransformerFactory. |
protected Source |
locateSource(Map model)
Locate the Source object in the supplied model,
converting objects as required. |
protected void |
renderMergedOutputModel(Map model,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to actually render the view. |
void |
setCacheTemplates(boolean cacheTemplates)
Turn on/off the caching of the XSLT Templates instance. |
void |
setErrorListener(ErrorListener errorListener)
Set an implementation of the ErrorListener
interface for custom handling of transformation errors and warnings. |
void |
setIndent(boolean indent)
Set whether the XSLT transformer may add additional whitespace when outputting the result tree. |
void |
setOutputProperties(Properties outputProperties)
Set arbitrary transformer output properties to be applied to the stylesheet. |
void |
setSourceKey(String sourceKey)
Set the name of the model attribute that represents the XSLT Source. |
void |
setUriResolver(URIResolver uriResolver)
Set the URIResolver used in the transform. |
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView |
---|
afterPropertiesSet, getUrl, setUrl, toString |
Methods inherited from class org.springframework.web.servlet.view.AbstractView |
---|
addStaticAttribute, createRequestContext, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XsltView()
Method Detail |
---|
public void setSourceKey(String sourceKey)
The following source types are supported out of the box:
Source
, Document
, Node
, Reader
,
InputStream
and Resource
.
public void setUriResolver(URIResolver uriResolver)
The URIResolver handles calls to the XSLT document()
function.
public void setErrorListener(ErrorListener errorListener)
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.
SimpleTransformErrorListener
public void setIndent(boolean indent)
Default is true
(on); set this to false
(off)
to not specify an "indent" key, leaving the choice up to the stylesheet.
OutputKeys.INDENT
public void setOutputProperties(Properties outputProperties)
Any values specified here will override defaults that this view sets programmatically.
public void setCacheTemplates(boolean cacheTemplates)
Templates
instance.
The default value is "true". Only set this to "false" in development, where caching does not seriously impact performance.
protected void initApplicationContext() throws BeansException
initApplicationContext
in class ApplicationObjectSupport
ApplicationContextException
- in case of initialization errors
BeansException
- if thrown by ApplicationContext methodsApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)
protected final TransformerFactory getTransformerFactory()
null
)protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception
AbstractView
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
in class AbstractView
model
- combined output Map (never null
),
with dynamic values taking precedence over static attributesrequest
- current HTTP requestresponse
- current HTTP response
Exception
- if rendering failedprotected Result createResult(HttpServletResponse response) throws Exception
Result
used to render the result of the transformation.
The default implementation creates a StreamResult
wrapping the supplied
HttpServletResponse's OutputStream
.
response
- current HTTP response
Exception
- if the Result cannot be builtprotected Source locateSource(Map 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
null
if none found)
Exception
- if an error occured during locating the sourcesetSourceKey(java.lang.String)
,
convertSource(java.lang.Object)
protected Class[] getSourceTypes()
Classes
that are supported when converting to an
XSLT Source
.
Currently supports Source
, Document
, Node
,
Reader
, InputStream
and Resource
.
protected Source convertSource(Object source) throws Exception
Object
into an XSLT Source
if the
Object
type is supported
.
source
- the original source object
IllegalArgumentException
- if the given Object is not of a supported type
Exception
protected void configureTransformer(Map model, HttpServletResponse response, Transformer transformer)
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 responsetransformer
- the target transformercopyModelParameters(Map, Transformer)
,
copyOutputProperties(Transformer)
,
configureIndentation(Transformer)
protected final void configureIndentation(Transformer transformer)
Transformer
.
transformer
- the target transformer
IllegalArgumentException
- if the supplied Transformer
is null
TransformerUtils.enableIndenting(javax.xml.transform.Transformer)
,
TransformerUtils.disableIndenting(javax.xml.transform.Transformer)
protected final void copyOutputProperties(Transformer transformer)
Properties
, if any, into the
output property set
of the supplied
Transformer
.
transformer
- the target transformerprotected final void copyModelParameters(Map model, Transformer transformer)
parameter set
of the supplied Transformer
.
model
- merged output Map (never null
)transformer
- the target transformerprotected void configureResponse(Map model, HttpServletResponse response, Transformer transformer)
HttpServletResponse
.
The default implementation of this method sets the
content type
and
encoding
from the "media-type" and "encoding" output properties
specified in the Transformer
.
model
- merged output Map (never null
)response
- current HTTP responsetransformer
- the target transformerprotected Transformer createTransformer(Templates templates) throws TransformerConfigurationException
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
TransformerConfigurationException
protected Source getStylesheetSource()
Source
for the XSLT template under the configured URL
.
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |