org.apache.tomcat.core
Class Context

java.lang.Object
  |
  +--org.apache.tomcat.core.Context

public class Context
extends java.lang.Object

Context represent a Web Application as specified by Servlet Specs. The implementation is a repository for all the properties defined in web.xml and tomcat specific properties.

Author:
James Duncan Davidson [duncan@eng.sun.com], James Todd [gonzo@eng.sun.com], Jason Hunter [jch@eng.sun.com], Harish Prabandham, costin@dnt.ro, Gal Shachor shachor@il.ibm.com

Constructor Summary
Context()
           
 
Method Summary
 void addContentType(java.lang.String ext, java.lang.String type)
           
 void addContextInterceptor(ContextInterceptor ci)
          Deprecated.  
 void addEnvEntry(java.lang.String name, java.lang.String type, java.lang.String value, java.lang.String description)
          Add Env-entry to this context
 void addErrorPage(java.lang.String errorType, java.lang.String value)
           
 void addHostAlias(java.lang.String alias)
          Virtual host support - this context will be part of a virtual host with the specified name.
 void addInitParameter(java.lang.String name, java.lang.String value)
           
 void addRequestInterceptor(RequestInterceptor ci)
          Deprecated.  
 void addSecurityConstraint(java.lang.String[] path, java.lang.String[] methods, java.lang.String[] roles, java.lang.String transport)
          Will add a new security constraint: For all paths: if( match(path) && match(method) && match( transport ) ) then require("roles") This is equivalent with adding a Container with the path, method and transport.
 void addServlet(ServletWrapper wrapper)
          Add a servlet with the given name to the container.
 ServletWrapper addServlet(java.lang.String name, java.lang.String classN)
           
 void addServletMapping(java.lang.String path, java.lang.String servletName)
          Maps a named servlet to a particular path or extension.
 void addTaglib(java.lang.String uri, java.lang.String location)
          Add a taglib declaration for this context
 void addWelcomeFile(java.lang.String s)
           
 boolean allowAttribute(java.lang.String name)
           
 void expectUserWelcomeFiles()
          If any new welcome file is added, remove the old list of welcome files and start a new one.
 java.lang.String getAbsolutePath()
          Return the absolute path for the docBase, if we are file-system based, null otherwise.
 java.lang.Object getAttribute(java.lang.String name)
           
 java.util.Enumeration getAttributeNames()
           
 java.lang.String getAuthMethod()
          Authentication method, if any specified
 Container getContainer()
           
 Container getContainer(java.lang.String path)
           
 java.util.Enumeration getContainerLocations()
           
 java.util.Enumeration getContainers()
           
 Context getContext(java.lang.String path)
           
 ContextInterceptor[] getContextInterceptors()
          Deprecated.  
 ContextManager getContextManager()
           
 int getDebug()
           
 java.lang.String getDescription()
           
 java.lang.String getDocBase()
           
 java.net.URL getDocumentBase()
          Deprecated. - use getDocBase and URLUtil if you need it as URL NOT USED INSIDE TOMCAT - ONLY IN OLD J2EE CONNECTORS !
 java.lang.String getEngineHeader()
          Deprecated.  
 java.util.Enumeration getEnvEntries()
           
 java.lang.String getEnvEntryType(java.lang.String name)
           
 java.lang.String getEnvEntryValue(java.lang.String name)
           
 java.lang.String getErrorPage(int errorCode)
           
 java.lang.String getErrorPage(java.lang.String errorCode)
           
 javax.servlet.ServletContext getFacade()
          Every context is associated with a facade
 FacadeManager getFacadeManager()
           
 java.lang.String getFormErrorPage()
           
 java.lang.String getFormLoginPage()
           
 java.lang.String getHost()
          Return the virtual host name, or null if we are in the default context
 java.util.Enumeration getHostAliases()
           
 java.lang.String getInitParameter(java.lang.String name)
           
 java.util.Enumeration getInitParameterNames()
           
 java.net.FileNameMap getMimeMap()
           
 java.lang.String getPath()
          Base URL for this context
 java.lang.Object getPermissions()
          Get the SecurityManager Permissions for this Context.
 java.lang.Object getProtectionDomain()
           
 java.lang.String getRealmName()
          Realm to be used
 java.lang.String getRealPath(java.lang.String path)
          According to Servlet 2.2 the real path is interpreted as relative to the current web app and _cannot_ go outside the box.
 boolean getReloadable()
          Should we reload servlets ?
 RequestInterceptor[] getRequestInterceptors()
          Deprecated.  
 java.net.URL getResource(java.lang.String rpath)
          Implements getResource() See getRealPath(), it have to be local to the current Context - and can't go to a sub-context.
 ServletWrapper getServletByName(java.lang.String servletName)
           
 ServletLoader getServletLoader()
           
 java.util.Enumeration getServletNames()
           
 int getSessionTimeOut()
           
 java.lang.String getTaglibLocation(java.lang.String uri)
           
 java.util.Enumeration getTaglibs()
           
 java.io.File getWARDir()
          Deprecated.  
 java.util.Enumeration getWelcomeFiles()
           
 java.io.File getWorkDir()
          Deprecated.  
 boolean isDistributable()
           
 boolean isInvokerEnabled()
          Deprecated.  
 boolean isTrusted()
           
 boolean isWARExpanded()
          Deprecated.  
 boolean isWARValidated()
          Deprecated.  
 boolean isWorkDirPersistent()
          Deprecated.  
 void log(java.lang.String msg)
          Internal log method
 void log(java.lang.String msg, java.lang.Throwable t)
          Internal log method
 void log(java.lang.String msg, java.lang.Throwable t, int level)
          Internal log method
 void logServlet(java.lang.String msg, java.lang.Throwable t)
          User-level log method ( called from a servlet)
 void removeAttribute(java.lang.String name)
           
 void removeContainer(Container ct)
           
 void removeServletByName(java.lang.String servletName)
          Remove the servlet with a specific name
 void removeWelcomeFiles()
          Deprecated. It is used as a hack to allow web.xml override default welcome files. Tomcat will first load the "default" web.xml and then this file.
 void setAttribute(java.lang.String name, java.lang.Object object)
           
 void setContextManager(ContextManager cm)
           
 void setDebug(int level)
           
 void setDebug(java.lang.String level)
           
 void setDescription(java.lang.String description)
           
 void setDistributable(boolean isDistributable)
           
 void setDistributable(java.lang.String s)
           
 void setDocBase(java.lang.String docB)
          DocBase points to the web application files.
 void setDocumentBase(java.net.URL s)
          Deprecated. - use setDocBase
 void setEngineHeader(java.lang.String s)
          Deprecated.  
 void setFormErrorPage(java.lang.String page)
           
 void setFormLoginPage(java.lang.String page)
           
 void setHost(java.lang.String h)
          Make this context visible as part of a virtual host
 void setIcon(java.lang.String icon)
           
 void setInitParameter(java.lang.String name, java.lang.String value)
          Deprecated. use addInitParameter
 void setInvokerEnabled(boolean isInvokerEnabled)
          Deprecated.  
 void setIsWARExpanded(boolean isWARExpanded)
          Deprecated.  
 void setIsWARValidated(boolean isWARValidated)
          Deprecated.  
 void setLoginConfig(java.lang.String authMethod, java.lang.String realmName, java.lang.String formLoginPage, java.lang.String formErrorPage)
           
 void setPath(java.lang.String path)
          Base URL for this context
 void setPermissions(java.lang.Object o)
           
 void setProtectionDomain(java.lang.Object o)
           
 void setReloadable(boolean b)
           
 void setReloadable(java.lang.String s)
           
 void setServletLoader(ServletLoader loader)
           
 void setSessionTimeOut(int sessionTimeOut)
           
 void setTrusted(boolean t)
           
 void setWARDir(java.io.File f)
          Deprecated.  
 void setWorkDir(java.io.File workDir)
          Deprecated.  
 void setWorkDirPath(java.lang.String workDir)
          Deprecated.  
 void setWorkDirPersistent(boolean b)
          Deprecated.  
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Context

