com.guiseframework.platform.web
Class HTTPServletGuiseContainer

java.lang.Object
  extended by com.guiseframework.AbstractGuiseContainer
      extended by com.guiseframework.platform.web.HTTPServletGuiseContainer
All Implemented Interfaces:
GuiseContainer

public class HTTPServletGuiseContainer
extends AbstractGuiseContainer

A Guise container for Guise HTTP servlets. There will be one servlet Guise container per ServletContext, which usually corresponds to a single web application on a JVM.

Author:
Garret Wilson

Nested Class Summary
protected static class HTTPServletGuiseContainer.GuiseApplicationHTTPSessionKey
          A key suitable for a hash map made up of a Guise application and an HTTP session.
 
Field Summary
static java.lang.String RESOURCES_DIRECTORY_PATH
          The absolute path, relative to the servlet context, of the resources directory.
 
Constructor Summary
HTTPServletGuiseContainer(java.net.URI baseURI, ServletContext servletContext)
          Servlet contains and container base URI constructor.
 
Method Summary
protected  java.lang.String getContextAbsoluteResourcePath(java.lang.String containerRelativeResourcePath)
          Determines the servlet context-relative absolute path of the given container-relative path.
static HTTPServletGuiseContainer getGuiseContainer(ServletContext servletContext, java.net.URI baseURI)
          Retrieves the Guise container associated with the given servlet context.
protected  GuiseSession getGuiseSession(GuiseApplication guiseApplication, HttpServletRequest httpRequest, HttpSession httpSession)
          Retrieves a Guise session for the given HTTP session.
 java.io.InputStream getInputStream(java.net.URI uri)
          Retrieves an input stream to the entity at the given URI.
protected  char[] getPassword(AbstractGuiseApplication application, java.security.Principal principal)
          Looks up the corresponding password for the given principal.
protected  java.security.Principal getPrincipal(AbstractGuiseApplication application, java.lang.String id)
          Looks up an application principal from the given ID.
protected  java.lang.String getRealm(AbstractGuiseApplication application, java.net.URI resourceURI)
          Determines the realm applicable for the resource indicated by the given URI.
protected  java.io.InputStream getResourceInputStream(java.lang.String resourcePath)
          Retrieves an input stream to the resource at the given path.
protected  ServletContext getServletContext()
           
protected  boolean hasResource(java.lang.String resourcePath)
          Determines if the container has a resource available stored at the given resource path.
protected  void installApplication(AbstractGuiseApplication application, java.net.URI baseURI, java.io.File homeDirectory, java.io.File logDirectory, java.io.File tempDirectory)
          Installs the given application at the given context path.
protected  boolean isAuthorized(AbstractGuiseApplication application, java.net.URI resourceURI, java.security.Principal principal, java.lang.String realm)
          Checks whether the given principal is authorized to access the resouce at the given application path.
protected  java.util.Set<GuiseSession> removeGuiseSessions(HttpSession httpSession)
          Removes the Guise sessions for the given HTTP session.
protected  void uninstallApplication(AbstractGuiseApplication application)
          Uninstalls the given application.
 
Methods inherited from class com.guiseframework.AbstractGuiseContainer
addGuiseSession, getBasePath, getBaseURI, removeGuiseSession, resolvePath, resolveURI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCES_DIRECTORY_PATH

public static final java.lang.String RESOURCES_DIRECTORY_PATH
The absolute path, relative to the servlet context, of the resources directory.

Constructor Detail

HTTPServletGuiseContainer

public HTTPServletGuiseContainer(java.net.URI baseURI,
                                 ServletContext servletContext)
Servlet contains and container base URI constructor.

Parameters:
baseURI - The base URI of the container, an absolute URI that ends with the base path, which ends with a slash ('/'), indicating the base path of the application base paths.
servletContext - The servlet context with which this container is associated.
Throws:
java.lang.NullPointerException - if the base URI and/or servlet context is null.
java.lang.IllegalArgumentException - if the base URI is not absolute or does not end with a slash ('/') character.
Method Detail

