nu.staldal.lsp.servlet
Class LSPManager

java.lang.Object
  extended by nu.staldal.lsp.servlet.LSPManager

public class LSPManager
extends java.lang.Object

Handle execution of LSP pages in a Servlet environment. This class is thread-safe. There is one instance of LSPManager per ServletContext, use getInstance(ServletContext) or getInstance(ServletContext, ClassLoader) to obtain it.


Field Summary
static java.lang.String LOCALE_KEY
          Use this key to store a user's locale in HttpSession.setAttribute(java.lang.String, java.lang.Object) to override the default use of ServletRequest.getLocales().
 
Method Summary
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Executes an LSP page and write the result to a HttpServletResponse.
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          Deprecated. use executePage(LSPPage,Map,HttpServletRequest,HttpServletResponse) instead
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.String stylesheetName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Executes an LSP page and transform the the result with an XSLT stylesheet.
 void executePage(LSPPage thePage, java.util.Map<java.lang.String,java.lang.Object> lspParams, java.lang.String stylesheetName, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          Deprecated. use executePage(LSPPage,Map,String,HttpServletRequest,HttpServletResponse) instead
 java.lang.ClassLoader getClassLoader()
          Get the ClassLoader used to load LSP pages and associated resources.
static LSPManager getInstance(javax.servlet.ServletContext context)
          Obtain the the LSPManager instance for the given ServletContext.
static LSPManager getInstance(javax.servlet.ServletContext context, java.lang.ClassLoader servletClassLoader)
          Obtain the the LSPManager instance for the given ServletContext.
 java.lang.String getLocalizedString(javax.servlet.http.HttpServletRequest request, java.lang.String key)
          Get a localized resource for the user's locale.
 java.lang.String getLocalizedString(javax.servlet.http.HttpServletRequest request, java.lang.String pageName, java.lang.String key)
          Get a localized resource for the user's locale.
 LSPHelper getLSPHelper()
          Obtain the underlaying LSPHelper.
 LSPPage getPage(java.lang.String pageName)
          Get the LSPPage instance for a given page name.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String pageName)
          Get a RequestDispatcher for a given page name.
 java.util.Locale getUserLocale(javax.servlet.http.HttpServletRequest request)
          Get the user's locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALE_KEY

public static final java.lang.String LOCALE_KEY
Use this key to store a user's locale in HttpSession.setAttribute(java.lang.String, java.lang.Object) to override the default use of ServletRequest.getLocales(). The value stored for this key must be of type Locale.

See Also:
Constant Field Values
Method Detail

getInstance

public static LSPManager getInstance(javax.servlet.ServletContext context)
Obtain the the LSPManager instance for the given ServletContext. Creates a new instance if nessecary.

Parameters:
context - the ServletContext
Returns:
the LSPManager instance for the given ServletContext

getInstance

public static LSPManager getInstance(javax.servlet.ServletContext context,
                                     java.lang.ClassLoader servletClassLoader)
Obtain the the LSPManager instance for the given ServletContext. Creates a new instance if nessecary.

Parameters:
context - the ServletContext
servletClassLoader - the ClassLoader used to load LSP pages, use getClass().getClassLoader() on the Servlet.
Returns:
the LSPManager instance for the given ServletContext

getLSPHelper

public LSPHelper getLSPHelper()
Obtain the underlaying LSPHelper.

Returns:
the LSPHelper

getPage

public LSPPage getPage(java.lang.String pageName)
Get the LSPPage instance for a given page name.

Parameters:
pageName - the name of the LSP page
Returns:
null if the given page name is not found

executePage

@Deprecated
public void executePage(LSPPage thePage,
                                   java.util.Map<java.lang.String,java.lang.Object> lspParams,
                                   javax.servlet.ServletRequest request,
                                   javax.servlet.ServletResponse response)
                 throws org.xml.sax.SAXException,
                        java.io.IOException
Deprecated. use executePage(LSPPage,Map,HttpServletRequest,HttpServletResponse) instead

