com.interface21.web.servlet.view.xslt
Class AbstractXsltView

java.lang.Object
  |
  +--com.interface21.context.support.ApplicationObjectSupport
        |
        +--com.interface21.web.servlet.view.AbstractView
              |
              +--com.interface21.web.servlet.view.xslt.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

    Version:
    $Id: AbstractXsltView.java,v 1.2 2003/05/11 07:04:04 johnsonr Exp $
    Author:
    Rod Johnson

    Fields inherited from class com.interface21.context.support.ApplicationObjectSupport
    logger
     
    Constructor Summary
    AbstractXsltView()
              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 com.interface21.context.support.ApplicationObjectSupport
    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
    setApplicationContext
     

    Constructor Detail

    AbstractXsltView

    public AbstractXsltView()
    Creates new XsltView
    Method Detail

    setStylesheet

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

    setRoot

    public final void setRoot(java.lang.String root)
    Document root element name. Only used if we're not passed a Node.
    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).

    getCache

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

    setCache

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

    initApplicationContext

    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
    Overrides:
    initApplicationContext in class ApplicationObjectSupport
    Parameters:
    ctx - ApplicationContext object used by this object
    namespace - namespace this object is in: null means default namespace
    Throws:
    ApplicationContextException - if initialization attempted by this object after it has access to the WebApplicatinContext fails

    getStylesheetSource

    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.

    renderMergedOutputModel

    protected final void renderMergedOutputModel(java.util.Map model,
                                                 javax.servlet.http.HttpServletRequest request,
                                                 javax.servlet.http.HttpServletResponse response)
                                          throws javax.servlet.ServletException,
                                                 java.io.IOException
    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.
    Overrides:
    renderMergedOutputModel in class AbstractView
    Following copied from class: com.interface21.web.servlet.view.AbstractView
    Parameters:
    model - combined output Map, with dynamic values taking precedence over static attributes
    request - current HTTP request
    response - current HTTP response
    Throws:
    java.io.IOException - if there is an IO exception trying to obtain or render the view
    javax.servlet.ServletException - if there is any other error

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

    doTransform

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


    Rod Johnson and Spring contributors 2001-2003.