getGuiseContainer

public static HTTPServletGuiseContainer getGuiseContainer(ServletContext servletContext,
                                                          java.net.URI baseURI)
Retrieves the Guise container associated with the given servlet context. Because the Java Servlet architecture does not provide the context path to the servlet context, this method can only be called after the first request, which will provide the context path. If no Guise container is associated with the servlet context, one is created.

Parameters:
servletContext - The servlet context with which this container is associated.
baseURI - The base URI of the container, an absolute URI that ends with the base path, which ends with a slash ('/'), indicating the base path of the application base paths.
Returns:
The Guise container associated with the given servlet context.
Throws:
java.lang.NullPointerException - if the servlet context and/or base URI is null.
java.lang.IllegalArgumentException - if the base URI is not absolute or does not end with a slash ('/') character.

getServletContext

protected final ServletContext getServletContext()
Returns:
The servlet context with which this container is associated.

installApplication

protected void installApplication(AbstractGuiseApplication application,
                                  java.net.URI baseURI,
                                  java.io.File homeDirectory,
                                  java.io.File logDirectory,
                                  java.io.File tempDirectory)
                           throws java.io.IOException
Installs the given application at the given context path. This version is provided to expose the method to the servlet.

Overrides:
installApplication in class AbstractGuiseContainer
Parameters:
baseURI - The base URI at which the application is being installed.
homeDirectory - The home directory of the application.
logDirectory - The log directory of the application.
tempDirectory - The temporary directory of the application.
application - The application to install.
Throws:
java.lang.NullPointerException - if the application, base URI, home directory, log directory, and/or temprary directory is null.
java.lang.IllegalArgumentException - if the given base URI is not absolute or the path of which is not absolute or not a collection.
java.lang.IllegalStateException - if the application is already installed in some container.
java.lang.IllegalStateException - if there is already an application installed in this container at the given context path.
java.io.IOException - if there is an I/O error when installing the application.

uninstallApplication

protected void uninstallApplication(AbstractGuiseApplication application)
Uninstalls the given application. This version is provided to expose the method to the servlet.

Overrides:
uninstallApplication in class AbstractGuiseContainer
Parameters:
application - The application to uninstall.
Throws:
java.lang.NullPointerException - if the application is null.
java.lang.IllegalStateException - if the application is not installed in this container.

getGuiseSession

protected GuiseSession getGuiseSession(GuiseApplication guiseApplication,
                                       HttpServletRequest httpRequest,
                                       HttpSession httpSession)
Retrieves a Guise session for the given HTTP session. A Guise session will be created if none is currently associated with the given HTTP session. When a Guise session is first created, its locale will be updated to match the language, if any, accepted by the HTTP request. This method should only be called by HTTP Guise session manager.

Parameters:
guiseApplication - The Guise application that will own the Guise session.
httpRequest - The HTTP request with which the Guise session is associated.
httpSession - The HTTP session for which a Guise session should be retrieved.
Returns:
The Guise session associated with the provided HTTP session.
See Also:
HTTPServletGuiseSessionManager

removeGuiseSessions

protected java.util.Set<GuiseSession> removeGuiseSessions(HttpSession httpSession)
Removes the Guise sessions for the given HTTP session. This method can only be accessed by classes in the same package. This method should only be called by HTTP Guise session manager.

Parameters:
httpSession - The HTTP session which should be removed along with its corresponding Guise session.
Returns:
The set of Guise sessions previously associated with the HTTP session.
See Also:
HTTPServletGuiseSessionManager

hasResource

protected boolean hasResource(java.lang.String resourcePath)
Determines if the container has a resource available stored at the given resource path. The provided path is first normalized.

