org.apache.sling.maven.jspc
Class JspCServletContext

java.lang.Object
  extended by org.apache.sling.maven.jspc.JspCServletContext
All Implemented Interfaces:
javax.servlet.ServletContext

public class JspCServletContext
extends Object
implements javax.servlet.ServletContext

Simple ServletContext implementation without HTTP-specific methods.

This class has been copied from the JspCServletContext of the Jasper 5.5.20 distribution and reformated to match the formating rules of Sling. Additionally, the getResource(String) method has special knowledge of the /WEB-INF/web.xml file, which is not required by the JspC plugin but by the TldLocationsCache. Hence this method simulates the web.xml with an embedded empty resource.


Field Summary
protected  Hashtable<String,Object> attributes
          Servlet context attributes.
protected  org.apache.maven.plugin.logging.Log log
          The log writer we will write log messages to.
protected  URL resourceBaseURL
          The base URL (document root) for this context.
 
Constructor Summary
JspCServletContext(org.apache.maven.plugin.logging.Log log, URL resourceBaseURL)
          Create a new instance of this ServletContext implementation.
 
Method Summary
 Object getAttribute(String name)
          Return the specified context attribute, if any.
 Enumeration<String> getAttributeNames()
          Return an enumeration of context attribute names.
 javax.servlet.ServletContext getContext(String uripath)
          Return the servlet context for the specified path.
 String getContextPath()
          Return "/" as the context path for compilation.
 String getInitParameter(String name)
          Return the specified context initialization parameter.
 Enumeration<String> getInitParameterNames()
          Return an enumeration of the names of context initialization parameters.
 int getMajorVersion()
          Return the Servlet API major version number.
 String getMimeType(String file)
          Return the MIME type for the specified filename.
 int getMinorVersion()
          Return the Servlet API minor version number.
 javax.servlet.RequestDispatcher getNamedDispatcher(String name)
          Return a request dispatcher for the specified servlet name.
 String getRealPath(String path)
          Return the real path for the specified context-relative virtual path.
 javax.servlet.RequestDispatcher getRequestDispatcher(String path)
          Return a request dispatcher for the specified context-relative path.
 URL getResource(String path)
          Return a URL object of a resource that is mapped to the specified context-relative path.
 InputStream getResourceAsStream(String path)
          Return an InputStream allowing access to the resource at the specified context-relative path.
 Set<String> getResourcePaths(String path)
          Return the set of resource paths for the "directory" at the specified context path.
 String getServerInfo()
          Return descriptive information about this server.
 javax.servlet.Servlet getServlet(String name)
          Deprecated. This method has been deprecated with no replacement
 String getServletContextName()
          Return the name of this servlet context.
 Enumeration<String> getServletNames()
          Deprecated. This method has been deprecated with no replacement
 Enumeration<javax.servlet.Servlet> getServlets()
          Deprecated. This method has been deprecated with no replacement
 void log(Exception exception, String message)
          Deprecated. Use log(String,Throwable) instead
 void log(String message)
          Log the specified message.
 void log(String message, Throwable exception)
          Log the specified message and exception.
 void removeAttribute(String name)
          Remove the specified context attribute.
 void setAttribute(String name, Object value)
          Set or replace the specified context attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

protected Hashtable<String,Object> attributes
Servlet context attributes.


log

protected org.apache.maven.plugin.logging.Log log
The log writer we will write log messages to.


resourceBaseURL

protected URL resourceBaseURL
The base URL (document root) for this context.

Constructor Detail

JspCServletContext

public JspCServletContext(org.apache.maven.plugin.logging.Log log,
                          URL resourceBaseURL)
Create a new instance of this ServletContext implementation.

Parameters:
log - The Log which is used for log() calls
resourceBaseURL - Resource base URL
Method Detail

getAttribute

public Object getAttribute(String name)
Return the specified context attribute, if any.

Specified by:
getAttribute in interface javax.servlet.ServletContext
Parameters:
name - Name of the requested attribute

getAttributeNames

public Enumeration<String> getAttributeNames()
Return an enumeration of context attribute names.

Specified by:
getAttributeNames in interface javax.servlet.ServletContext

getContext

public javax.servlet.ServletContext getContext(String uripath)
Return the servlet context for the specified path.

