nu.staldal.lsp
Class LSPHelper

java.lang.Object
  extended by nu.staldal.lsp.LSPHelper

public class LSPHelper
extends java.lang.Object

Helper class for loading and executing an LSP pages and serialize the output to a byte stream.

This class should generally be considered as Singleton, usually only one instance is required. An instance of this class is thread-safe, except for the setXXX methods which should not be invoked concurrently with any other method.


Constructor Summary
LSPHelper(java.lang.ClassLoader classLoader)
          Create an LSPHelper.
 
Method Summary
 java.lang.String executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.Object extContext)
          Executes an LSP page and serialize the result to a String Uses any stylesheet specified in the LSP page.
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.Object extContext, java.io.OutputStream out)
          Executes an LSP page and serialize the result to an OutputStream.
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.Object extContext, javax.xml.transform.stream.StreamResult out)
          Executes an LSP page and serialize the result to an StreamResult.
 java.lang.String executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.Object extContext, javax.xml.transform.Templates compiledStylesheet)
          Executes an LSP page, transform the the result with an XSLT stylesheet and serialize the result to a String.
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.Object extContext, javax.xml.transform.Templates compiledStylesheet, java.io.OutputStream out)
          Executes an LSP page, transform the the result with an XSLT stylesheet and serialize the result to an OutputStream The output properties specified in the stylesheet will be used, and those specified in the LSP page will be ignored.
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.Object extContext, javax.xml.transform.Templates compiledStylesheet, javax.xml.transform.stream.StreamResult out)
          Executes an LSP page, transform the the result with an XSLT stylesheet and serialize the result to an StreamResult The output properties specified in the stylesheet will be used, and those specified in the LSP page will be ignored.
 java.lang.String getContentType(LSPPage thePage)
          Get Content-Type (Internet Media Type, MIME type) with character encoding as "charset" parameter from an LSP page.
static java.lang.String getContentType(java.util.Properties outputProperties)
          Get Content-Type (Internet Media Type, MIME type) with character encoding as "charset" parameter from an JAXP/TrAX OutputProperties object.
 java.lang.String getContentType(javax.xml.transform.Templates compiledStylesheet)
          Get Content-Type (Internet Media Type, MIME type) with character encoding as "charset" parameter from compiled stylesheet.
 LSPPage getPage(java.lang.String pageName)
          Get the LSPPage instance for a given page name.
 javax.xml.transform.Templates getStylesheet(java.lang.String stylesheetName)
          Get an compiled XSLT stylesheet.
 void setHtmlEncoding(java.lang.String htmlEncoding)
          Set the default character encoding for HTML.
 void setHtmlType(java.lang.String htmlType)
          Set the default media-type for HTML.
 void setTextEncoding(java.lang.String textEncoding)
          Set the default character encoding for TEXT.
 void setTextType(java.lang.String textType)
          Set the default media-type for TEXT.
 void setXhtmlEncoding(java.lang.String xhtmlEncoding)
          Set the default character encoding for XHTML.
 void setXhtmlType(java.lang.String xhtmlType)
          Set the default media-type for XHTML.
 void setXmlEncoding(java.lang.String xmlEncoding)
          Set the default character encoding for XML.
 void setXmlType(java.lang.String xmlType)
          Set the default media-type for XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LSPHelper

public LSPHelper(java.lang.ClassLoader classLoader)
Create an LSPHelper.

Parameters:
classLoader - ClassLoader to load LSP pages and stylesheet source with
Method Detail

setHtmlType

public void setHtmlType(java.lang.String htmlType)
Set the default media-type for HTML.

Default is "text/html", and this should not be changed.

Parameters:
htmlType - the default media-type for HTML

setXhtmlType

public void setXhtmlType(java.lang.String xhtmlType)
Set the default media-type for XHTML.

Default is "text/html", but another reasonable choice is "application/xhtml+xml".

Parameters:
xhtmlType - the default media-type for XHTML

setXmlType

public void setXmlType(java.lang.String xmlType)
Set the default media-type for XML.

Default is "text/xml", but another reasonable choice is "application/xml".

Parameters:
xmlType - the default media-type for XML

setTextType

public void setTextType(java.lang.String textType)
Set the default media-type for TEXT.

Default is "text/plain".

Parameters:
textType - the default media-type for TEXT

setHtmlEncoding

public void setHtmlEncoding(java.lang.String htmlEncoding)
Set the default character encoding for HTML.

Default is "iso-8859-1".

Parameters:
htmlEncoding - default character encoding for HTML

setXhtmlEncoding

public void setXhtmlEncoding(java.lang.String xhtmlEncoding)
Set the default character encoding for XHTML.

Default is "UTF-8".

Parameters:
xhtmlEncoding - default character encoding for XHTML

setXmlEncoding

public void setXmlEncoding(java.lang.String xmlEncoding)
Set the default character encoding for XML.

Default is "UTF-8".

Parameters:
xmlEncoding - default character encoding for XML

setTextEncoding

public void setTextEncoding(java.lang.String textEncoding)
Set the default character encoding for TEXT.

Default is "iso-8859-1".

Parameters:
textEncoding - default character encoding for TEXT

getStylesheet

public javax.xml.transform.Templates getStylesheet(java.lang.String stylesheetName)
                                            throws javax.xml.transform.TransformerConfigurationException
Get an compiled XSLT stylesheet.

The compiled stylesheets are cached and reused. Stylesheet source is loaded from the supplied ClassLoader.

Parameters:
stylesheetName - the name of the XSLT stylesheet
Returns:
null if the given stylesheet is not found
Throws:
javax.xml.transform.TransformerConfigurationException - if the stylesheet cannot be compiled

getPage

