Class 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 abstract getRepository() method that returns the actual content repository.

    The Repository instance bound to the servlet context is actually a ProxyRepository 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 Detail

      • AbstractRepositoryServlet

        public AbstractRepositoryServlet()
    • Method Detail

      • init

        public void init()
                  throws javax.servlet.ServletException
        Binds a ProxyRepository with the repository returned by getRepository() in the configured servlet context attribute.
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • 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
      • 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