org.springframework.web.servlet.view.xslt
Class AbstractXsltView

java.lang.Object
  extended byorg.springframework.context.support.ApplicationObjectSupport
      extended byorg.springframework.web.context.support.WebApplicationObjectSupport
          extended byorg.springframework.web.servlet.view.AbstractView
              extended byorg.springframework.web.servlet.view.xslt.AbstractXsltView
All Implemented Interfaces:
ApplicationContextAware, BeanNameAware, View

public abstract class AbstractXsltView
extends AbstractView

Convenient superclass for views rendered using an XSLT stylesheet. Subclasses must provide the XML W3C document to transform. They do not need to concern themselves with XSLT.

Properties:

Setting cache to false will cause the templates object to be reloaded for each rendering. This is useful during development, but will seriously affect performance in production and isn't threadsafe.

Version:
$Id: AbstractXsltView.java,v 1.10 2004/03/18 02:46:14 trisberg Exp $
Author:
Rod Johnson, Darren Davison

Field Summary
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
AbstractXsltView()
           
 
Method Summary
protected abstract  org.w3c.dom.Node createDomNode(java.util.Map model, java.lang.String root, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Return the XML node to transform.
protected  void doTransform(javax.servlet.http.HttpServletResponse response, org.w3c.dom.Node dom)
          Use TrAX to perform the transform.
protected  java.util.Map getParameters()
          Return a Map of parameters to be applied to the stylesheet.
protected  javax.xml.transform.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(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Subclasses must implement this method to render the view.
 void setCache(boolean cache)
          Activate or deactivate the cache.
 void setRoot(java.lang.String root)
          Document root element name.
 void setStylesheetLocation(Resource stylesheetLocation)
          Set the location of the XSLT stylesheet.
 void setUriResolver(javax.xml.transform.URIResolver uriResolver)
          Set the URIResolver used in the transform.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, getBeanName, getContentType, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, requiredContextClass
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractXsltView

public AbstractXsltView()
Method Detail

setStylesheetLocation

public final void setStylesheetLocation(Resource stylesheetLocation)
Set the location of the XSLT stylesheet.

Parameters:
stylesheetLocation - the location of the XSLT stylesheet
See Also:
ResourceLoader.getResource(java.lang.String)

setRoot

public final void setRoot(java.lang.String root)
Document root element name. Only used if we're not passed a single Node as model.

Parameters:
root - document root element name

setUriResolver

public final void setUriResolver(javax.xml.transform.URIResolver uriResolver)
Set the URIResolver used in the transform. The URIResolver handles calls to the XSLT document() function. This method can be used by subclasses or as a bean property

Parameters:
uriResolver - URIResolver to set. No URIResolver will be set if this is null (this is the default).

setCache

public final void setCache(boolean cache)
Activate or deactivate the cache.

Parameters:
cache - whether to activate the cache

initApplicationContext

protected final void initApplicationContext()
                                     throws ApplicationContextException
Here we load our template, as we need the ApplicationContext to do it.

Overrides:
initApplicationContext in class ApplicationObjectSupport
Throws:
ApplicationContextException - in case of initialization errors

getStylesheetSource

protected javax.xml.transform.Source getStylesheetSource(Resource stylesheetLocation)
                                                  throws ApplicationContextException
Load the stylesheet. Subclasses can override this.

Throws:
ApplicationContextException

renderMergedOutputModel

protected final void renderMergedOutputModel(java.util.Map model,
                                             javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response)
                                      throws java.lang.Exception
Description copied from class: AbstractView
Subclasses must implement this method to render the view.

The first take will be preparing the request: This may include setting the model elements as request attributes, e.g. in the case of a JSP view.

Specified by:
renderMergedOutputModel in class AbstractView
Parameters:
model - combined output Map, with dynamic values taking precedence over static attributes
request - current HTTP request
response - current HTTP response
Throws:
java.lang.Exception - if rendering failed

createDomNode

protected abstract org.w3c.dom.Node createDomNode(java.util.Map model,
                                                  java.lang.String root,
                                                  javax.servlet.http.HttpServletRequest request,
                                                  javax.servlet.http.HttpServletResponse response)
                                           throws java.lang.Exception
Return the XML node to transform. Subclasses must implement this method.

Parameters:
model - the model Map
root - 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.
Throws:
java.lang.Exception - we let this method throw any exception; the AbstractXlstView superclass will catch exceptions

getParameters

protected java.util.Map getParameters()
Return a Map of parameters to be applied to the stylesheet. Subclasses can override the default implementation (which simply returns null) in order to apply one or more parameters to the transformation process.

Returns:
a Map of parameters to apply to the transformation process
See Also:
Transformer.setParameter(java.lang.String, java.lang.Object)

doTransform

protected void doTransform(javax.servlet.http.HttpServletResponse response,
                           org.w3c.dom.Node dom)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Use TrAX to perform the transform.

Throws:
javax.servlet.ServletException
java.io.IOException


Copyright (C) 2003-2004 The Spring Framework Project.