| Method from org.apache.catalina.core.ApplicationContext Detail: |
protected void clearAttributes() {
// Create list of attributes to be removed
ArrayList list = new ArrayList();
Iterator iter = attributes.keySet().iterator();
while (iter.hasNext()) {
list.add(iter.next());
}
// Remove application originated attributes
// (read only attributes will be left in place)
Iterator keys = list.iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
removeAttribute(key);
}
}
Clear all application-created attributes. |
public Object getAttribute(String name) {
return (attributes.get(name));
}
Return the value of the specified context attribute, if any;
otherwise return null. |
public Enumeration getAttributeNames() {
return new Enumerator(attributes.keySet(), true);
}
Return an enumeration of the names of the context attributes
associated with this context. |
protected StandardContext getContext() {
return this.context;
}
|
public ServletContext getContext(String uri) {
// Validate the format of the specified argument
if ((uri == null) || (!uri.startsWith("/")))
return (null);
Context child = null;
try {
Host host = (Host) context.getParent();
String mapuri = uri;
while (true) {
child = (Context) host.findChild(mapuri);
if (child != null)
break;
int slash = mapuri.lastIndexOf('/");
if (slash < 0)
break;
mapuri = mapuri.substring(0, slash);
}
} catch (Throwable t) {
return (null);
}
if (child == null)
return (null);
if (context.getCrossContext()) {
// If crossContext is enabled, can always return the context
return child.getServletContext();
} else if (child == context) {
// Can still return the current context
return context.getServletContext();
} else {
// Nothing to return
return (null);
}
}
Return a ServletContext object that corresponds to a
specified URI on the server. This method allows servlets to gain
access to the context for various parts of the server, and as needed
obtain RequestDispatcher objects or resources from the
context. The given path must be absolute (beginning with a "/"),
and is interpreted based on our virtual host's document root. |
public String getContextPath() {
return context.getPath();
}
Return the main path associated with this context. |
protected ServletContext getFacade() {
return (this.facade);
}
Return the facade associated with this ApplicationContext. |
public String getInitParameter(String name) {
mergeParameters();
return ((String) parameters.get(name));
}
Return the value of the specified initialization parameter, or
null if this parameter does not exist. |
public Enumeration getInitParameterNames() {
mergeParameters();
return (new Enumerator(parameters.keySet()));
}
Return the names of the context's initialization parameters, or an
empty enumeration if the context has no initialization parameters. |
public int getMajorVersion() {
return (Constants.MAJOR_VERSION);
}
Return the major version of the Java Servlet API that we implement. |
public String getMimeType(String file) {
if (file == null)
return (null);
int period = file.lastIndexOf(".");
if (period < 0)
return (null);
String extension = file.substring(period + 1);
if (extension.length() < 1)
return (null);
return (context.findMimeMapping(extension));
}
Return the MIME type of the specified file, or null if
the MIME type cannot be determined. |
public int getMinorVersion() {
return (Constants.MINOR_VERSION);
}
Return the minor version of the Java Servlet API that we implement. |
public RequestDispatcher getNamedDispatcher(String name) {
// Validate the name argument
if (name == null)
return (null);
// Create and return a corresponding request dispatcher
Wrapper wrapper = (Wrapper) context.findChild(name);
if (wrapper == null)
return (null);
return new ApplicationDispatcher(wrapper, null, null, null, null, name);
}
Return a RequestDispatcher object that acts as a
wrapper for the named servlet. |
protected Map getReadonlyAttributes() {
return this.readOnlyAttributes;
}
|
public String getRealPath(String path) {
if (!context.isFilesystemBased())
return null;
if (path == null) {
return null;
}
File file = new File(basePath, path);
return (file.getAbsolutePath());
}
Return the real path for a given virtual path, if possible; otherwise
return null. |
public RequestDispatcher getRequestDispatcher(String path) {
// Validate the path argument
if (path == null)
return (null);
if (!path.startsWith("/"))
throw new IllegalArgumentException
(sm.getString
("applicationContext.requestDispatcher.iae", path));
path = normalize(path);
if (path == null)
return (null);
// Use the thread local URI and mapping data
DispatchData dd = dispatchData.get();
if (dd == null) {
dd = new DispatchData();
dispatchData.set(dd);
}
MessageBytes uriMB = dd.uriMB;
uriMB.recycle();
// Get query string
String queryString = null;
int pos = path.indexOf('?");
if (pos >= 0) {
queryString = path.substring(pos + 1);
} else {
pos = path.length();
}
// Use the thread local mapping data
MappingData mappingData = dd.mappingData;
// Map the URI
CharChunk uriCC = uriMB.getCharChunk();
try {
uriCC.append(context.getPath(), 0, context.getPath().length());
/*
* Ignore any trailing path params (separated by ';') for mapping
* purposes
*/
int semicolon = path.indexOf(';");
if (pos >= 0 && semicolon > pos) {
semicolon = -1;
}
uriCC.append(path, 0, semicolon > 0 ? semicolon : pos);
context.getMapper().map(uriMB, mappingData);
if (mappingData.wrapper == null) {
return (null);
}
/*
* Append any trailing path params (separated by ';') that were
* ignored for mapping purposes, so that they're reflected in the
* RequestDispatcher's requestURI
*/
if (semicolon > 0) {
uriCC.append(path, semicolon, pos - semicolon);
}
} catch (Exception e) {
// Should never happen
log(sm.getString("applicationContext.mapping.error"), e);
return (null);
}
Wrapper wrapper = (Wrapper) mappingData.wrapper;
String wrapperPath = mappingData.wrapperPath.toString();
String pathInfo = mappingData.pathInfo.toString();
mappingData.recycle();
// Construct a RequestDispatcher to process this request
return new ApplicationDispatcher
(wrapper, uriCC.toString(), wrapperPath, pathInfo,
queryString, null);
}
Return a RequestDispatcher instance that acts as a
wrapper for the resource at the given path. The path must begin
with a "/" and is interpreted as relative to the current context root. |
public URL getResource(String path) throws MalformedURLException {
if (path == null || !path.startsWith("/")) {
throw new MalformedURLException(sm.getString("applicationContext.requestDispatcher.iae", path));
}
path = normalize(path);
if (path == null)
return (null);
String libPath = "/WEB-INF/lib/";
if ((path.startsWith(libPath)) && (path.endsWith(".jar"))) {
File jarFile = null;
if (context.isFilesystemBased()) {
jarFile = new File(basePath, path);
} else {
jarFile = new File(context.getWorkPath(), path);
}
if (jarFile.exists()) {
return jarFile.toURL();
} else {
return null;
}
} else {
DirContext resources = context.getResources();
if (resources != null) {
String fullPath = context.getName() + path;
String hostName = context.getParent().getName();
try {
resources.lookup(path);
return new URL
("jndi", "", 0, getJNDIUri(hostName, fullPath),
new DirContextURLStreamHandler(resources));
} catch (Exception e) {
// Ignore
}
}
}
return (null);
}
Return the URL to the resource that is mapped to a specified path.
The path must begin with a "/" and is interpreted as relative to the
current context root. |
public InputStream getResourceAsStream(String path) {
path = normalize(path);
if (path == null || !path.startsWith("/"))
return (null);
DirContext resources = context.getResources();
if (resources != null) {
try {
Object resource = resources.lookup(path);
if (resource instanceof Resource)
return (((Resource) resource).streamContent());
} catch (Exception e) {
}
}
return (null);
}
Return the requested resource as an InputStream. The
path must be specified according to the rules described under
getResource. If no such resource can be identified,
return null. |
public Set getResourcePaths(String path) {
// Validate the path argument
if (path == null) {
return null;
}
if (!path.startsWith("/")) {
throw new IllegalArgumentException
(sm.getString("applicationContext.resourcePaths.iae", path));
}
path = normalize(path);
if (path == null)
return (null);
DirContext resources = context.getResources();
if (resources != null) {
return (getResourcePathsInternal(resources, path));
}
return (null);
}
Return a Set containing the resource paths of resources member of the
specified collection. Each path will be a String starting with
a "/" character. The returned set is immutable. |
public DirContext getResources() {
// --------------------------------------------------------- Public Methods
return context.getResources();
}
Return the resources object that is mapped to a specified path.
The path must begin with a "/" and is interpreted as relative to the
current context root. |
public String getServerInfo() {
return (ServerInfo.getServerInfo());
}
Return the name and version of the servlet container. |
public Servlet getServlet(String name) {
return (null);
} Deprecated! As - of Java Servlet API 2.1, with no direct replacement.
|
public String getServletContextName() {
return (context.getDisplayName());
}
Return the display name of this web application. |
public Enumeration getServletNames() {
return (new Enumerator(empty));
} Deprecated! As - of Java Servlet API 2.1, with no direct replacement.
|
public Enumeration getServlets() {
return (new Enumerator(empty));
} Deprecated! As - of Java Servlet API 2.1, with no direct replacement.
|
public void log(String message) {
context.getLogger().info(message);
}
Writes the specified message to a servlet log file. |
public void log(Exception exception,
String message) {
context.getLogger().error(message, exception);
} Deprecated! As - of Java Servlet API 2.1, use
log(String, Throwable) instead
Writes the specified exception and message to a servlet log file. |
public void log(String message,
Throwable throwable) {
context.getLogger().error(message, throwable);
}
Writes the specified message and exception to a servlet log file. |
public void removeAttribute(String name) {
Object value = null;
boolean found = false;
// Remove the specified attribute
// Check for read only attribute
if (readOnlyAttributes.containsKey(name))
return;
found = attributes.containsKey(name);
if (found) {
value = attributes.get(name);
attributes.remove(name);
} else {
return;
}
// Notify interested application event listeners
Object listeners[] = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0))
return;
ServletContextAttributeEvent event =
new ServletContextAttributeEvent(context.getServletContext(),
name, value);
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletContextAttributeListener))
continue;
ServletContextAttributeListener listener =
(ServletContextAttributeListener) listeners[i];
try {
context.fireContainerEvent("beforeContextAttributeRemoved",
listener);
listener.attributeRemoved(event);
context.fireContainerEvent("afterContextAttributeRemoved",
listener);
} catch (Throwable t) {
context.fireContainerEvent("afterContextAttributeRemoved",
listener);
// FIXME - should we do anything besides log these?
log(sm.getString("applicationContext.attributeEvent"), t);
}
}
}
Remove the context attribute with the specified name, if any. |
public void setAttribute(String name,
Object value) {
// Name cannot be null
if (name == null)
throw new IllegalArgumentException
(sm.getString("applicationContext.setAttribute.namenull"));
// Null value is the same as removeAttribute()
if (value == null) {
removeAttribute(name);
return;
}
Object oldValue = null;
boolean replaced = false;
// Add or replace the specified attribute
// Check for read only attribute
if (readOnlyAttributes.containsKey(name))
return;
oldValue = attributes.get(name);
if (oldValue != null)
replaced = true;
attributes.put(name, value);
// Notify interested application event listeners
Object listeners[] = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0))
return;
ServletContextAttributeEvent event = null;
if (replaced)
event =
new ServletContextAttributeEvent(context.getServletContext(),
name, oldValue);
else
event =
new ServletContextAttributeEvent(context.getServletContext(),
name, value);
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletContextAttributeListener))
continue;
ServletContextAttributeListener listener =
(ServletContextAttributeListener) listeners[i];
try {
if (replaced) {
context.fireContainerEvent
("beforeContextAttributeReplaced", listener);
listener.attributeReplaced(event);
context.fireContainerEvent("afterContextAttributeReplaced",
listener);
} else {
context.fireContainerEvent("beforeContextAttributeAdded",
listener);
listener.attributeAdded(event);
context.fireContainerEvent("afterContextAttributeAdded",
listener);
}
} catch (Throwable t) {
if (replaced)
context.fireContainerEvent("afterContextAttributeReplaced",
listener);
else
context.fireContainerEvent("afterContextAttributeAdded",
listener);
// FIXME - should we do anything besides log these?
log(sm.getString("applicationContext.attributeEvent"), t);
}
}
}
Bind the specified value with the specified context attribute name,
replacing any existing value for that name. |
void setAttributeReadOnly(String name) {
if (attributes.containsKey(name))
readOnlyAttributes.put(name, name);
}
Set an attribute as read only. |