Class AbstractRepositoryServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.apache.jackrabbit.servlet.AbstractRepositoryServlet
-
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
- Direct Known Subclasses:
ContextRepositoryServlet
,JackrabbitRepositoryServlet
,JNDIRepositoryServlet
,RepositoryStartupServlet
public abstract class AbstractRepositoryServlet extends javax.servlet.http.HttpServlet
Abstract base class for servlets that make a repository available in the servlet context. This class handles the initialization and cleanup tasks of setting up and clearing the configured repository attribute, while a subclass only needs to implement the abstractgetRepository()
method that returns the actual content repository.The
Repository
instance bound to the servlet context is actually aProxyRepository
for late binding of the underlying content repository.The default name of the repository attribute is "
javax.jcr.Repository
", but it can be changed by specifying an init parameter with the same name:<servlet> <init-param> <param-name>javax.jcr.Repository</param-name> <param-value>my.repository.attribute</param-value> <description> This init parameter causes the repository to be looked up from the "my.repository.attribute" attribute instead of the default "javax.jcr.Repository". </description> </init-param> </servlet>
A repository servlet can also be mapped to the URL space. See the
doGet(HttpServletRequest, HttpServletResponse)
method for the details of the default behavior.- Since:
- 1.4
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractRepositoryServlet()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
destroy()
Removes the repository attribute from the servlet context.protected void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Outputs the repository descriptors either as a collection of properties (seeProperties.store(java.io.OutputStream, String)
or individually addressable text/plain resources based on the request URI.protected String
getAttributeName()
Returns the name of the repository attribute.protected String
getInitParameter(String name, String def)
Utility method that returns the named init parameter or the given default value if the parameter does not exist.protected abstract Repository
getRepository()
Returns the repository that will be used by theProxyRepository
bound to the servlet context.void
init()
Binds aProxyRepository
with the repository returned bygetRepository()
in the configured servlet context attribute.-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
-
-
-
Method Detail
-
init
public void init() throws javax.servlet.ServletException
Binds aProxyRepository
with the repository returned bygetRepository()
in the configured servlet context attribute.- Overrides:
init
in classjavax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
-
destroy
public void destroy()
Removes the repository attribute from the servlet context.- Specified by:
destroy
in interfacejavax.servlet.Servlet
- Overrides:
destroy
in classjavax.servlet.GenericServlet
-
getRepository
protected abstract Repository getRepository() throws RepositoryException
Returns the repository that will be used by theProxyRepository
bound to the servlet context.- Returns:
- repository
- Throws:
RepositoryException
- if the repository could not be created
-
getAttributeName
protected String getAttributeName()
Returns the name of the repository attribute. The default implementation returns "javax.jcr.Repository
" or the value of the "javax.jcr.Repository
" init parameter.A subclass can override this method to customize the attribute name, but for consistency it is generally better not to do that.
- Returns:
- name of the repository attribute
-
getInitParameter
protected String getInitParameter(String name, String def)
Utility method that returns the named init parameter or the given default value if the parameter does not exist.- Parameters:
name
- name of the init parameterdef
- default value- Returns:
- value of the init parameter, or the default value
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Outputs the repository descriptors either as a collection of properties (seeProperties.store(java.io.OutputStream, String)
or individually addressable text/plain resources based on the request URI.A typical mapping for a repository servlet would be:
<servlet-mapping> <servlet-name>Repository</servlet-name> <url-pattern>/repository/*</url-pattern> </servlet-mapping>
This mapping would allow clients to retrieve all repository descriptors from
http://server/context/repository/
and to address individual descriptors by key with URIs likehttp://server/context/repository/key
. For example, the name of the repository vendor could be retrieved fromhttp://server/context/repository/jcr.repository.vendor
. Likewise, a 404 (not found) response fromhttp://server/context/repository/level.2.supported
would indicate that the repository does not support Level 2 features.Note that mapping a repository servlet to the URL space is optional, as the main purpose of the servlet is to make a repository available in the servlet context, not to expose repository information to web clients.
- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Parameters:
request
- HTTP requestresponse
- HTTP response- Throws:
IOException
- on IO errorsjavax.servlet.ServletException
- on servlet errors
-
-