Package org.apache.sling.maven.jspc
Class JspCServletContext
- java.lang.Object
-
- org.apache.sling.maven.jspc.JspCServletContext
-
- All Implemented Interfaces:
javax.servlet.ServletContext
public class JspCServletContext extends Object implements javax.servlet.ServletContext
SimpleServletContext
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.
-
-
Constructor Summary
Constructors Constructor Description JspCServletContext(org.apache.maven.plugin.logging.Log log, URL resourceBaseURL, org.apache.sling.scripting.jsp.jasper.compiler.TldLocationsCache tldLocationsCache)
Create a new instance of this ServletContext implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAlternativeBaseURL(URL altBaseURL)
Adds an alternative base url for finding resources.javax.servlet.FilterRegistration.Dynamic
addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)
javax.servlet.FilterRegistration.Dynamic
addFilter(String filterName, String className)
javax.servlet.FilterRegistration.Dynamic
addFilter(String filterName, javax.servlet.Filter filter)
void
addListener(Class<? extends EventListener> listenerClass)
void
addListener(String className)
<T extends EventListener>
voidaddListener(T t)
javax.servlet.ServletRegistration.Dynamic
addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)
javax.servlet.ServletRegistration.Dynamic
addServlet(String servletName, String className)
javax.servlet.ServletRegistration.Dynamic
addServlet(String servletName, javax.servlet.Servlet servlet)
<T extends javax.servlet.Filter>
TcreateFilter(Class<T> clazz)
<T extends EventListener>
TcreateListener(Class<T> clazz)
<T extends javax.servlet.Servlet>
TcreateServlet(Class<T> clazz)
void
declareRoles(String... roleNames)
Object
getAttribute(String name)
Return the specified context attribute, if any.Enumeration<String>
getAttributeNames()
Return an enumeration of context attribute names.ClassLoader
getClassLoader()
javax.servlet.ServletContext
getContext(String uripath)
Return the servlet context for the specified path.String
getContextPath()
Return "/" as the context path for compilation.Set<javax.servlet.SessionTrackingMode>
getDefaultSessionTrackingModes()
int
getEffectiveMajorVersion()
int
getEffectiveMinorVersion()
Set<javax.servlet.SessionTrackingMode>
getEffectiveSessionTrackingModes()
javax.servlet.FilterRegistration
getFilterRegistration(String filterName)
Map<String,? extends javax.servlet.FilterRegistration>
getFilterRegistrations()
String
getInitParameter(String name)
Return the specified context initialization parameter.Enumeration<String>
getInitParameterNames()
Return an enumeration of the names of context initialization parameters.javax.servlet.descriptor.JspConfigDescriptor
getJspConfigDescriptor()
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 replacementString
getServletContextName()
Return the name of this servlet context.Enumeration<String>
getServletNames()
Deprecated.This method has been deprecated with no replacementjavax.servlet.ServletRegistration
getServletRegistration(String servletName)
Map<String,? extends javax.servlet.ServletRegistration>
getServletRegistrations()
Enumeration<javax.servlet.Servlet>
getServlets()
Deprecated.This method has been deprecated with no replacementjavax.servlet.SessionCookieConfig
getSessionCookieConfig()
String
getVirtualServerName()
void
log(Exception exception, String message)
Deprecated.Use log(String,Throwable) insteadvoid
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.boolean
setInitParameter(String name, String value)
void
setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
-
-
-
Constructor Detail
-
JspCServletContext
public JspCServletContext(org.apache.maven.plugin.logging.Log log, URL resourceBaseURL, org.apache.sling.scripting.jsp.jasper.compiler.TldLocationsCache tldLocationsCache)
Create a new instance of this ServletContext implementation.- Parameters:
log
- The Log which is used forlog()
callsresourceBaseURL
- Resource base URLtldLocationsCache
-
-
-
Method Detail
-
addAlternativeBaseURL
public void addAlternativeBaseURL(URL altBaseURL)
Adds an alternative base url for finding resources.- Parameters:
altBaseURL
- alternative resource base
-
getAttribute
public Object getAttribute(String name)
Return the specified context attribute, if any.- Specified by:
getAttribute
in interfacejavax.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 interfacejavax.servlet.ServletContext
-
getContext
public javax.servlet.ServletContext getContext(String uripath)
Return the servlet context for the specified path.- Specified by:
getContext
in interfacejavax.servlet.ServletContext
- Parameters:
uripath
- Server-relative path starting with '/'
-
getInitParameter
public String getInitParameter(String name)
Return the specified context initialization parameter.- Specified by:
getInitParameter
in interfacejavax.servlet.ServletContext
- Parameters:
name
- Name of the requested parameter
-
getInitParameterNames
public Enumeration<String> getInitParameterNames()
Return an enumeration of the names of context initialization parameters.- Specified by:
getInitParameterNames
in interfacejavax.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()
Return the Servlet API major version number.- Specified by:
getMajorVersion
in interfacejavax.servlet.ServletContext
-
getMimeType
public String getMimeType(String file)
Return the MIME type for the specified filename.- Specified by:
getMimeType
in interfacejavax.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 interfacejavax.servlet.ServletContext
-
getNamedDispatcher
public javax.servlet.RequestDispatcher getNamedDispatcher(String name)
Return a request dispatcher for the specified servlet name.- Specified by:
getNamedDispatcher
in interfacejavax.servlet.ServletContext
- 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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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.- Specified by:
getResourcePaths
in interfacejavax.servlet.ServletContext
- Parameters:
path
- Context-relative base path
-
getServerInfo
public String getServerInfo()
Return descriptive information about this server.- Specified by:
getServerInfo
in interfacejavax.servlet.ServletContext
-
getServlet
@Deprecated public javax.servlet.Servlet getServlet(String name)
Deprecated.This method has been deprecated with no replacementReturn a null reference for the specified servlet name.- Specified by:
getServlet
in interfacejavax.servlet.ServletContext
- Parameters:
name
- Name of the requested servlet
-
getServletContextName
public String getServletContextName()
Return the name of this servlet context.- Specified by:
getServletContextName
in interfacejavax.servlet.ServletContext
-
getContextPath
public String getContextPath()
Return "/" as the context path for compilation.- Specified by:
getContextPath
in interfacejavax.servlet.ServletContext
-
getServletNames
@Deprecated public Enumeration<String> getServletNames()
Deprecated.This method has been deprecated with no replacementReturn an empty enumeration of servlet names.- Specified by:
getServletNames
in interfacejavax.servlet.ServletContext
-
getServlets
@Deprecated public Enumeration<javax.servlet.Servlet> getServlets()
Deprecated.This method has been deprecated with no replacementReturn an empty enumeration of servlets.- Specified by:
getServlets
in interfacejavax.servlet.ServletContext
-
log
public void log(String message)
Log the specified message.- Specified by:
log
in interfacejavax.servlet.ServletContext
- Parameters:
message
- The message to be logged
-
log
@Deprecated public void log(Exception exception, String message)
Deprecated.Use log(String,Throwable) insteadLog the specified message and exception.- Specified by:
log
in interfacejavax.servlet.ServletContext
- Parameters:
exception
- The exception to be loggedmessage
- The message to be logged
-
log
public void log(String message, Throwable exception)
Log the specified message and exception.- Specified by:
log
in interfacejavax.servlet.ServletContext
- Parameters:
message
- The message to be loggedexception
- The exception to be logged
-
removeAttribute
public void removeAttribute(String name)
Remove the specified context attribute.- Specified by:
removeAttribute
in interfacejavax.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 interfacejavax.servlet.ServletContext
- Parameters:
name
- Name of the context attribute to setvalue
- Corresponding attribute value
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()
- Specified by:
getEffectiveMajorVersion
in interfacejavax.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()
- Specified by:
getEffectiveMinorVersion
in interfacejavax.servlet.ServletContext
-
setInitParameter
public boolean setInitParameter(String name, String value)
- Specified by:
setInitParameter
in interfacejavax.servlet.ServletContext
-
addServlet
public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className)
- Specified by:
addServlet
in interfacejavax.servlet.ServletContext
-
addServlet
public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, javax.servlet.Servlet servlet)
- Specified by:
addServlet
in interfacejavax.servlet.ServletContext
-
addServlet
public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)
- Specified by:
addServlet
in interfacejavax.servlet.ServletContext
-
createServlet
public <T extends javax.servlet.Servlet> T createServlet(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createServlet
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getServletRegistration
public javax.servlet.ServletRegistration getServletRegistration(String servletName)
- Specified by:
getServletRegistration
in interfacejavax.servlet.ServletContext
-
getServletRegistrations
public Map<String,? extends javax.servlet.ServletRegistration> getServletRegistrations()
- Specified by:
getServletRegistrations
in interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
- Specified by:
addFilter
in interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, javax.servlet.Filter filter)
- Specified by:
addFilter
in interfacejavax.servlet.ServletContext
-
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)
- Specified by:
addFilter
in interfacejavax.servlet.ServletContext
-
createFilter
public <T extends javax.servlet.Filter> T createFilter(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createFilter
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getFilterRegistration
public javax.servlet.FilterRegistration getFilterRegistration(String filterName)
- Specified by:
getFilterRegistration
in interfacejavax.servlet.ServletContext
-
getFilterRegistrations
public Map<String,? extends javax.servlet.FilterRegistration> getFilterRegistrations()
- Specified by:
getFilterRegistrations
in interfacejavax.servlet.ServletContext
-
getSessionCookieConfig
public javax.servlet.SessionCookieConfig getSessionCookieConfig()
- Specified by:
getSessionCookieConfig
in interfacejavax.servlet.ServletContext
-
setSessionTrackingModes
public void setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
- Specified by:
setSessionTrackingModes
in interfacejavax.servlet.ServletContext
-
getDefaultSessionTrackingModes
public Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
- Specified by:
getDefaultSessionTrackingModes
in interfacejavax.servlet.ServletContext
-
getEffectiveSessionTrackingModes
public Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
- Specified by:
getEffectiveSessionTrackingModes
in interfacejavax.servlet.ServletContext
-
addListener
public void addListener(String className)
- Specified by:
addListener
in interfacejavax.servlet.ServletContext
-
addListener
public <T extends EventListener> void addListener(T t)
- Specified by:
addListener
in interfacejavax.servlet.ServletContext
-
addListener
public void addListener(Class<? extends EventListener> listenerClass)
- Specified by:
addListener
in interfacejavax.servlet.ServletContext
-
createListener
public <T extends EventListener> T createListener(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createListener
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getJspConfigDescriptor
public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
- Specified by:
getJspConfigDescriptor
in interfacejavax.servlet.ServletContext
-
getClassLoader
public ClassLoader getClassLoader()
- Specified by:
getClassLoader
in interfacejavax.servlet.ServletContext
-
declareRoles
public void declareRoles(String... roleNames)
- Specified by:
declareRoles
in interfacejavax.servlet.ServletContext
-
getVirtualServerName
public String getVirtualServerName()
- Specified by:
getVirtualServerName
in interfacejavax.servlet.ServletContext
-
-