public Context()
Method Detail

getFacade

public javax.servlet.ServletContext getFacade()
Every context is associated with a facade

getContextManager

public ContextManager getContextManager()

setContextManager

public void setContextManager(ContextManager cm)

getFacadeManager

public FacadeManager getFacadeManager()

getPath

public java.lang.String getPath()
Base URL for this context

setPath

public void setPath(java.lang.String path)
Base URL for this context

setDocBase

public void setDocBase(java.lang.String docB)
DocBase points to the web application files. There is no restriction on the syntax and content of DocBase, it's up to the various modules to interpret this and use it. For example, to serve from a war file you can use war: protocol, and set up War interceptors. "Basic" tomcat treats it as a file ( either absolute or relative to the CM home ). If docBase is relative assume it is relative to the context manager home.

getDocBase

public java.lang.String getDocBase()

getAbsolutePath

public java.lang.String getAbsolutePath()
Return the absolute path for the docBase, if we are file-system based, null otherwise.

setReloadable

public void setReloadable(java.lang.String s)

setReloadable

public void setReloadable(boolean b)

getReloadable

public boolean getReloadable()
Should we reload servlets ?

getWelcomeFiles

public java.util.Enumeration getWelcomeFiles()

removeWelcomeFiles

public void removeWelcomeFiles()
Deprecated. It is used as a hack to allow web.xml override default welcome files. Tomcat will first load the "default" web.xml and then this file.


