org.apache.jackrabbit.servlet
Class AbstractRepositoryServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.apache.jackrabbit.servlet.AbstractRepositoryServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ContextRepositoryServlet, JackrabbitRepositoryServlet, JNDIRepositoryServlet, RemoteRepositoryServlet, 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 abstract #getRepositoryFactory() method that returns a factory for retrieving the actual content repository.

The Repository instance bound to the servlet context is actually a ProxyRepository that uses the given RepositoryFactory 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
AbstractRepositoryServlet()
           
 
Method Summary
 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 (see Properties.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 the ProxyRepository bound to the servlet context.
 void init()
          Binds a ProxyRepository with the factory returned by #getRepositoryFactory() in the configured servlet context attribute.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRepositoryServlet

public AbstractRepositoryServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Binds a ProxyRepository with the factory returned by #getRepositoryFactory() in the configured servlet context attribute.

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException - if the factory could not be retrieved

destroy

public void destroy()
Removes the repository attribute from the servlet context.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

getRepository

protected abstract Repository getRepository()
                                     throws RepositoryException
Returns the repository that will be used by the ProxyRepository 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 parameter
def - 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 (see Properties.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 like http://server/context/repository/key. For example, the name of the repository vendor could be retrieved from http://server/context/repository/jcr.repository.vendor. Likewise, a 404 (not found) response from http://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 class javax.servlet.http.HttpServlet
Parameters:
request - HTTP request
response - HTTP response
Throws:
IOException - on IO errors
javax.servlet.ServletException - on servlet errors


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.