public class SlingServletContext extends Object implements javax.servlet.ServletContext
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.
SlingMainServlet for
MIME type mapping.ResourceResolver.getRequestDispatcher(String) method returns a
SlingRequestDispatcher which may dispatch a request inside sling
without going through the servlet container. The
getNamedDispatcher(String) method returns a servlet container
request dispatcher which always goes through the servlet container.SlingMainServlet is running.
This class implements the Servlet API 2.5 ServletContext interface.
See SlingServletContext3 for the Servlet API 3 implementation.
| Constructor and Description |
|---|
SlingServletContext(org.osgi.framework.BundleContext bundleContext,
SlingMainServlet slingMainServlet)
Creates an instance of this class delegating some methods to the given
SlingMainServlet. |
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Unregisters this servlet context as a service (if registered at all)
This method must be called before the sling main servlet
is destroyed.
|
Object |
getAttribute(String name)
Returns the named servlet context attribute.
|
Enumeration<String> |
getAttributeNames()
Returns the names of all servlet context attributes.
|
javax.servlet.ServletContext |
getContext(String uripath)
Returns the servlet context from the servlet container in which sling is
running.
|
String |
getContextPath()
Returns the context path of the web application.
|
String |
getInitParameter(String name)
Returns the init-param of the servlet context in which Sling is
configured.
|
Enumeration<String> |
getInitParameterNames()
Returns the names of the init-params of the servlet context in which
Sling is configured.
|
int |
getMajorVersion()
Returns the major version number of the Servlet API supported by the
servlet container in which Sling is running.
|
String |
getMimeType(String file)
Returns a MIME type for the extension of the given file name.
|
int |
getMinorVersion()
Returns the minor version number of the Servlet API supported by the
servlet container in which Sling is running.
|
javax.servlet.RequestDispatcher |
getNamedDispatcher(String name)
Returns a servlet container request dispatcher for the named servlet.
|
String |
getRealPath(String path)
Returns the real file inside the web application to which the given path
maps or
null if no such file exists. |
javax.servlet.RequestDispatcher |
getRequestDispatcher(String path)
Returns a
SlingRequestDispatcher for the given path if not
null. |
URL |
getResource(String path)
Returns the URI for the given path.
|
InputStream |
getResourceAsStream(String path)
Returns an input stream to the given path.
|
Set<String> |
getResourcePaths(String parentPath)
Returns a set of names for path entries considered children of the given
path.
|
String |
getServerInfo()
Returns the Sling server info string.
|
javax.servlet.Servlet |
getServlet(String name)
Deprecated.
|
protected javax.servlet.ServletContext |
getServletContext()
Returns the real servlet context of the servlet container in which the
Sling Servlet is running.
|
String |
getServletContextName()
Returns the name of the servlet context in which Sling is configured.
|
Enumeration<String> |
getServletNames()
Deprecated.
|
Enumeration<javax.servlet.Servlet> |
getServlets()
Deprecated.
|
void |
log(Exception exception,
String message)
Deprecated.
|
void |
log(String message)
Logs the message at info level to the logger
|
void |
log(String message,
Throwable throwable)
Logs the message and optional throwable at error level to the logger
|
void |
removeAttribute(String name)
Removes the named servlet context attribute.
|
void |
setAttribute(String name,
Object object)
Sets the name servlet context attribute to the requested value.
|
protected javax.servlet.ServletContext |
wrapServletContext(javax.servlet.ServletContext context) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddFilter, addFilter, addFilter, addListener, addListener, addListener, addServlet, addServlet, addServlet, createFilter, createListener, createServlet, declareRoles, getClassLoader, getDefaultSessionTrackingModes, getEffectiveMajorVersion, getEffectiveMinorVersion, getEffectiveSessionTrackingModes, getFilterRegistration, getFilterRegistrations, getJspConfigDescriptor, getServletRegistration, getServletRegistrations, getSessionCookieConfig, setInitParameter, setSessionTrackingModespublic SlingServletContext(org.osgi.framework.BundleContext bundleContext,
SlingMainServlet slingMainServlet)
SlingMainServlet. In addition the new instance is registered as
aServletContext.
This method must only be called after the sling main servlet
has been fully initialized. Otherwise the getServletContext()
method may cause a NullPointerException !
dispose()public void dispose()
This method must be called before the sling main servlet
is destroyed. Otherwise the getServletContext() method may
cause a NullPointerException !
#SlingServletContext(SlingMainServlet)public String getServletContextName()
ServletContext in which the
SlingMainServlet is running.getServletContextName in interface javax.servlet.ServletContextpublic String getContextPath()
getContextPath in interface javax.servlet.ServletContextpublic String getInitParameter(String name)
ServletContext in
which the SlingMainServlet is running.getInitParameter in interface javax.servlet.ServletContextpublic Enumeration<String> getInitParameterNames()
ServletContext
in which the SlingMainServlet is running.getInitParameterNames in interface javax.servlet.ServletContextpublic Object getAttribute(String name)
ServletContext in which the SlingMainServlet is
running.getAttribute in interface javax.servlet.ServletContextpublic Enumeration<String> getAttributeNames()
ServletContext in which the SlingMainServlet
is running.getAttributeNames in interface javax.servlet.ServletContextpublic void removeAttribute(String name)
ServletContext in which the SlingMainServlet is
running.removeAttribute in interface javax.servlet.ServletContextpublic void setAttribute(String name, Object object)
ServletContext in which the
SlingMainServlet is running.setAttribute in interface javax.servlet.ServletContextpublic String getServerInfo()
getServerInfo in interface javax.servlet.ServletContextpublic int getMajorVersion()
ServletContext in which the SlingMainServlet is
running.getMajorVersion in interface javax.servlet.ServletContextpublic int getMinorVersion()
ServletContext in which the SlingMainServlet is
running.getMinorVersion in interface javax.servlet.ServletContextpublic String getMimeType(String file)
ServletContext in which the
SlingMainServlet is running.getMimeType in interface javax.servlet.ServletContextpublic javax.servlet.RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher in interface javax.servlet.ServletContextpublic javax.servlet.RequestDispatcher getNamedDispatcher(String name)
ServletContext in which the
SlingMainServlet is running.getNamedDispatcher in interface javax.servlet.ServletContextpublic URL getResource(String path) throws MalformedURLException
ServletContext in which the SlingMainServlet is
running.getResource in interface javax.servlet.ServletContextMalformedURLExceptionpublic InputStream getResourceAsStream(String path)
ServletContext in which the SlingMainServlet is
running.getResourceAsStream in interface javax.servlet.ServletContextpublic Set<String> getResourcePaths(String parentPath)
ServletContext in which the
SlingMainServlet is running.getResourcePaths in interface javax.servlet.ServletContextpublic String getRealPath(String path)
null if no such file exists. This method calls on
the ServletContext in which the SlingMainServlet
is running.getRealPath in interface javax.servlet.ServletContextpublic void log(String message, Throwable throwable)
log in interface javax.servlet.ServletContextpublic void log(String message)
log in interface javax.servlet.ServletContext@Deprecated public void log(Exception exception, String message)
log in interface javax.servlet.ServletContextpublic javax.servlet.ServletContext getContext(String uripath)
ServletContext in which
the SlingMainServlet is running.getContext in interface javax.servlet.ServletContext@Deprecated public javax.servlet.Servlet getServlet(String name)
null as defined in Servlet API 2.4getServlet in interface javax.servlet.ServletContext@Deprecated public Enumeration<String> getServletNames()
getServletNames in interface javax.servlet.ServletContext@Deprecated public Enumeration<javax.servlet.Servlet> getServlets()
getServlets in interface javax.servlet.ServletContextprotected javax.servlet.ServletContext getServletContext()
protected javax.servlet.ServletContext wrapServletContext(javax.servlet.ServletContext context)
Copyright © 2007–2014 The Apache Software Foundation. All rights reserved.