Specified by:
hasResource in class AbstractGuiseContainer
Parameters:
resourcePath - A container-relative path to a resource in the resource storage area.
Returns:
true if a resource exists at the given resource path.
Throws:
java.lang.IllegalArgumentException - if the given resource path is absolute.
java.lang.IllegalArgumentException - if the given path is not a valid path.

getResourceInputStream

protected java.io.InputStream getResourceInputStream(java.lang.String resourcePath)
Retrieves an input stream to the resource at the given path. The provided path is first normalized.

Specified by:
getResourceInputStream in class AbstractGuiseContainer
Parameters:
resourcePath - A container-relative path to a resource in the resource storage area.
Returns:
An input stream to the resource at the given resource path, or null if no resource exists at the given resource path.
Throws:
java.lang.IllegalArgumentException - if the given resource path is absolute.

getInputStream

public java.io.InputStream getInputStream(java.net.URI uri)
                                   throws java.io.IOException
Retrieves an input stream to the entity at the given URI. The URI is first resolved to the container base URI. This version loads local resources directly through the servlet context.

Specified by:
getInputStream in interface GuiseContainer
Overrides:
getInputStream in class AbstractGuiseContainer
Parameters:
uri - A URI to the entity; either absolute or relative to the container.
Returns:
An input stream to the entity at the given resource URI, or null if no entity exists at the given resource path.
Throws:
java.lang.NullPointerException - if the given URI is null.
java.io.IOException - if there was an error connecting to the entity at the given URI.
See Also:
AbstractGuiseContainer.getBaseURI()

getContextAbsoluteResourcePath

protected java.lang.String getContextAbsoluteResourcePath(java.lang.String containerRelativeResourcePath)
Determines the servlet context-relative absolute path of the given container-relative path. The provided path is first normalized.

Parameters:
containerRelativeResourcePath - A container-relative path to a resource in the resource storage area.
Returns:
The absolute path to the resource relative to the servlet context.
Throws:
java.lang.IllegalArgumentException - if the given resource path is absolute.

getPrincipal

protected java.security.Principal getPrincipal(AbstractGuiseApplication application,
                                               java.lang.String id)
Looks up an application principal from the given ID. This version is provided to allow package access.

Overrides:
getPrincipal in class AbstractGuiseContainer
Parameters:
application - The application for which a principal should be returned for the given ID.
id - The ID of the principal.
Returns:
The principal corresponding to the given ID, or null if no principal could be determined.

getPassword

protected char[] getPassword(AbstractGuiseApplication application,
                             java.security.Principal principal)
Looks up the corresponding password for the given principal. This version is provided to allow package access.

Overrides:
getPassword in class AbstractGuiseContainer
Parameters:
application - The application for which a password should e retrieved for the given principal.
principal - The principal for which a password should be returned.
Returns:
The password associated with the given principal, or null if no password is associated with the given principal.

getRealm

protected java.lang.String getRealm(AbstractGuiseApplication application,
                                    java.net.URI resourceURI)
Determines the realm applicable for the resource indicated by the given URI. This version is provided to allow package access.

Overrides:
getRealm in class AbstractGuiseContainer
Parameters:
application - The application for a realm should be returned for the given resouce URI.
resourceURI - The URI of the resource requested.
Returns:
The realm appropriate for the resource, or null if the given resource is not in a known realm.
See Also:
GuiseApplication.relativizeURI(URI)

isAuthorized

protected boolean isAuthorized(AbstractGuiseApplication application,
                               java.net.URI resourceURI,
                               java.security.Principal principal,
                               java.lang.String realm)
Checks whether the given principal is authorized to access the resouce at the given application path. This version is provided to allow package access.

Overrides:
isAuthorized in class AbstractGuiseContainer
Parameters:
application - The application for which a principal should be authorized for a given resouce URI.
resourceURI - The URI of the resource requested.
principal - The principal requesting authentication, or null if the principal is not known.
realm - The realm with which the resource is associated, or null if the realm is not known.
Returns:
true if the given principal is authorized to access the resource represented by the given resource URI.


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.