Class SlingServletContext
java.lang.Object
org.apache.sling.engine.impl.helper.SlingServletContext
- All Implemented Interfaces:
 EventListener,javax.servlet.ServletContext,javax.servlet.ServletContextListener
public class SlingServletContext
extends Object
implements javax.servlet.ServletContext, javax.servlet.ServletContextListener
The 
SlingServletContext class is the ServletContext
 which is registered as a service usable by servlets and helpers inside Sling.
 Most methods just call into the servlet context in which the
 SlingMainServlet is running.
 - MIME Type Mapping
 - Just forwards to the servlet context of the 
SlingMainServletfor MIME type mapping. - Resources
 - This class provides access to the resources in the web application by
 means of the respective resource accessor methods. These are not the same
 resources as available through the 
ResourceResolver. - Request Dispatcher
 - The 
getRequestDispatcher(String)method returns aSlingRequestDispatcherwhich may dispatch a request inside sling without going through the servlet container. ThegetNamedDispatcher(String)method returns a servlet container request dispatcher which always goes through the servlet container. - Parameters and Attributes
 - Initialization parameters and context attributes are shared with the
 servlet context in which the 
SlingMainServletis running. - Logging
 - Logging is diverted to a logger whose name is the fully qualified name of this class.
 
 This class implements the Servlet API 3.0 ServletContext interface.
- 
Field Summary
FieldsFields inherited from interface javax.servlet.ServletContext
ORDERED_LIBS, TEMPDIR - 
Constructor Summary
ConstructorsConstructorDescriptionSlingServletContext(org.apache.sling.engine.impl.Config config, org.osgi.framework.BundleContext bundleContext, org.apache.sling.engine.impl.ProductInfoProvider infoProvider)  - 
Method Summary
Modifier and TypeMethodDescriptionjavax.servlet.FilterRegistration.Dynamicjavax.servlet.FilterRegistration.Dynamicjavax.servlet.FilterRegistration.DynamicvoidaddListener(Class<? extends EventListener> listenerClass) voidaddListener(String className) <T extends EventListener>
voidaddListener(T t) javax.servlet.ServletRegistration.DynamicaddServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass) javax.servlet.ServletRegistration.DynamicaddServlet(String servletName, String className) javax.servlet.ServletRegistration.DynamicaddServlet(String servletName, javax.servlet.Servlet servlet) voidcontextDestroyed(javax.servlet.ServletContextEvent sce) voidcontextInitialized(javax.servlet.ServletContextEvent sce) <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) voiddeclareRoles(String... roleNames) getAttribute(String name) Returns the named servlet context attribute.Returns the names of all servlet context attributes.javax.servlet.ServletContextgetContext(String uripath) Returns the servlet context from the servlet container in which sling is running.Returns the context path of the web application.Set<javax.servlet.SessionTrackingMode>intintSet<javax.servlet.SessionTrackingMode>javax.servlet.FilterRegistrationgetFilterRegistration(String filterName) getInitParameter(String name) Returns the init-param of the servlet context in which Sling is configured.Returns the names of the init-params of the servlet context in which Sling is configured.javax.servlet.descriptor.JspConfigDescriptorintReturns the major version number of the Servlet API supported by the servlet container in which Sling is running.getMimeType(String file) Returns a MIME type for the extension of the given file name.intReturns the minor version number of the Servlet API supported by the servlet container in which Sling is running.javax.servlet.RequestDispatchergetNamedDispatcher(String name) Returns a servlet container request dispatcher for the named servlet.getRealPath(String path) Returns the real file inside the web application to which the given path maps ornullif no such file exists.javax.servlet.RequestDispatchergetRequestDispatcher(String path) Returns aSlingRequestDispatcherfor the given path if notnull.getResource(String path) Returns the URI for the given path.getResourceAsStream(String path) Returns an input stream to the given path.getResourcePaths(String parentPath) Returns a set of names for path entries considered children of the given path.Returns the Sling server info string.javax.servlet.ServletgetServlet(String name) Deprecated.protected javax.servlet.ServletContextReturns the real servlet context of the servlet container in which the Sling Servlet is running.Returns the name of the servlet context in which Sling is configured.Deprecated.javax.servlet.ServletRegistrationgetServletRegistration(String servletName) Enumeration<javax.servlet.Servlet>Deprecated.javax.servlet.SessionCookieConfigvoidDeprecated.voidLogs the message at info level to the loggervoidLogs the message and optional throwable at error level to the loggerprotected voidmodified(org.apache.sling.engine.impl.Config config) voidremoveAttribute(String name) Removes the named servlet context attribute.voidsetAttribute(String name, Object object) Sets the name servlet context attribute to the requested value.booleansetInitParameter(String name, String value) voidsetSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes) protected javax.servlet.ServletContextwrapServletContext(javax.servlet.ServletContext context)  
- 
Field Details
- 
TARGET
- See Also:
 
 
 - 
 - 
