Class AbstractXsltView

All Implemented Interfaces:
ApplicationContextAware, View

public abstract class AbstractXsltView
extends AbstractView
implements ApplicationContextAware

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:

  • stylesheet: no transform is null
  • uriResolver:
  • cache (optional, default=false): debug setting only. Setting this to true 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. root: name of the root element

    $Id:,v 1.2 2003/05/11 07:04:04 johnsonr Exp $
    Rod Johnson

    Fields inherited from class
    Constructor Summary
              Creates new XsltView
    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)
              Subclasses must implement this method 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
     boolean getCache()
              Gets the cache.
    protected  javax.xml.transform.Source getStylesheetSource(java.lang.String url)
              Load the stylesheet.
    protected  void initApplicationContext()
              Set the ApplicationContext object used by this object.
    protected  void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
              Renders the view given the specified model.
     void setCache(boolean cache)
              Sets the cache.
     void setRoot(java.lang.String root)
              Document root element name.
     void setStylesheet(java.lang.String url)
              Set the URL of the XSLT stylesheet
     void setUriResolver(javax.xml.transform.URIResolver uriResolver)
              Set the URIResolver used in the transform.
    Methods inherited from class com.interface21.web.servlet.view.AbstractView
    addStaticAttribute, getContentType, getName, getStaticAttributes, render, setAttributes, setAttributesCSV, setContentType, setName, setRequestContextAttribute
    Methods inherited from class
    getApplicationContext, setApplicationContext
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Methods inherited from interface com.interface21.context.ApplicationContextAware

    Constructor Detail


    public AbstractXsltView()
    Creates new XsltView
    Method Detail


    public final void setStylesheet(java.lang.String url)
    Set the URL of the XSLT stylesheet
    url - the URL of the XSLT stylesheet


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


    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
    uriResolver - URIResolver to set. No URIResolver will be set if this is null (this is the default).


    public final boolean getCache()
    Gets the cache.
    Returns a boolean


    public final void setCache(boolean cache)
    Sets the cache.
    cache - The cache to set


    protected final void initApplicationContext()
                                         throws ApplicationContextException
    Set the ApplicationContext object used by this object. Here is also where we load our template, as we need the Application Context to do it
    initApplicationContext in class ApplicationObjectSupport
    ctx - ApplicationContext object used by this object
    namespace - namespace this object is in: null means default namespace
    ApplicationContextException - if initialization attempted by this object after it has access to the WebApplicatinContext fails


    protected javax.xml.transform.Source getStylesheetSource(java.lang.String url)
                                                      throws ApplicationContextException
    Load the stylesheet. This implementation uses getRealPath(). Subclasses can override this method to avoid any container restrictions on use of this slightly questionable method. However, when it does work it's efficient and convenient.


    protected final void renderMergedOutputModel(java.util.Map model,
                                                 javax.servlet.http.HttpServletRequest request,
                                                 javax.servlet.http.HttpServletResponse response)
                                          throws javax.servlet.ServletException,
    Renders the view given the specified model. There can be many types of view.
    The first take will be preparing the request: this may include setting the model as an attribute, in the case of a JSP view.
    renderMergedOutputModel in class AbstractView
    Following copied from class: com.interface21.web.servlet.view.AbstractView
    model - combined output Map, with dynamic values taking precedence over static attributes
    request - current HTTP request
    response - current HTTP response
    Throws: - if there is an IO exception trying to obtain or render the view
    javax.servlet.ServletException - if there is any other error


    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
    Subclasses must implement this method Return the XML node to transform.
    model - model
    root - name for root element
    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.
    java.lang.Exception - we let this method throw any exception; the AbstractXlstView superclass will catch exceptions


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

    Rod Johnson and Spring contributors 2001-2003.