public LSPPage getPage(java.lang.String pageName)
                throws java.lang.InstantiationException,
                       java.lang.IllegalAccessException,
                       java.lang.VerifyError
Get the LSPPage instance for a given page name.

LSPPage instances are cached and reused.

Parameters:
pageName - the name of the LSP page
Returns:
null if the given page is not found
Throws:
java.lang.InstantiationException - if the LSP page cannot be loaded
java.lang.IllegalAccessException - if the LSP page cannot be loaded
java.lang.VerifyError - if the LSP page is damaged

getContentType

public java.lang.String getContentType(LSPPage thePage)
Get Content-Type (Internet Media Type, MIME type) with character encoding as "charset" parameter from an LSP page. If the LSP page specifies a stylesheet, the Content-Type for the stylesheet will be returned.

Parameters:
thePage - the LSP page.
Returns:
the Content-Type

getContentType

public java.lang.String getContentType(javax.xml.transform.Templates compiledStylesheet)
Get Content-Type (Internet Media Type, MIME type) with character encoding as "charset" parameter from compiled stylesheet.

Parameters:
compiledStylesheet - the compiled stylesheet
Returns:
the Content-Type

getContentType

public static java.lang.String getContentType(java.util.Properties outputProperties)
Get Content-Type (Internet Media Type, MIME type) with character encoding as "charset" parameter from an JAXP/TrAX OutputProperties object.

Parameters:
outputProperties - JAXP/TrAX OutputProperties object.
Returns:
the Content-Type
See Also:
OutputKeys

executePage

public void executePage(LSPPage thePage,
                        java.util.Map<java.lang.String,java.lang.Object> lspParams,
                        java.lang.Object extContext,
                        javax.xml.transform.stream.StreamResult out)
                 throws java.io.FileNotFoundException,
                        org.xml.sax.SAXException,
                        java.io.IOException
Executes an LSP page and serialize the result to an StreamResult. Uses any stylesheet specified in the LSP page.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
extContext - external context which will be passed to ExtLibs
out - the StreamResult
Throws:
java.io.FileNotFoundException - if the stylesheet cannot be found
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.IOException - if any I/O error occurs while executing the page

executePage

public void executePage(LSPPage thePage,
                        java.util.Map<java.lang.String,java.lang.Object> lspParams,
                        java.lang.Object extContext,
                        java.io.OutputStream out)
                 throws java.io.FileNotFoundException,
                        org.xml.sax.SAXException,
                        java.io.IOException
Executes an LSP page and serialize the result to an OutputStream. Uses any stylesheet specified in the LSP page.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
extContext - external context which will be passed to ExtLibs
out - the OutputStream
Throws:
java.io.FileNotFoundException - if the stylesheet cannot be found
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.IOException - if any I/O error occurs while executing the page

executePage

public java.lang.String executePage(LSPPage thePage,
                                    java.util.Map<java.lang.String,java.lang.Object> lspParams,
                                    java.lang.Object extContext)
                             throws java.io.FileNotFoundException,
                                    org.xml.sax.SAXException,
                                    java.io.IOException
Executes an LSP page and serialize the result to a String Uses any stylesheet specified in the LSP page.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
extContext - external context which will be passed to ExtLibs
Returns:
the result of the LSP execution
Throws:
java.io.FileNotFoundException - if the stylesheet cannot be found
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.IOException - if any I/O error occurs while executing the page

executePage

public void executePage(LSPPage thePage,
                        java.util.Map<java.lang.String,java.lang.Object> lspParams,
                        java.lang.Object extContext,
                        javax.xml.transform.Templates compiledStylesheet,
                        javax.xml.transform.stream.StreamResult out)
                 throws org.xml.sax.SAXException,
                        java.io.IOException
Executes an LSP page, transform the the result with an XSLT stylesheet and serialize the result to an StreamResult

The output properties specified in the stylesheet will be used, and those specified in the LSP page will be ignored. Also, the default output properties specified in this class will be ignored. Make sure to specify the output method in the stylesheet using <xsl:output>.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
extContext - external context which will be passed to ExtLibs
compiledStylesheet - the compiled XSLT stylesheet
out - the StreamResult
Throws:
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.IOException - if any I/O error occurs while executing the page

executePage

public void executePage(LSPPage thePage,
                        java.util.Map<java.lang.String,java.lang.Object> lspParams,
                        java.lang.Object extContext,
                        javax.xml.transform.Templates compiledStylesheet,
                        java.io.OutputStream out)
                 throws org.xml.sax.SAXException,
                        java.io.IOException
Executes an LSP page, transform the the result with an XSLT stylesheet and serialize the result to an OutputStream

The output properties specified in the stylesheet will be used, and those specified in the LSP page will be ignored. Also, the default output properties specified in this class will be ignored. Make sure to specify the output method in the stylesheet using <xsl:output>.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
extContext - external context which will be passed to ExtLibs
compiledStylesheet - the compiled XSLT stylesheet
out - the OutputStream
Throws:
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.IOException - if any I/O error occurs while executing the page

executePage

public java.lang.String executePage(LSPPage thePage,
                                    java.util.Map<java.lang.String,java.lang.Object> lspParams,
                                    java.lang.Object extContext,
                                    javax.xml.transform.Templates compiledStylesheet)
                             throws org.xml.sax.SAXException,
                                    java.io.IOException
Executes an LSP page, transform the the result with an XSLT stylesheet and serialize the result to a String.

The output properties specified in the stylesheet will be used, and those specified in the LSP page will be ignored. Also, the default output properties specified in this class will be ignored. Make sure to specify the output method in the stylesheet using <xsl:output>.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
extContext - external context which will be passed to ExtLibs
compiledStylesheet - the compiled XSLT stylesheet
Returns:
the result of the LSP execution
Throws:
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.IOException - if any I/O error occurs while executing the page