All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.jackrabbit.servlet.ServletRepository Maven / Gradle / Ivy

Go to download

Servlets and related classes for easy use of JCR content repositories in web applications.

There is a newer version: 2.13.4
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.servlet;

import javax.servlet.FilterConfig;
import javax.servlet.GenericServlet;

import org.apache.jackrabbit.commons.repository.ProxyRepository;

/**
 * Proxy for a repository bound in servlet context. The configured repository
 * attribute is looked up from the servlet context during each method call.
 * Thus the repository does not need to exist when this class is instantiated.
 * The repository can also be replaced with another repository during the
 * lifetime of an instance of this class.
 * 

* A typical way to use this class would be: *

 * public class MyServlet extends HttpServlet {
 *
 *     private final Repository repository = new ServletRepository(this);
 *
 *     protected void doGet(
 *             HttpServletRequest request, HttpServletResponse response)
 *             throws ServletException, IOException {
 *          try {
 *              Session session = repository.login();
 *              try {
 *                  ...;
 *              } finally {
 *                  session.logout();
 *              }
 *          } catch (RepositoryException e) {
 *              throw new ServletException(e);
 *          }
 *      }
 *
 * }
 * 
*

* Starting with version 1.6 this class can also be used by a servlet filter: *

 * public class MyFilter implements Filter {
 *
 *     private Repository repository;
 *
 *     public void init(FilterConfig config) {
 *         repository = new ServletRepository(config);
 *     }
 *
 *     // ...
 *
 * }
 * 
* * @since 1.4 * @see ServletRepositoryFactory * @see FilterRepositoryFactory */ public class ServletRepository extends ProxyRepository { /** * Creates a proxy for a repository found in the context of the given * servlet. * * @param servlet servlet */ public ServletRepository(GenericServlet servlet) { super(new ServletRepositoryFactory(servlet)); } /** * Creates a proxy for a repository found in the servlet context * associated with the given filter configuration. * * @since Apache Jackrabbit 1.6 * @param config filter configuration */ public ServletRepository(FilterConfig config) { super(new FilterRepositoryFactory(config)); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy