org.benow.web.path.page
Class PagePathHandler

java.lang.Object
  extended by org.benow.web.path.PathHandler
      extended by org.benow.web.path.FileBasedPathHandler
          extended by org.benow.web.path.page.PagePathHandler

public class PagePathHandler
extends FileBasedPathHandler

Processes a .page dynamic page. Pages are xsl, with a few workarounds. They sit in the html/ directory and reference libraries from lib/xsl/ (the default root for xsl:includes). There are some custom directives, or TagProcessors including ServiceTagProcessor (for service manager calls) and ObjectTagProcessor (for objects return from query). Other tag processors can be added. See javadoc for specification. These custom processors graft the DOM result of custom processing onto the html DOM result tree. Also, there is a method to include freeform data in the returned stream via the <stream> tag.

The stream tag is of one of two formats <stream class="org.some.ClassName"

Author:
andy
See Also:
ServiceTagProcessor, ObjectTagProcessor

Field Summary
static java.lang.String PAGE_TAG
           
static java.lang.String PARAM_PAGE_PATH
          In QueryParams, the external path to the page without any loose parameters (ie project/browse.page, not html/project/browse/aproject/)
static java.lang.String RHT_RENDER
          render key for request handler thread
static java.lang.String SESSION_ABSENT_URL
           
protected  org.benow.xml.xsl.XSL xsl
           
 
Fields inherited from class org.benow.web.path.FileBasedPathHandler
base
 
Fields inherited from class org.benow.web.path.PathHandler
CONTENT_LENGTH_UNKNOWN, LAST_MODIFIED_UNKNOWN, params, request, response
 
Constructor Summary
PagePathHandler()
           
 
Method Summary
static void addEnv(org.w3c.dom.Document doc)
          Adds the environment nodes to the root element of the given document.
static void addEnv(org.w3c.dom.Document doc, org.w3c.dom.Element e, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, QueryParams params)
           
 boolean canHandle(java.lang.String path)
          ensure to call this method
static boolean canRecordXML()
           
static org.w3c.dom.Document getXML(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, QueryParams params)
          Override to provide xml for initial page rendering
protected  org.benow.xml.xsl.XSL getXSL(java.net.URL xslURL)
          Creates an xsl transformer for the pathspec.
protected  java.lang.Object handle(java.io.PrintWriter w)
           
static boolean handlesFile(java.lang.String name)
           
protected  java.lang.String marshallToXML(java.lang.Object result)
           
protected  java.io.File onAbsentXSL(java.lang.String baseName)
          Override to do something on absent xsl (like create it)
 void postProcessHTML(org.w3c.dom.Element htmlElem, java.util.Map<java.lang.String,java.lang.Object> templateParams, org.benow.xml.xsl.XSL source, java.lang.String inputXML)
           
static void recordXML(java.lang.String url, java.lang.String name, java.lang.String xml2)
           
 javax.xml.transform.stream.StreamSource resolve(java.lang.String href, java.lang.String base)
          Called during xsl transform to resolve <xsl:include> hrefs.
protected  void setXSL(java.lang.String path)
          Call to set xsl manually, instead of via PagePathHandler.canHandle(String)
protected  void transform(org.w3c.dom.Document xmlDoc, java.util.Map<java.lang.String,java.lang.Object> templateParams, org.w3c.dom.Element contentE)
          Transform the source xml onto the given output element using the given parameters.
 
Methods inherited from class org.benow.web.path.FileBasedPathHandler
deliverFile, deliverResource
 
Methods inherited from class org.benow.web.path.PathHandler
deliverHTML, deliverStream, deliverStream, deliverStream, handle, handle, handle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RHT_RENDER

public static final java.lang.String RHT_RENDER
render key for request handler thread

See Also:
Constant Field Values

SESSION_ABSENT_URL

public static final java.lang.String SESSION_ABSENT_URL
See Also:
Constant Field Values

PAGE_TAG