Constructor Details
- 
SlingServletContext
public SlingServletContext(org.apache.sling.engine.impl.Config config, org.osgi.framework.BundleContext bundleContext, org.apache.sling.engine.impl.ProductInfoProvider infoProvider)  
 - 
 - 
Method Details
- 
modified
protected void modified(org.apache.sling.engine.impl.Config config)  - 
contextInitialized
public void contextInitialized(javax.servlet.ServletContextEvent sce) - Specified by:
 contextInitializedin interfacejavax.servlet.ServletContextListener
 - 
contextDestroyed
public void contextDestroyed(javax.servlet.ServletContextEvent sce) - Specified by:
 contextDestroyedin interfacejavax.servlet.ServletContextListener
 - 
getServletContextName
Returns the name of the servlet context in which Sling is configured. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getServletContextNamein interfacejavax.servlet.ServletContext
 - 
getContextPath
Returns the context path of the web application. (Servlet API 2.5)- Specified by:
 getContextPathin interfacejavax.servlet.ServletContext
 - 
getInitParameter
Returns the init-param of the servlet context in which Sling is configured. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getInitParameterin interfacejavax.servlet.ServletContext
 - 
getInitParameterNames
Returns the names of the init-params of the servlet context in which Sling is configured. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getInitParameterNamesin interfacejavax.servlet.ServletContext
 - 
getAttribute
Returns the named servlet context attribute. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getAttributein interfacejavax.servlet.ServletContext
 - 
getAttributeNames
Returns the names of all servlet context attributes. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getAttributeNamesin interfacejavax.servlet.ServletContext
 - 
removeAttribute
Removes the named servlet context attribute. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 removeAttributein interfacejavax.servlet.ServletContext
 - 
setAttribute
Sets the name servlet context attribute to the requested value. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 setAttributein interfacejavax.servlet.ServletContext
 - 
getServerInfo
Returns the Sling server info string. This is not the same server info string as returned by the servlet context in which Sling is configured.- Specified by:
 getServerInfoin interfacejavax.servlet.ServletContext
 - 
getMajorVersion
public int getMajorVersion()Returns the major version number of the Servlet API supported by the servlet container in which Sling is running. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getMajorVersionin interfacejavax.servlet.ServletContext
 - 
getMinorVersion
public int getMinorVersion()Returns the minor version number of the Servlet API supported by the servlet container in which Sling is running. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getMinorVersionin interfacejavax.servlet.ServletContext
 - 
getMimeType
Returns a MIME type for the extension of the given file name. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getMimeTypein interfacejavax.servlet.ServletContext
 - 
getRequestDispatcher
- Specified by:
 getRequestDispatcherin interfacejavax.servlet.ServletContext
 - 
getNamedDispatcher
Returns a servlet container request dispatcher for the named servlet. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getNamedDispatcherin interfacejavax.servlet.ServletContext
 - 
getResource
Returns the URI for the given path. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getResourcein interfacejavax.servlet.ServletContext- Throws:
 MalformedURLException
 - 
getResourceAsStream
Returns an input stream to the given path. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getResourceAsStreamin interfacejavax.servlet.ServletContext
 - 
getResourcePaths
Returns a set of names for path entries considered children of the given path. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getResourcePathsin interfacejavax.servlet.ServletContext
 - 
getRealPath
Returns the real file inside the web application to which the given path maps ornullif no such file exists. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getRealPathin interfacejavax.servlet.ServletContext
 - 
log
Logs the message and optional throwable at error level to the logger- Specified by:
 login interfacejavax.servlet.ServletContext
 - 
log
Logs the message at info level to the logger- Specified by:
 login interfacejavax.servlet.ServletContext
 - 
log
Deprecated.Logs the message and optional exception at error level to the logger- Specified by:
 login interfacejavax.servlet.ServletContext
 - 