Executes an LSP page and write the result to a HttpServletResponse. Uses any stylesheet specified in the LSP page.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
request - the HttpServletRequest
response - the HttpServletResponse
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,
                        javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response)
                 throws org.xml.sax.SAXException,
                        java.io.IOException
Executes an LSP page and write the result to a HttpServletResponse. Uses any stylesheet specified in the LSP page.

Parameters:
thePage - the LSP page
lspParams - parameters to the LSP page
request - the HttpServletRequest
response - the HttpServletResponse
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

@Deprecated
public void executePage(LSPPage thePage,
                                   java.util.Map<java.lang.String,java.lang.Object> lspParams,
                                   java.lang.String stylesheetName,
                                   javax.servlet.ServletRequest request,
                                   javax.servlet.ServletResponse response)
                 throws org.xml.sax.SAXException,
                        java.io.FileNotFoundException,
                        java.io.IOException,
                        javax.xml.transform.TransformerConfigurationException
Deprecated. use executePage(LSPPage,Map,String,HttpServletRequest,HttpServletResponse) instead

Executes an LSP page and transform the the result with an XSLT stylesheet.

The output properties specified in the stylesheet will be used, and those specified in the LSP page 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
stylesheetName - the XSLT stylesheet
request - the HttpServletRequest
response - the HttpServletResponse
Throws:
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.FileNotFoundException - if the stylesheet cannot be found
java.io.IOException - if any I/O error occurs while executing the page
javax.xml.transform.TransformerConfigurationException - if the stylesheet cannot be compiled

executePage

public void executePage(LSPPage thePage,
                        java.util.Map<java.lang.String,java.lang.Object> lspParams,
                        java.lang.String stylesheetName,
                        javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response)
                 throws org.xml.sax.SAXException,
                        java.io.FileNotFoundException,
                        java.io.IOException,
                        javax.xml.transform.TransformerConfigurationException
Executes an LSP page and transform the the result with an XSLT stylesheet.

The output properties specified in the stylesheet will be used, and those specified in the LSP page 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
stylesheetName - the XSLT stylesheet
request - the HttpServletRequest
response - the HttpServletResponse
Throws:
org.xml.sax.SAXException - if any error occurs while executing the page
java.io.FileNotFoundException - if the stylesheet cannot be found
java.io.IOException - if any I/O error occurs while executing the page
javax.xml.transform.TransformerConfigurationException - if the stylesheet cannot be compiled

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String pageName)
Get a RequestDispatcher for a given page name. The attributes in the ServletRequest object will be used as parameters to the LSP page.

Parameters:
pageName - the name of the LSP page
Returns:
null if the LSP page cannot be found

getClassLoader

public java.lang.ClassLoader getClassLoader()
Get the ClassLoader used to load LSP pages and associated resources.

Returns:
the ClassLoader used to load LSP pages and associated resources.

getLocalizedString

public java.lang.String getLocalizedString(javax.servlet.http.HttpServletRequest request,
                                           java.lang.String key)
                                    throws java.lang.Exception
Get a localized resource for the user's locale. Same as getLocalizedString(request, null, key)

Parameters:
request - the HttpServletRequest to determine the user's locale
key - the key
Returns:
null if not found.
Throws:
java.lang.Exception - if the LocaleBundleFactory throws any exception

getUserLocale

public java.util.Locale getUserLocale(javax.servlet.http.HttpServletRequest request)
Get the user's locale.

This method is used by the LSP ExtLib date and time formatting functions.

Parameters:
request - the HttpServletRequest to determine the user's locale
Returns:
the user's locale, never null

getLocalizedString

public java.lang.String getLocalizedString(javax.servlet.http.HttpServletRequest request,
                                           java.lang.String pageName,
                                           java.lang.String key)
                                    throws java.lang.Exception
Get a localized resource for the user's locale.

This method is used by the LSP ExtLib lang element and function.

Parameters:
request - the HttpServletRequest to determine the user's locale
pageName - LSP page name, or null for global resources only
key - the key
Returns:
null if not found.
Throws:
java.lang.Exception - if the LocaleBundleFactory throws any exception