org.enhydra.xml.xmlc.servlet
Class XMLCContext

java.lang.Object
  |
  +--org.enhydra.xml.xmlc.servlet.XMLCContext

public class XMLCContext
extends Object

Class to facility the use of XMLC in a HTTP servlet. This object contains a XMLC factory to create instances of XMLC document classes and methods to output documents.

An instance of this object is associated with the ServletContext object for an application (one per WebApp). The object is created on first use by getContext. It provides a factory for creating XMLC document class with optional automatic reloading of out of date classes or recompilation and reloading of classes out-of-date relative to a source file. Also provided are methods to output a XMLC document as a HTTP response, with automatic setting of response content type.

Instance of this class are configured using the following Servlet context-wide init parameters:

See Also:
ServletContext

Inner Class Summary
static class XMLCContext.SessionURLEncodingMode
          Enumerated constant indicating how URL session encoding is to be handled.
 
Field Summary
static String CONTEXT_ATTRIBUTE
          Name of ServletContext attribute that contains the instance of this class for a WebApp.
static XMLCContext.SessionURLEncodingMode URL_ENCODING_ALWAYS
          Value indicating that URL session encoding should always be used.
static XMLCContext.SessionURLEncodingMode URL_ENCODING_AUTO
          Value indicating that URL session encoding should be detected automatically based on if it was used for the current requested.
static XMLCContext.SessionURLEncodingMode URL_ENCODING_NEVER
          Value indicating that URL session encoding should never be used.
(package private) static int XMLC_COMPRESS_GZIP
           
(package private) static int XMLC_COMPRESS_NONE
          Definition of xmlcCompression parameter values as a bit set.
 
Constructor Summary
XMLCContext(javax.servlet.ServletContext servletContext, XMLCFactory factory, XMLCContext.SessionURLEncodingMode sessionURLEncodingMode, boolean logStats, int compressionType)
          Constructor.
 
Method Summary
 OutputOptions createOutputOptions(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, XMLObject document)
          Create an OutputOptions object for a document.
static XMLCContext getContext(javax.servlet.http.HttpServlet servlet)
          Obtain the XMLCContext for the current application, creating it if it doesn't exist.
static XMLCContext getContext(javax.servlet.ServletContext servletContext)
          Obtain the XMLCContext for the current application, creating it if it doesn't exist.
protected  javax.servlet.ServletContext getServletContext()
          Get the associated servlet context
 XMLCContext.SessionURLEncodingMode getSessionURLEncoding()
           
 XMLCFactory getXMLCFactory()
          Get the XMLC factory object associated with the context.
 void setSessionURLEncoding(XMLCContext.SessionURLEncodingMode mode)
          Set the session URL encoding mode.
protected  URLRewriter setupURLRewriter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Setup the session URL encoder as required by configuration and request.
 void setXMLCFactory(XMLCFactory factory)
          Explictly set XMLC factory.
protected  boolean shouldEncodeSessionId(javax.servlet.http.HttpServletRequest request)
          Determine if a session id should be encoded URLs.
 void writeDOM(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, OutputOptions outputOptions, XMLObject document)
          Output an an XMLC document object (DOM).
 void writeDOM(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, XMLObject document)
          Output an an XMLC document object (DOM).
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_ENCODING_AUTO

public static final XMLCContext.SessionURLEncodingMode URL_ENCODING_AUTO
Value indicating that URL session encoding should be detected automatically based on if it was used for the current requested.

URL_ENCODING_ALWAYS

public static final XMLCContext.SessionURLEncodingMode URL_ENCODING_ALWAYS
Value indicating that URL session encoding should always be used.

URL_ENCODING_NEVER

public static final XMLCContext.SessionURLEncodingMode URL_ENCODING_NEVER
Value indicating that URL session encoding should never be used.

CONTEXT_ATTRIBUTE