public static final java.lang.String PAGE_TAG
See Also:
Constant Field Values

PARAM_PAGE_PATH

public static final java.lang.String PARAM_PAGE_PATH
In QueryParams, the external path to the page without any loose parameters (ie project/browse.page, not html/project/browse/aproject/)

See Also:
Constant Field Values

xsl

protected org.benow.xml.xsl.XSL xsl
Constructor Detail

PagePathHandler

public PagePathHandler()
Method Detail

canHandle

public boolean canHandle(java.lang.String path)
                  throws WebException,
                         java.io.IOException
ensure to call this method

Specified by:
canHandle in class PathHandler
Returns:
Throws:
WebException
java.io.IOException

setXSL

protected void setXSL(java.lang.String path)
               throws WebException
Call to set xsl manually, instead of via PagePathHandler.canHandle(String)

Parameters:
path -
Throws:
WebException

handle

protected java.lang.Object handle(java.io.PrintWriter w)
                           throws java.io.IOException,
                                  WebException
Overrides:
handle in class PathHandler
Throws:
java.io.IOException
WebException

transform

protected void transform(org.w3c.dom.Document xmlDoc,
                         java.util.Map<java.lang.String,java.lang.Object> templateParams,
                         org.w3c.dom.Element contentE)
                  throws javax.xml.transform.TransformerException
Transform the source xml onto the given output element using the given parameters.

Override this method to introduce new parameters or xml in descendants

Parameters:
xml -
templateParams -
contentE -
Throws:
javax.xml.transform.TransformerException

canRecordXML

public static boolean canRecordXML()

recordXML

public static void recordXML(java.lang.String url,
                             java.lang.String name,
                             java.lang.String xml2)

postProcessHTML

public void postProcessHTML(org.w3c.dom.Element htmlElem,
                            java.util.Map<java.lang.String,java.lang.Object> templateParams,
                            org.benow.xml.xsl.XSL source,
                            java.lang.String inputXML)
                     throws java.lang.Throwable
Parameters:
htmlElem - result html element
templateParams - params used with xsl to generate including page
source - xsl used to generate including page
inputXML - xml input to including page
Throws:
java.lang.Throwable

getXML

public static org.w3c.dom.Document getXML(javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response,
                                          QueryParams params)
                                   throws java.lang.Exception
Override to provide xml for initial page rendering

Parameters:
request -
response -
params -
Returns:
Throws:
java.lang.Exception

addEnv

public static void addEnv(org.w3c.dom.Document doc)
Adds the environment nodes to the root element of the given document. Environment nodes include:

addEnv

public static void addEnv(org.w3c.dom.Document doc,
                          org.w3c.dom.Element e,
                          javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          QueryParams params)

marshallToXML

protected java.lang.String marshallToXML(java.lang.Object result)
                                  throws java.io.IOException,
                                         javax.xml.transform.TransformerException
Throws:
java.io.IOException
javax.xml.transform.TransformerException

getXSL

protected org.benow.xml.xsl.XSL getXSL(java.net.URL xslURL)
                                throws java.lang.Exception
Creates an xsl transformer for the pathspec. The actual xsl file to use is resolved in a specific order. See code for details.

Parameters:
baseName -
Returns:
Throws:
java.lang.Exception
WebException

onAbsentXSL

protected java.io.File onAbsentXSL(java.lang.String baseName)
Override to do something on absent xsl (like create it)

Parameters:
baseName -
Returns:

resolve

public javax.xml.transform.stream.StreamSource resolve(java.lang.String href,
                                                       java.lang.String base)
Called during xsl transform to resolve <xsl:include> hrefs. By default, hrefs are local to including xsl directory. By proving a URIResolver, the actual documents can be included from elsewhere. ie href="lib/libsite.xsl" is translated to "/lib/xsl/libsite.xsl" (relative to protect root)


handlesFile

public static boolean handlesFile(java.lang.String name)