expectUserWelcomeFiles

public void expectUserWelcomeFiles()
If any new welcome file is added, remove the old list of welcome files and start a new one. This is used as a hack to allow a default web.xml file to specifiy welcome files. We should use a better mechanism!

addWelcomeFile

public void addWelcomeFile(java.lang.String s)

addTaglib

public void addTaglib(java.lang.String uri,
                      java.lang.String location)
Add a taglib declaration for this context

getTaglibLocation

public java.lang.String getTaglibLocation(java.lang.String uri)

getTaglibs

public java.util.Enumeration getTaglibs()

addEnvEntry

public void addEnvEntry(java.lang.String name,
                        java.lang.String type,
                        java.lang.String value,
                        java.lang.String description)
Add Env-entry to this context

getEnvEntryType

public java.lang.String getEnvEntryType(java.lang.String name)

getEnvEntryValue

public java.lang.String getEnvEntryValue(java.lang.String name)

getEnvEntries

public java.util.Enumeration getEnvEntries()

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)

setInitParameter

public void setInitParameter(java.lang.String name,
                             java.lang.String value)
Deprecated. use addInitParameter


addInitParameter

public void addInitParameter(java.lang.String name,
                             java.lang.String value)

getInitParameterNames

public java.util.Enumeration getInitParameterNames()

getAttribute

public java.lang.Object getAttribute(java.lang.String name)

getAttributeNames

public java.util.Enumeration getAttributeNames()

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object object)

removeAttribute

public void removeAttribute(java.lang.String name)

getDescription

public java.lang.String getDescription()

setDescription

public void setDescription(java.lang.String description)

setIcon

public void setIcon(java.lang.String icon)

isDistributable

public boolean isDistributable()

setDistributable

public void setDistributable(boolean isDistributable)

setDistributable

public void setDistributable(java.lang.String s)

getSessionTimeOut

public int getSessionTimeOut()

setSessionTimeOut

public void setSessionTimeOut(int sessionTimeOut)

getMimeMap

public java.net.FileNameMap getMimeMap()

addContentType

public void addContentType(java.lang.String ext,
                           java.lang.String type)

getErrorPage

public java.lang.String getErrorPage(int errorCode)

addErrorPage

public void addErrorPage(java.lang.String errorType,
                         java.lang.String value)

getErrorPage

public java.lang.String getErrorPage(java.lang.String errorCode)

getAuthMethod

public java.lang.String getAuthMethod()
Authentication method, if any specified

getRealmName

public java.lang.String getRealmName()
Realm to be used

getFormLoginPage

public java.lang.String getFormLoginPage()

getFormErrorPage

public java.lang.String getFormErrorPage()

setFormLoginPage

public void setFormLoginPage(java.lang.String page)

setFormErrorPage

public void setFormErrorPage(java.lang.String page)

setLoginConfig

public void setLoginConfig(java.lang.String authMethod,
                           java.lang.String realmName,
                           java.lang.String formLoginPage,
                           java.lang.String formErrorPage)

addServletMapping

public void addServletMapping(java.lang.String path,
                              java.lang.String servletName)
                       throws TomcatException