public static final String CONTEXT_ATTRIBUTE
Name of ServletContext attribute that contains the instance of this class for a WebApp.

XMLC_COMPRESS_NONE

static final int XMLC_COMPRESS_NONE
Definition of xmlcCompression parameter values as a bit set.

XMLC_COMPRESS_GZIP

static final int XMLC_COMPRESS_GZIP
Constructor Detail

XMLCContext

public XMLCContext(javax.servlet.ServletContext servletContext,
                   XMLCFactory factory,
                   XMLCContext.SessionURLEncodingMode sessionURLEncodingMode,
                   boolean logStats,
                   int compressionType)
Constructor. Must be public because it is accessed via reflection, but instances should only be created through getContext.
Method Detail

getXMLCFactory

public XMLCFactory getXMLCFactory()
Get the XMLC factory object associated with the context.

setXMLCFactory

public void setXMLCFactory(XMLCFactory factory)
Explictly set XMLC factory. The XMLC factory is normally defined base on the servlet configuration parameters. This allows the user to overide the standard factories.

setSessionURLEncoding

public void setSessionURLEncoding(XMLCContext.SessionURLEncodingMode mode)
Set the session URL encoding mode. This option is normally set from the servlet configuration parameters. This allows the explicit setting of this option.
Parameters:
mode - Constant indicating what mode to use
See Also:
XMLCContext.SessionURLEncodingMode

getSessionURLEncoding

public XMLCContext.SessionURLEncodingMode getSessionURLEncoding()

shouldEncodeSessionId

protected boolean shouldEncodeSessionId(javax.servlet.http.HttpServletRequest request)
Determine if a session id should be encoded URLs.

setupURLRewriter

protected URLRewriter setupURLRewriter(javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response)
Setup the session URL encoder as required by configuration and request.

createOutputOptions

public OutputOptions createOutputOptions(javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpServletResponse response,
                                         XMLObject document)
Create an OutputOptions object for a document. Options are defaulted for the specified document. The object maybe then modified as needed to override the default values.

The following attributes are set in the object:

Parameters:
request - The servlet request object. The request is required to determine if URL encoding should be done on the document.
response - The servlet response object. The response is required to set up the URL encoder.
document - The DOM object to be returned as response.

writeDOM

public void writeDOM(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response,
                     OutputOptions outputOptions,
                     XMLObject document)
              throws IOException
Output an an XMLC document object (DOM). The document is formatted according to it's type. The MIME type of the response is automatically set.
Parameters:
request - The servlet request object. The request is required to determine if URL encoding should be done on the document.
response - The servlet response object. The Content-Type and Content-Length will be set from the document..
outputFormat - Object use to specify options controlling the formatting of the document.
document - The DOM object to be returned as response.

writeDOM

public void writeDOM(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response,
                     XMLObject document)
              throws IOException
Output an an XMLC document object (DOM). The document is formatted according to it's type. The MIME type of the response is automatically set.
Parameters:
request - The servlet request object. The request is required to determine if URL encoding should be done on the document.
response - The servlet response object. The Content-Type and Content-Length will be set from the document..
document - The DOM object to be returned as response.

getContext

public static XMLCContext getContext(javax.servlet.http.HttpServlet servlet)
Obtain the XMLCContext for the current application, creating it if it doesn't exist.
Parameters:
servlet - A servlet in the application. Used to obtain the servlet context.
Returns:
The XMLC context object for the application.
See Also:
getContext(ServletContext)

getContext

public static XMLCContext getContext(javax.servlet.ServletContext servletContext)
Obtain the XMLCContext for the current application, creating it if it doesn't exist.
Parameters:
servletContext - The servlet context of this application.
Returns:
The XMLC context object for the application.

getServletContext

protected javax.servlet.ServletContext getServletContext()
Get the associated servlet context


Copyright © 1999-2002 enhydra.org (Mark Diekhans, David Li, Richard Kunze). All Rights reserved.