getContext
Returns the servlet context from the servlet container in which sling is running. This method calls on theServletContextin which theSlingMainServletis running.- Specified by:
 getContextin interfacejavax.servlet.ServletContext
 - 
getServlet
Deprecated.Returnsnullas defined in Servlet API 2.4- Specified by:
 getServletin interfacejavax.servlet.ServletContext
 - 
getServletNames
Deprecated.Returns an empty enumeration as defined in Servlet API 2.4- Specified by:
 getServletNamesin interfacejavax.servlet.ServletContext
 - 
getServlets
Deprecated.Returns an empty enumeration as defined in Servlet API 2.4- Specified by:
 getServletsin interfacejavax.servlet.ServletContext
 - 
getEffectiveMajorVersion
public int getEffectiveMajorVersion()- Specified by:
 getEffectiveMajorVersionin interfacejavax.servlet.ServletContext
 - 
getEffectiveMinorVersion
public int getEffectiveMinorVersion()- Specified by:
 getEffectiveMinorVersionin interfacejavax.servlet.ServletContext
 - 
setInitParameter
- Specified by:
 setInitParameterin interfacejavax.servlet.ServletContext
 - 
getSessionCookieConfig
public javax.servlet.SessionCookieConfig getSessionCookieConfig()- Specified by:
 getSessionCookieConfigin interfacejavax.servlet.ServletContext
 - 
setSessionTrackingModes
- Specified by:
 setSessionTrackingModesin interfacejavax.servlet.ServletContext
 - 
getDefaultSessionTrackingModes
- Specified by:
 getDefaultSessionTrackingModesin interfacejavax.servlet.ServletContext
 - 
getEffectiveSessionTrackingModes
- Specified by:
 getEffectiveSessionTrackingModesin interfacejavax.servlet.ServletContext
 - 
getJspConfigDescriptor
public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()- Specified by:
 getJspConfigDescriptorin interfacejavax.servlet.ServletContext
 - 
getClassLoader
- Specified by:
 getClassLoaderin interfacejavax.servlet.ServletContext
 - 
declareRoles
- Specified by:
 declareRolesin interfacejavax.servlet.ServletContext
 - 
addServlet
- Specified by:
 addServletin interfacejavax.servlet.ServletContext
 - 
addServlet
public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, javax.servlet.Servlet servlet) - Specified by:
 addServletin interfacejavax.servlet.ServletContext
 - 
addServlet
public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass) - Specified by:
 addServletin interfacejavax.servlet.ServletContext
 - 
createServlet
- Specified by:
 createServletin interfacejavax.servlet.ServletContext
 - 
getServletRegistration
- Specified by:
 getServletRegistrationin interfacejavax.servlet.ServletContext
 - 
getServletRegistrations
- Specified by:
 getServletRegistrationsin interfacejavax.servlet.ServletContext
 - 
addFilter
- Specified by:
 addFilterin interfacejavax.servlet.ServletContext
 - 
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, javax.servlet.Filter filter) - Specified by:
 addFilterin interfacejavax.servlet.ServletContext
 - 
addFilter
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass) - Specified by:
 addFilterin interfacejavax.servlet.ServletContext
 - 
createFilter
- Specified by:
 createFilterin interfacejavax.servlet.ServletContext
 - 
getFilterRegistration
- Specified by:
 getFilterRegistrationin interfacejavax.servlet.ServletContext
 - 
getFilterRegistrations
- Specified by:
 getFilterRegistrationsin interfacejavax.servlet.ServletContext
 - 
addListener
- Specified by:
 addListenerin interfacejavax.servlet.ServletContext
 - 
addListener
- Specified by:
 addListenerin interfacejavax.servlet.ServletContext
 - 
addListener
- Specified by:
 addListenerin interfacejavax.servlet.ServletContext
 - 
createListener
- Specified by:
 createListenerin interfacejavax.servlet.ServletContext
 - 
getVirtualServerName
- Specified by:
 getVirtualServerNamein interfacejavax.servlet.ServletContext
 - 
getServletContext
protected javax.servlet.ServletContext getServletContext()Returns the real servlet context of the servlet container in which the Sling Servlet is running.- Returns:
 - the servlet context
 
 - 
wrapServletContext
protected javax.servlet.ServletContext wrapServletContext(javax.servlet.ServletContext context)  
 -