Maps a named servlet to a particular path or extension. If the named servlet is unregistered, it will be added and subsequently mapped. Note that the order of resolution to handle a request is: exact mapped servlet (eg /catalog) prefix mapped servlets (eg /foo/bar/*) extension mapped servlets (eg *jsp) default servlet

addSecurityConstraint

public void addSecurityConstraint(java.lang.String[] path,
                                  java.lang.String[] methods,
                                  java.lang.String[] roles,
                                  java.lang.String transport)
                           throws TomcatException
Will add a new security constraint: For all paths: if( match(path) && match(method) && match( transport ) ) then require("roles") This is equivalent with adding a Container with the path, method and transport. If the container will be matched, the request will have to pass the security constraints.

getContainers

public java.util.Enumeration getContainers()

getContainerLocations

public java.util.Enumeration getContainerLocations()

getContainer

public Container getContainer(java.lang.String path)

getContainer

public Container getContainer()

removeContainer

public void removeContainer(Container ct)

removeServletByName

public void removeServletByName(java.lang.String servletName)
                         throws TomcatException
Remove the servlet with a specific name

getServletByName

public ServletWrapper getServletByName(java.lang.String servletName)

addServlet

public void addServlet(ServletWrapper wrapper)
                throws TomcatException
Add a servlet with the given name to the container. The servlet will be loaded by the container's class loader and instantiated using the given class name. Called to add a new servlet from web.xml

addServlet

public ServletWrapper addServlet(java.lang.String name,
                                 java.lang.String classN)
                          throws TomcatException

getServletNames

public java.util.Enumeration getServletNames()

setServletLoader

public void setServletLoader(ServletLoader loader)

getServletLoader

public ServletLoader getServletLoader()

setDebug

public void setDebug(int level)

setDebug

public void setDebug(java.lang.String level)

getDebug

public int getDebug()

log

public final void log(java.lang.String msg)
Internal log method

log

public void log(java.lang.String msg,
                java.lang.Throwable t)
Internal log method

log

public void log(java.lang.String msg,
                java.lang.Throwable t,
                int level)
Internal log method

logServlet

public void logServlet(java.lang.String msg,
                       java.lang.Throwable t)
User-level log method ( called from a servlet)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getContext

public Context getContext(java.lang.String path)

getResource

public java.net.URL getResource(java.lang.String rpath)
                         throws java.net.MalformedURLException
Implements getResource() See getRealPath(), it have to be local to the current Context - and can't go to a sub-context. That means we don't need any overhead.

getRealPath

public java.lang.String getRealPath(java.lang.String path)
According to Servlet 2.2 the real path is interpreted as relative to the current web app and _cannot_ go outside the box. If your intention is different or want the "other" behavior you'll have to first call getContext(path) and call getRealPath() on the result context ( if any - the server may disable that from security reasons !). XXX find out how can we find the context path in order to remove it from the path - that's the only way a user can do that unless he have prior knowledge of the mappings !

isInvokerEnabled

public boolean isInvokerEnabled()
Deprecated.  


setInvokerEnabled

public void setInvokerEnabled(boolean isInvokerEnabled)
Deprecated.  


isWorkDirPersistent

public boolean isWorkDirPersistent()
Deprecated.  


setWorkDirPersistent

public void setWorkDirPersistent(boolean b)
Deprecated.  


getWorkDir

public java.io.File getWorkDir()
Deprecated.  


setWorkDir

public void setWorkDir(java.io.File workDir)
Deprecated.  


setWorkDirPath

public void setWorkDirPath(java.lang.String workDir)
Deprecated.  

Set work dir using a String property

getEngineHeader

public java.lang.String getEngineHeader()
Deprecated.  


setEngineHeader

public void setEngineHeader(java.lang.String s)
Deprecated.  


getWARDir

public java.io.File getWARDir()
Deprecated.  


setWARDir

public void setWARDir(java.io.File f)
Deprecated.  


isWARExpanded

public boolean isWARExpanded()
Deprecated.  


setIsWARExpanded

public void setIsWARExpanded(boolean isWARExpanded)
Deprecated.  


isWARValidated

public boolean isWARValidated()
Deprecated.  


setIsWARValidated

public void setIsWARValidated(boolean isWARValidated)
Deprecated.  


addContextInterceptor

public void addContextInterceptor(ContextInterceptor ci)
Deprecated.  


getContextInterceptors

public ContextInterceptor[] getContextInterceptors()
Deprecated.  


addRequestInterceptor

public void addRequestInterceptor(RequestInterceptor ci)
Deprecated.  


getRequestInterceptors

public RequestInterceptor[] getRequestInterceptors()
Deprecated.  


getPermissions

public java.lang.Object getPermissions()
Get the SecurityManager Permissions for this Context.

setPermissions

public void setPermissions(java.lang.Object o)

getProtectionDomain

public java.lang.Object getProtectionDomain()

setProtectionDomain

public void setProtectionDomain(java.lang.Object o)

getDocumentBase

public java.net.URL getDocumentBase()
Deprecated. - use getDocBase and URLUtil if you need it as URL NOT USED INSIDE TOMCAT - ONLY IN OLD J2EE CONNECTORS !


setDocumentBase

public void setDocumentBase(java.net.URL s)
Deprecated. - use setDocBase


setHost

public void setHost(java.lang.String h)
Make this context visible as part of a virtual host

getHost

public java.lang.String getHost()
Return the virtual host name, or null if we are in the default context

addHostAlias

public void addHostAlias(java.lang.String alias)
Virtual host support - this context will be part of a virtual host with the specified name. You should set all the aliases. XXX Not implemented

getHostAliases

public java.util.Enumeration getHostAliases()

setTrusted

public void setTrusted(boolean t)

isTrusted

public boolean isTrusted()

allowAttribute

public boolean allowAttribute(java.lang.String name)


Copyright © 2000 Apache Software Foundation. All Rights Reserved.