FileDocCategorySizeDatePackage
JspCServletContext.javaAPI DocGlassfish v2 API11240Fri May 04 22:32:58 BST 2007org.apache.jasper.servlet

JspCServletContext

public class JspCServletContext extends Object implements ServletContext
Simple ServletContext implementation without HTTP-specific methods.
author
Peter Rossbach (pr@webapp.de)

Fields Summary
protected Hashtable
myAttributes
Servlet context attributes.
protected PrintWriter
myLogWriter
The log writer we will write log messages to.
protected URL
myResourceBaseURL
The base URL (document root) for this context.
Constructors Summary
public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL)
Create a new instance of this ServletContext implementation.

param
aLogWriter PrintWriter which is used for log() calls
param
aResourceBaseURL Resource base URL


        myAttributes = new Hashtable();
        myLogWriter = aLogWriter;
        myResourceBaseURL = aResourceBaseURL;

    
Methods Summary
public java.lang.ObjectgetAttribute(java.lang.String name)
Return the specified context attribute, if any.

param
name Name of the requested attribute


        return (myAttributes.get(name));

    
public java.util.EnumerationgetAttributeNames()
Return an enumeration of context attribute names.


        return (myAttributes.keys());

    
public javax.servlet.ServletContextgetContext(java.lang.String uripath)
Return the servlet context for the specified path.

param
uripath Server-relative path starting with '/'


        return (null);

    
public java.lang.StringgetContextPath()
Returns the context path of the web application.

        return null;
    
public java.lang.StringgetInitParameter(java.lang.String name)
Return the specified context initialization parameter.

param
name Name of the requested parameter


        return (null);

    
public java.util.EnumerationgetInitParameterNames()
Return an enumeration of the names of context initialization parameters.


        return (new Vector().elements());

    
public intgetMajorVersion()
Return the Servlet API major version number.


        return (2);

    
public java.lang.StringgetMimeType(java.lang.String file)
Return the MIME type for the specified filename.

param
file Filename whose MIME type is requested


        return (null);

    
public intgetMinorVersion()
Return the Servlet API minor version number.


        return (3);

    
public javax.servlet.RequestDispatchergetNamedDispatcher(java.lang.String name)
Return a request dispatcher for the specified servlet name.

param
name Name of the requested servlet


        return (null);

    
public java.lang.StringgetRealPath(java.lang.String path)
Return the real path for the specified context-relative virtual path.

param
path The context-relative virtual path to resolve


        if (!myResourceBaseURL.getProtocol().equals("file"))
            return (null);
        if (!path.startsWith("/"))
            return (null);
        try {
            return
                (getResource(path).getFile().replace('/", File.separatorChar));
        } catch (Throwable t) {
            return (null);
        }

    
public javax.servlet.RequestDispatchergetRequestDispatcher(java.lang.String path)
Return a request dispatcher for the specified context-relative path.

param
path Context-relative path for which to acquire a dispatcher


        return (null);

    
public java.net.URLgetResource(java.lang.String path)
Return a URL object of a resource that is mapped to the specified context-relative path.

param
path Context-relative path of the desired resource
exception
MalformedURLException if the resource path is not properly formed


        if (!path.startsWith("/"))
            throw new MalformedURLException("Path '" + path +
                                            "' does not start with '/'");
        URL url = new URL(myResourceBaseURL, path.substring(1));
        InputStream is = null;
        try {
            is = url.openStream();
        } catch (Throwable t) {
            url = null;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Throwable t2) {
                    // Ignore
                }
            }
        }
        return url;
    
public java.io.InputStreamgetResourceAsStream(java.lang.String path)
Return an InputStream allowing access to the resource at the specified context-relative path.

param
path Context-relative path of the desired resource


        try {
            return (getResource(path).openStream());
        } catch (Throwable t) {
            return (null);
        }

    
public java.util.SetgetResourcePaths(java.lang.String path)
Return the set of resource paths for the "directory" at the specified context path.

param
path Context-relative base path


        Set thePaths = new HashSet();
        if (!path.endsWith("/"))
            path += "/";
        String basePath = getRealPath(path);
        if (basePath == null)
            return (thePaths);
        File theBaseDir = new File(basePath);
        if (!theBaseDir.exists() || !theBaseDir.isDirectory())
            return (thePaths);
        String theFiles[] = theBaseDir.list();
        for (int i = 0; i < theFiles.length; i++) {
            File testFile = new File(basePath + File.separator + theFiles[i]);
            if (testFile.isFile())
                thePaths.add(path + theFiles[i]);
            else if (testFile.isDirectory())
                thePaths.add(path + theFiles[i] + "/");
        }
        return (thePaths);

    
public java.lang.StringgetServerInfo()
Return descriptive information about this server.


        return ("JspCServletContext/1.0");

    
public javax.servlet.ServletgetServlet(java.lang.String name)
Return a null reference for the specified servlet name.

param
name Name of the requested servlet
deprecated
This method has been deprecated with no replacement


        return (null);

    
public java.lang.StringgetServletContextName()
Return the name of this servlet context.


        return (getServerInfo());

    
public java.util.EnumerationgetServletNames()
Return an empty enumeration of servlet names.

deprecated
This method has been deprecated with no replacement


        return (new Vector().elements());

    
public java.util.EnumerationgetServlets()
Return an empty enumeration of servlets.

deprecated
This method has been deprecated with no replacement


        return (new Vector().elements());

    
public voidlog(java.lang.String message)
Log the specified message.

param
message The message to be logged


        myLogWriter.println(message);

    
public voidlog(java.lang.Exception exception, java.lang.String message)
Log the specified message and exception.

param
exception The exception to be logged
param
message The message to be logged
deprecated
Use log(String,Throwable) instead


        log(message, exception);

    
public voidlog(java.lang.String message, java.lang.Throwable exception)
Log the specified message and exception.

param
message The message to be logged
param
exception The exception to be logged


        myLogWriter.println(message);
        exception.printStackTrace(myLogWriter);

    
public voidremoveAttribute(java.lang.String name)
Remove the specified context attribute.

param
name Name of the attribute to remove


        myAttributes.remove(name);

    
public voidsetAttribute(java.lang.String name, java.lang.Object value)
Set or replace the specified context attribute.

param
name Name of the context attribute to set
param
value Corresponding attribute value


        myAttributes.put(name, value);