Specified by:
getContext in interface javax.servlet.ServletContext
Parameters:
uripath - Server-relative path starting with '/'

getInitParameter

public String getInitParameter(String name)
Return the specified context initialization parameter.

Parameters:
name - Name of the requested parameter

getInitParameterNames

public Enumeration<String> getInitParameterNames()
Return an enumeration of the names of context initialization parameters.


getMajorVersion

public int getMajorVersion()
Return the Servlet API major version number.

Specified by:
getMajorVersion in interface javax.servlet.ServletContext

getMimeType

public String getMimeType(String file)
Return the MIME type for the specified filename.

Specified by:
getMimeType in interface javax.servlet.ServletContext
Parameters:
file - Filename whose MIME type is requested

getMinorVersion

public int getMinorVersion()
Return the Servlet API minor version number.

Specified by:
getMinorVersion in interface javax.servlet.ServletContext

getNamedDispatcher

public javax.servlet.RequestDispatcher getNamedDispatcher(String name)
Return a request dispatcher for the specified servlet name.

Parameters:
name - Name of the requested servlet

getRealPath

public String getRealPath(String path)
Return the real path for the specified context-relative virtual path.

Specified by:
getRealPath in interface javax.servlet.ServletContext
Parameters:
path - The context-relative virtual path to resolve

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
Return a request dispatcher for the specified context-relative path.

Specified by:
getRequestDispatcher in interface javax.servlet.ServletContext
Parameters:
path - Context-relative path for which to acquire a dispatcher

getResource

public URL getResource(String path)
                throws MalformedURLException
Return a URL object of a resource that is mapped to the specified context-relative path.

Specified by:
getResource in interface javax.servlet.ServletContext
Parameters:
path - Context-relative path of the desired resource
Throws:
MalformedURLException - if the resource path is not properly formed

getResourceAsStream

public InputStream getResourceAsStream(String path)
Return an InputStream allowing access to the resource at the specified context-relative path.

Specified by:
getResourceAsStream in interface javax.servlet.ServletContext
Parameters:
path - Context-relative path of the desired resource

getResourcePaths

public Set<String> getResourcePaths(String path)
Return the set of resource paths for the "directory" at the specified context path.

Parameters:
path - Context-relative base path

getServerInfo

public String getServerInfo()
Return descriptive information about this server.

Specified by:
getServerInfo in interface javax.servlet.ServletContext

getServlet

@Deprecated
public javax.servlet.Servlet getServlet(String name)
Deprecated. This method has been deprecated with no replacement

Return a null reference for the specified servlet name.

Specified by:
getServlet in interface javax.servlet.ServletContext
Parameters:
name - Name of the requested servlet

getServletContextName

public String getServletContextName()
Return the name of this servlet context.


getContextPath

public String getContextPath()
Return "/" as the context path for compilation.


getServletNames

@Deprecated
public Enumeration<String> getServletNames()
Deprecated. This method has been deprecated with no replacement

Return an empty enumeration of servlet names.

Specified by:
getServletNames in interface javax.servlet.ServletContext

getServlets

@Deprecated
public Enumeration<javax.servlet.Servlet> getServlets()
Deprecated. This method has been deprecated with no replacement

Return an empty enumeration of servlets.

Specified by:
getServlets in interface javax.servlet.ServletContext

log

public void log(String message)
Log the specified message.

Specified by:
log in interface javax.servlet.ServletContext
Parameters:
message - The message to be logged

log

@Deprecated
public void log(Exception exception,
                           String message)
Deprecated. Use log(String,Throwable) instead

Log the specified message and exception.

Specified by:
log in interface javax.servlet.ServletContext
Parameters:
exception - The exception to be logged
message - The message to be logged

log

public void log(String message,
                Throwable exception)
Log the specified message and exception.

Specified by:
log in interface javax.servlet.ServletContext
Parameters:
message - The message to be logged
exception - The exception to be logged

removeAttribute

public void removeAttribute(String name)
Remove the specified context attribute.

Specified by:
removeAttribute in interface javax.servlet.ServletContext
Parameters:
name - Name of the attribute to remove

setAttribute

public void setAttribute(String name,
                         Object value)
Set or replace the specified context attribute.

Specified by:
setAttribute in interface javax.servlet.ServletContext
Parameters:
name - Name of the context attribute to set
value - Corresponding attribute value


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.