| org.springframework.web.servlet.view.AbstractView org.springframework.web.servlet.view.xslt.AbstractXsltView
AbstractXsltView | abstract public class AbstractXsltView extends AbstractView (Code) | | Convenient superclass for views rendered using an XSLT stylesheet.
Subclasses typically must provide the
Source to transform
by overriding
AbstractXsltView.createXsltSource . Subclasses do not need to
concern themselves with XSLT other than providing a valid stylesheet location.
Properties:
Note that setting
AbstractXsltView.setCache(boolean) "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 is not thread-safe.
author: Rod Johnson author: Juergen Hoeller author: Darren Davison |
Constructor Summary | |
protected | AbstractXsltView() This constructor sets the content type to "text/xml;charset=ISO-8859-1"
by default. |
Method Summary | |
protected void | applyTransformerParameters(Map parameters, Transformer transformer) Apply the specified parameters to the given Transformer. | protected Transformer | buildTransformer(Map parameters) Build a Transformer object for immediate use, based on the
given parameters. | protected Source | createXsltSource(Map model, String root, HttpServletRequest request, HttpServletResponse response) Return the XML
Source to transform.
Parameters: model - the model Map Parameters: root - name for root element. | protected void | doTransform(Map model, Source source, HttpServletRequest request, HttpServletResponse response) Perform the actual transformation, writing to the HTTP response. | protected void | doTransform(Source source, Map parameters, Result result, String encoding) Perform the actual transformation, writing to the given result. | protected Map | getParameters(Map model, HttpServletRequest request) 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 Map | getParameters() Return a Map of transformer parameters to be applied to the stylesheet. | protected Resource | getStylesheetLocation() Return the location of the XSLT stylesheet, if any. | protected Source | getStylesheetSource(Resource stylesheetLocation) Load the stylesheet from the specified location. | protected Templates | getTemplates() Obtain the Templates object to use, based on the configured
stylesheet, either a cached one or a freshly built one.
Subclasses may override this method e.g. | final protected TransformerFactory | getTransformerFactory() Return the TransformerFactory used by this view. | final protected void | initApplicationContext() Here we load our template, as we need the
org.springframework.context.ApplicationContext to do it. | final protected void | renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) | final public void | resetCachedTemplates() Reset the cached Templates object, if any. | public void | setCache(boolean cache) Set whether to activate the template cache for this view.
Default is true . | public void | setContentType(String contentType) | public void | setErrorListener(ErrorListener errorListener) Set an implementation of the
javax.xml.transform.ErrorListener interface for custom handling of transformation errors and warnings. | public void | setIndent(boolean indent) Set whether the XSLT transformer may add additional whitespace when
outputting the result tree. | public void | setOutputProperties(Properties outputProperties) Set arbitrary transformer output properties to be applied to the stylesheet. | public void | setRoot(String root) The document root element name. | public void | setStylesheetLocation(Resource stylesheetLocation) Set the location of the XSLT stylesheet. | public void | setUriResolver(URIResolver uriResolver) Set the URIResolver used in the transform. | public void | setUseSingleModelNameAsRoot(boolean useSingleModelNameAsRoot) Set whether to use the name of a given single model object as the
document root element name.
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. | protected boolean | useWriter() Return whether to use a java.io.Writer to write text content
to the HTTP response. |
DEFAULT_ROOT | final public static String DEFAULT_ROOT(Code) | | The default document root name
|
XML_CONTENT_TYPE | final public static String XML_CONTENT_TYPE(Code) | | The default content type if no stylesheet specified
|
AbstractXsltView | protected AbstractXsltView()(Code) | | This constructor sets the content type to "text/xml;charset=ISO-8859-1"
by default. This will be switched to the standard web view default
"text/html;charset=ISO-8859-1" if a stylesheet location has been specified.
A specific content type can be configured via the
AbstractXsltView.setContentType "contentType" bean property.
|
createXsltSource | protected Source createXsltSource(Map model, String root, HttpServletRequest request, HttpServletResponse response) throws Exception(Code) | | Return the XML
Source to transform.
Parameters: model - the model Map Parameters: root - name for root element. This can be supplied as a bean propertyto concrete subclasses within the view definition file, but will be overriddenin 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 defaultroot tag name will be supplied. Parameters: request - HTTP request. Subclasses won't normally use this, asrequest processing should have been complete. However, we might want tocreate a RequestContext to expose as part of the model. Parameters: response - HTTP response. Subclasses won't normally use this,however there may sometimes be a need to set cookies. the XSLT Source to transform throws: Exception - if an error occurs |
doTransform | protected void doTransform(Source source, Map parameters, Result result, String encoding) throws Exception(Code) | | Perform the actual transformation, writing to the given result.
Parameters: source - the Source to transform Parameters: parameters - a Map of parameters to be applied to the stylesheet(as determined by AbstractXsltView.getParameters(Map,HttpServletRequest)) Parameters: result - the result to write to Parameters: encoding - the preferred character encoding that the underlying Transformer should use throws: Exception - if an error occurs |
getStylesheetLocation | protected Resource getStylesheetLocation()(Code) | | Return the location of the XSLT stylesheet, if any.
|
getTransformerFactory | final protected TransformerFactory getTransformerFactory()(Code) | | Return the TransformerFactory used by this view.
Available once the View object has been fully initialized.
|
setCache | public void setCache(boolean cache)(Code) | | Set whether to activate the template cache for this view.
Default is true . Turn this off to refresh
the Templates object on every access, e.g. during development.
See Also: AbstractXsltView.resetCachedTemplates() |
setContentType | public void setContentType(String contentType)(Code) | | |
setIndent | public void setIndent(boolean indent)(Code) | | 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.
See Also: javax.xml.transform.OutputKeys.INDENT |
setUriResolver | public void setUriResolver(URIResolver uriResolver)(Code) | | Set the URIResolver used in the transform.
The URIResolver handles calls to the XSLT document() function.
|
setUseSingleModelNameAsRoot | public void setUseSingleModelNameAsRoot(boolean useSingleModelNameAsRoot)(Code) | | Set whether to use the name of a given single model object as the
document root element name.
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
AbstractXsltView.setRoot(String) "root" property .
Parameters: useSingleModelNameAsRoot - true if the name of a given singlemodel object is to be used as the document root element name See Also: AbstractXsltView.setRoot |
useWriter | protected boolean useWriter()(Code) | | Return whether to use a java.io.Writer to write text content
to the HTTP response. Else, a java.io.OutputStream will be used,
to write binary content to the response.
The default implementation returns false , indicating a
a java.io.OutputStream .
whether to use a Writer (true ) or an OutputStream(false ) See Also: javax.servlet.ServletResponse.getWriter See Also: javax.servlet.ServletResponse.getOutputStream |
Fields inherited from org.springframework.web.servlet.view.AbstractView | final public static String DEFAULT_CONTENT_TYPE(Code)(Java Doc)
|
|
|