Class BaseResourceServletContext
- java.lang.Object
-
- de.aristaflow.adept2.base.servletcontainer.dynamic.BaseResourceServletContext
-
- All Implemented Interfaces:
javax.servlet.ServletContext
public class BaseResourceServletContext extends Object implements javax.servlet.ServletContext
A wrapping servlet context that loads resources relative to a provided class.
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.servlet.ServletContext
context
The servlet context to which to delegate to.static String
FILE_PROTOCOL
The protocol for a file.static String
JAR_FILE_PROTOCOL
The protocol for a Jar-file.protected Class<?>
loader
The class relative to which we try to load resources.protected URL
loaderBase
The URL that is the base of our loader (class) .protected Logger
logger
The logger for logging exception messages and important proceed information.
-
Constructor Summary
Constructors Constructor Description BaseResourceServletContext(javax.servlet.ServletContext context, Class<?> loader, Logger logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
javax.servlet.ServletRegistration.Dynamic
addJspFile(String servletName, String jspFile)
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)
Enumeration<String>
getAttributeNames()
protected Set<String>
getChildren(String entryPath, JarFile file)
Gets the children for the designated path in the designated jar-file.ClassLoader
getClassLoader()
javax.servlet.ServletContext
getContext(String uripath)
String
getContextPath()
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)
Enumeration<String>
getInitParameterNames()
javax.servlet.descriptor.JspConfigDescriptor
getJspConfigDescriptor()
int
getMajorVersion()
String
getMimeType(String file)
int
getMinorVersion()
javax.servlet.RequestDispatcher
getNamedDispatcher(String name)
String
getRealPath(String path)
String
getRequestCharacterEncoding()
javax.servlet.RequestDispatcher
getRequestDispatcher(String path)
URL
getResource(String path)
InputStream
getResourceAsStream(String path)
protected URL
getResourceFromLoader(String path)
Tries to retrieve the designated path from our loader (class).Set<String>
getResourcePaths(String path)
String
getResponseCharacterEncoding()
String
getServerInfo()
javax.servlet.Servlet
getServlet(String name)
String
getServletContextName()
Enumeration<String>
getServletNames()
javax.servlet.ServletRegistration
getServletRegistration(String servletName)
Map<String,? extends javax.servlet.ServletRegistration>
getServletRegistrations()
Enumeration<javax.servlet.Servlet>
getServlets()
javax.servlet.SessionCookieConfig
getSessionCookieConfig()
int
getSessionTimeout()
String
getVirtualServerName()
protected Set<String>
listContentOfUrl(URL resource, URL base)
Lists the content of the designated URL.protected Set<String>
listContentOfUrlExt(URL resource, URL base, String relResPath)
Lists the content of the designated URL and thus extendslistContentOfUrl(URL, URL)
.void
log(Exception exception, String msg)
void
log(String msg)
void
log(String message, Throwable throwable)
void
removeAttribute(String name)
void
setAttribute(String name, Object object)
boolean
setInitParameter(String name, String value)
void
setRequestCharacterEncoding(String encoding)
void
setResponseCharacterEncoding(String encoding)
void
setSessionTimeout(int sessionTimeout)
void
setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
-
-
-
Field Detail
-
FILE_PROTOCOL
public static final String FILE_PROTOCOL
The protocol for a file.- See Also:
- Constant Field Values
-
JAR_FILE_PROTOCOL
public static final String JAR_FILE_PROTOCOL
The protocol for a Jar-file.- See Also:
- Constant Field Values
-
context
protected final javax.servlet.ServletContext context
The servlet context to which to delegate to.
-
loader
protected final Class<?> loader
The class relative to which we try to load resources.
-
loaderBase
protected final URL loaderBase
The URL that is the base of our loader (class) .
-
logger
protected final Logger logger
The logger for logging exception messages and important proceed information.
-
-
Constructor Detail
-
BaseResourceServletContext
public BaseResourceServletContext(javax.servlet.ServletContext context, Class<?> loader, Logger logger) throws MalformedURLException
- Parameters:
context
- The servlet context to which to delegate to.loader
- The class relative to which we try to load resources.logger
- The logger for logging exception messages and important proceed information.- Throws:
MalformedURLException
- If there are problems creating the base URL, that is the URL relative to which to load resources, aMalformedURLException
will be thrown.
-
-
Method Detail
-
getContextPath
public String getContextPath()
- Specified by:
getContextPath
in interfacejavax.servlet.ServletContext
-
getContext
public javax.servlet.ServletContext getContext(String uripath)
- Specified by:
getContext
in interfacejavax.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()
- Specified by:
getMajorVersion
in interfacejavax.servlet.ServletContext
-
getMinorVersion
public int getMinorVersion()
- Specified by:
getMinorVersion
in interfacejavax.servlet.ServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()
- Specified by:
getEffectiveMajorVersion
in interfacejavax.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()
- Specified by:
getEffectiveMinorVersion
in interfacejavax.servlet.ServletContext
-
getMimeType
public String getMimeType(String file)
- Specified by:
getMimeType
in interfacejavax.servlet.ServletContext
-
getResourcePaths
public Set<String> getResourcePaths(String path)
- Specified by:
getResourcePaths
in interfacejavax.servlet.ServletContext
-
getResource
public URL getResource(String path) throws MalformedURLException
- Specified by:
getResource
in interfacejavax.servlet.ServletContext
- Throws:
MalformedURLException
-
listContentOfUrl
protected Set<String> listContentOfUrl(URL resource, URL base)
Lists the content of the designated URL. The URL is retrieved from loading a resource relative to a class. It may be specific to the servlet container that embeds this servlet. This method does not need to delegate to the underlying context. This will be done if this method does not return valid content.Usually you do not override this method but
listContentOfUrlExt(URL, URL, String)
. If a file or Jar-file protocol is encountered, this implementation will usually suit your needs. In case of other protocols,listContentOfUrlExt(URL, URL, String)
will be called.- Parameters:
resource
- The URL identifying a resource as retrieved from our loader (class).base
- The URL identifying the top-level path of our loader.- Returns:
- The content of the designated URL (usually the content of the
directory specified by the designated URL relative to the loader
URL. If the directory for the resource is empty, the empty list
will be returned, if no content can be retrieved, e.g. the resource
URL cannot be interpreted as directory,
null
will be returned. Directories need to have a trailing slash.
-
listContentOfUrlExt
protected Set<String> listContentOfUrlExt(URL resource, URL base, String relResPath)
Lists the content of the designated URL and thus extendslistContentOfUrl(URL, URL)
. This method will be called if the URL protocol cannot be handled there. Subclasses should override this method to support further protocols.This default implementation just returns
null
indicating that the resource cannot be interpreted as directory.- Parameters:
resource
- The URL identifying a resource as retrieved from our loader (class).base
- The URL identifying the top-level path of our loader.relResPath
- The path to the resource URL relative to the base URL. Obviously this will only be valid if the designated resource is part of the designated base.- Returns:
- The content of the designated URL (usually the content of the
directory specified by the designated URL relative to the loader
URL. If the directory for the resource is empty, the empty list
will be returned, if no content can be retrieved, e.g. the resource
URL cannot be interpreted as directory,
null
will be returned. Directories need to have a trailing slash.
-
getChildren
protected Set<String> getChildren(String entryPath, JarFile file)
Gets the children for the designated path in the designated jar-file.- Parameters:
entryPath
- The entry for which to get the direct children. The path is relative to the designated jar-file.file
- The jar-file from which to retrieve the children.- Returns:
- The paths of the children of the designated entry relative to the designated jar-file. Note that directories must have a trailing "/".
-
getResourceFromLoader
protected URL getResourceFromLoader(String path)
Tries to retrieve the designated path from our loader (class). The path is tried relatively and absolutely. If the loader does not know the designated path,null
will be returned.- Parameters:
path
- The path which to search in our loader (class).- Returns:
- The URL retrieved from our loader (class) or
null
if the loader does not know the path.
-
getResourceAsStream
public InputStream getResourceAsStream(String path)
- Specified by:
getResourceAsStream
in interfacejavax.servlet.ServletContext
-
getRequestDispatcher
public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
- Specified by:
getRequestDispatcher
in interfacejavax.servlet.ServletContext
-
getNamedDispatcher
public javax.servlet.RequestDispatcher getNamedDispatcher(String name)
- Specified by:
getNamedDispatcher
in interfacejavax.servlet.ServletContext
-
getServlet
public javax.servlet.Servlet getServlet(String name) throws javax.servlet.ServletException
- Specified by:
getServlet
in interfacejavax.servlet.ServletContext
- Throws:
javax.servlet.ServletException
-
getServlets
public Enumeration<javax.servlet.Servlet> getServlets()
- Specified by:
getServlets
in interfacejavax.servlet.ServletContext
-
getServletNames
public Enumeration<String> getServletNames()
- Specified by:
getServletNames
in interfacejavax.servlet.ServletContext
-
log
public void log(String msg)
- Specified by:
log
in interfacejavax.servlet.ServletContext
-
log
public void log(Exception exception, String msg)
- Specified by:
log
in interfacejavax.servlet.ServletContext
-
log
public void log(String message, Throwable throwable)
- Specified by:
log
in interfacejavax.servlet.ServletContext
-
getRealPath
public String getRealPath(String path)
- Specified by:
getRealPath
in interfacejavax.servlet.ServletContext
-
getServerInfo
public String getServerInfo()
- Specified by:
getServerInfo
in interfacejavax.servlet.ServletContext
-
getInitParameter
public String getInitParameter(String name)
- Specified by:
getInitParameter
in interfacejavax.servlet.ServletContext
-
getInitParameterNames
public Enumeration<String> getInitParameterNames()
- Specified by:
getInitParameterNames
in interfacejavax.servlet.ServletContext
-
setInitParameter
public boolean setInitParameter(String name, String value)
- Specified by:
setInitParameter
in interfacejavax.servlet.ServletContext
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttribute
in interfacejavax.servlet.ServletContext
-
getAttributeNames
public Enumeration<String> getAttributeNames()
- Specified by:
getAttributeNames
in interfacejavax.servlet.ServletContext
-
setAttribute
public void setAttribute(String name, Object object)
- Specified by:
setAttribute
in interfacejavax.servlet.ServletContext
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttribute
in interfacejavax.servlet.ServletContext
-
getServletContextName
public String getServletContextName()
- Specified by:
getServletContextName
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
-
addJspFile
public javax.servlet.ServletRegistration.Dynamic addJspFile(String servletName, String jspFile)
- Specified by:
addJspFile
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
-
getSessionTimeout
public int getSessionTimeout()
- Specified by:
getSessionTimeout
in interfacejavax.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout)
- Specified by:
setSessionTimeout
in interfacejavax.servlet.ServletContext
-
getRequestCharacterEncoding
public String getRequestCharacterEncoding()
- Specified by:
getRequestCharacterEncoding
in interfacejavax.servlet.ServletContext
-
setRequestCharacterEncoding
public void setRequestCharacterEncoding(String encoding)
- Specified by:
setRequestCharacterEncoding
in interfacejavax.servlet.ServletContext
-
getResponseCharacterEncoding
public String getResponseCharacterEncoding()
- Specified by:
getResponseCharacterEncoding
in interfacejavax.servlet.ServletContext
-
setResponseCharacterEncoding
public void setResponseCharacterEncoding(String encoding)
- Specified by:
setResponseCharacterEncoding
in interfacejavax.servlet.ServletContext
-
-