|
||||||||||
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.xslt.AbstractXsltView
public abstract class AbstractXsltView
Convenient superclass for views rendered using an XSLT stylesheet.
Subclasses must either provide the XML W3C Document or Node to
transform by overriding createDomNode()
, or provide the
Source
to transform by overriding createXsltSource()
.
Note that createXsltSource()
is the preferred method which all
new subclasses should override since Spring 1.2. createDomNode()
has been deprecated and may be removed in a future version.
Subclasses do not need to concern themselves with XSLT other than providing a valid stylesheet location.
Properties:
Resource
pointing to the
XSLT stylesheet
Note that setting "cache" to "false" will cause the template objects to be reloaded for each rendering. This is useful during development, but will seriously affect performance in production and isn't thread-safe.
Field Summary | |
---|---|
static String |
DEFAULT_ROOT
|
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 | |
---|---|
AbstractXsltView()
|
Method Summary | |
---|---|
protected Node |
createDomNode(Map model,
String root,
HttpServletRequest request,
HttpServletResponse response)
Deprecated. in favor of createXsltSource(Map, String, HttpServletRequest, HttpServletResponse) |
protected Source |
createXsltSource(Map model,
String root,
HttpServletRequest request,
HttpServletResponse response)
Return the XML Source to transform. |
protected void |
doTransform(Map model,
Node dom,
HttpServletRequest request,
HttpServletResponse response)
Deprecated. the preferred method is doTransform with a Source argument |
protected void |
doTransform(Map model,
Source source,
HttpServletRequest request,
HttpServletResponse response)
Perform the actual transformation, writing to the HTTP response. |
protected void |
doTransform(Node dom,
Map parameters,
Result result,
String encoding)
Deprecated. the preferred method is doTransform(Source source, Map parameters, Result result, String encoding) |
protected void |
doTransform(Source source,
Map parameters,
Result result,
String encoding)
Perform the actual transformation, writing to the given result. |
protected Map |
getParameters()
Return a Map of transformer parameters to be applied to the stylesheet. |
protected Map |
getParameters(HttpServletRequest request)
Return a Map of transformer parameters to be applied to the stylesheet. |
protected Source |
getStylesheetSource(Resource stylesheetLocation)
Load the stylesheet. |
protected void |
initApplicationContext()
Here we load our template, as we need the ApplicationContext to do it. |
protected void |
renderMergedOutputModel(Map model,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to actually render the view. |
void |
setCache(boolean cache)
Set whether to activate the cache. |
void |
setErrorListener(ErrorListener errorListener)
Set an implementation of the javax.xml.transform.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 |
setRoot(String root)
Document root element name. |
void |
setStylesheetLocation(Resource stylesheetLocation)
Set the location of the XSLT stylesheet. |
void |
setUriResolver(URIResolver uriResolver)
Set the URIResolver used in the transform. |
void |
setUseSingleModelNameAsRoot(boolean useSingleModelNameAsRoot)
Set whether to use the name of a given single model object as document root element name. |
Methods inherited from class org.springframework.web.servlet.view.AbstractView |
---|
addStaticAttribute, createRequestContext, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute, toString |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, isContextRequired |
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 |
Field Detail |
---|
public static final String DEFAULT_ROOT
Constructor Detail |
---|
public AbstractXsltView()
Method Detail |
---|
public void setStylesheetLocation(Resource stylesheetLocation)
stylesheetLocation
- the location of the XSLT stylesheetResourceLoader.getResource(java.lang.String)
public void setRoot(String root)
root
- the document root element nameDEFAULT_ROOT
public void setUseSingleModelNameAsRoot(boolean useSingleModelNameAsRoot)
Default is "true": If you pass in a model with a single object named "myElement", then the document root will be named "myElement" as well. Set this flag to "false" if you want to pass in a single model object while still using the root element name configured through the "root" property.
setRoot(java.lang.String)
public void setUriResolver(URIResolver uriResolver)
uriResolver
- URIResolver to set. No URIResolver
will be set if this is null (this is the default).public void setErrorListener(ErrorListener errorListener)
javax.xml.transform.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)
OutputKeys.INDENT
public void setOutputProperties(Properties outputProperties)
Any values specified here will override defaults that this view sets programmatically.
outputProperties
- output properties to apply to the transformation processTransformer.setOutputProperty(java.lang.String, java.lang.String)
public void setCache(boolean cache)
protected final void initApplicationContext() throws ApplicationContextException
initApplicationContext
in class ApplicationObjectSupport
ApplicationContextException
- in case of initialization errorsApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)
protected Source getStylesheetSource(Resource stylesheetLocation) throws ApplicationContextException
ApplicationContextException
protected final 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 Source createXsltSource(Map model, String root, HttpServletRequest request, HttpServletResponse response) throws Exception
Source
to transform. Subclasses must implement
either this method or createDomNode
, which is
retained only for backward compatibility.
model
- the model Maproot
- name for root element. This can be supplied as a bean property
to concrete subclasses within the view definition file, but will be overridden
in the case of a single object in the model map to be the key for that object.
If no root property is specified and multiple model objects exist, a default
root tag name will be supplied.request
- HTTP request. Subclasses won't normally use this, as
request processing should have been complete. However, we might to
create a RequestContext to expose as part of the model.response
- HTTP response. Subclasses won't normally use this,
however there may sometimes be a need to set cookies.
Exception
- we let this method throw any exception; the
AbstractXlstView superclass will catch exceptionsprotected Node createDomNode(Map model, String root, HttpServletRequest request, HttpServletResponse response) throws Exception
createXsltSource(Map, String, HttpServletRequest, HttpServletResponse)
Node
to transform.
This method is deprecated from version 1.2 with the preferred extension point
being createXsltSource(Map, String, HttpServletRequest, HttpServletResponse)
instead. Code that previously implemented this method can now override the preferred
method, returning new DOMSource(node)
in place of returning node
model
- the model Maproot
- name for root element. This can be supplied as a bean property
to concrete subclasses within the view definition file, but will be overridden
in the case of a single object in the model map to be the key for that object.
If no root property is specified and multiple model objects exist, a default
root tag name will be supplied.request
- HTTP request. Subclasses won't normally use this, as
request processing should have been complete. However, we might to
create a RequestContext to expose as part of the model.response
- HTTP response. Subclasses won't normally use this,
however there may sometimes be a need to set cookies.
Exception
- we let this method throw any exception; the
AbstractXlstView superclass will catch exceptionsprotected void doTransform(Map model, Node dom, HttpServletRequest request, HttpServletResponse response) throws Exception
doTransform
with a Source argument
Default implementation delegates to the doTransform version that takes a Result argument, building a StreamResult for the ServletResponse OutputStream.
model
- the model Mapdom
- the XNL node to transformrequest
- current HTTP requestresponse
- current HTTP response
Exception
- we let this method throw any exception; the
AbstractXlstView superclass will catch exceptionsdoTransform(Node, Map, Result, String)
,
StreamResult
,
ServletResponse.getOutputStream()
,
doTransform(Map, Source, HttpServletRequest, HttpServletResponse)
,
doTransform(java.util.Map, javax.xml.transform.Source, HttpServletRequest, HttpServletResponse)
protected void doTransform(Map model, Source source, HttpServletRequest request, HttpServletResponse response) throws Exception
Default implementation delegates to the doTransform version that takes a Result argument, building a StreamResult for the ServletResponse OutputStream.
model
- the model Mapsource
- the Source to transformrequest
- current HTTP requestresponse
- current HTTP response
Exception
- we let this method throw any exception; the
AbstractXlstView superclass will catch exceptionsdoTransform(Node, Map, Result, String)
,
StreamResult
,
ServletResponse.getOutputStream()
protected void doTransform(Node dom, Map parameters, Result result, String encoding) throws Exception
doTransform(Source source, Map parameters, Result result, String encoding)
doTransform(Source, Map, Result, String)
version.
dom
- the XML node to transformparameters
- a Map of parameters to be applied to the stylesheetresult
- the result to write to
Exception
- we let this method throw any exception; the
AbstractXlstView superclass will catch exceptionsdoTransform(Source, Map, Result, String)
protected void doTransform(Source source, Map parameters, Result result, String encoding) throws Exception
source
- the Source to transformparameters
- a Map of parameters to be applied to the stylesheetresult
- the result to write to
Exception
- we let this method throw any exception; the
AbstractXlstView superclass will catch exceptionsprotected Map getParameters(HttpServletRequest request)
Default implementation delegates to simple
getParameters
version.
request
- current HTTP request
getParameters()
,
Transformer.setParameter(java.lang.String, java.lang.Object)
protected Map getParameters()
Default implementation delegates simply returns null
.
getParameters(HttpServletRequest)
,
Transformer.setParameter(java.lang.String, java.lang.Object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |