jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r558192 - in /jackrabbit/trunk/jackrabbit-webapp/src/main: java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java webapp/WEB-INF/web.xml
Date Fri, 20 Jul 2007 23:04:14 GMT
Author: jukka
Date: Fri Jul 20 16:04:13 2007
New Revision: 558192

URL: http://svn.apache.org/viewvc?view=rev&rev=558192
Log:
JCR-1016: Allow RepositoryAccessServlet to get the Repository from a ServletContext attribute
    - Applied patch from Bertrand Delacretaz

Modified:
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
    jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java?view=diff&rev=558192&r1=558191&r2=558192
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
Fri Jul 20 16:04:13 2007
@@ -67,7 +67,12 @@
      * the initialized initial context
      */
     private InitialContext jndiContext;
-
+    
+    /**
+     * if this is set we try to get a Repository from the ServletContext
+     */
+    private String repositoryContextAttributeName;
+    
     /**
      * the repository
      */
@@ -87,6 +92,9 @@
             throw new ServletException("Only one repository access servlet allowed per web-app.");
         }
         getServletContext().setAttribute(CTX_PARAM_THIS, this);
+        
+        repositoryContextAttributeName = getServletConfig().getInitParameter("repository.context.attribute.name");
+            
         log.info("RepositoryAccessServlet initialized.");
     }
 
@@ -96,7 +104,13 @@
      * @return this servlet
      */
     private static RepositoryAccessServlet getInstance(ServletContext ctx) {
-        return (RepositoryAccessServlet) ctx.getAttribute(CTX_PARAM_THIS);
+        final RepositoryAccessServlet instance = (RepositoryAccessServlet) ctx.getAttribute(CTX_PARAM_THIS);
+        if(instance==null) {
+            throw new IllegalStateException(
+                "No RepositoryAccessServlet instance in ServletContext, RepositoryAccessServlet
servlet not initialized?"
+            );
+        }
+        return instance;
     }
 
     /**
@@ -236,6 +250,25 @@
             return null;
         }
     }
+    
+    /**
+     *  If our config said so, try to retrieve a Repository from the ServletContext 
+     */
+    protected Repository getRepositoryByContextAttribute() {
+        Repository result = null;
+        if(repositoryContextAttributeName!=null) {
+            result = (Repository)getServletContext().getAttribute(repositoryContextAttributeName);
+            
+            if(log.isDebugEnabled()) {
+                if(result!=null) {
+                    log.debug("Got Repository from ServletContext attribute '" + repositoryContextAttributeName
+ "'");
+                } else {
+                    log.debug("ServletContext attribute '" + repositoryContextAttributeName
+ "' does not provide a Repository");
+                }
+            }
+        }
+        return result;
+    }
 
     /**
      * Return the fully qualified name of the class providing the client
@@ -256,6 +289,10 @@
      */
     public Repository getRepository() {
         try {
+            if (repository == null) {
+                // try to get via context attribute
+                repository = getRepositoryByContextAttribute();
+            }
             if (repository == null) {
                 // try to retrieve via jndi
                 repository = getRepositoryByJNDI();

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml?view=diff&rev=558192&r1=558191&r2=558192
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml (original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml Fri Jul 20 16:04:13
2007
@@ -149,6 +149,17 @@
                 places the one in the bootstrap-config wins.
             </description>
         </init-param>
+        <!-- 
+        <init-param>
+          <param-name>repository.context.attribute.name</param-name>
+          <param-value>javax.jcr.Repository</param-value>
+          <description>
+            If this is set, the RepositoryAccessServlet expects a Repository in the ServletContext

+            attribute having this name. This allows servlets of this module to be used with
repositories
+            intialized by the jackrabbit-jcr-servlet module utilities.
+          </description>
+        </init-param>
+         -->
         <!--
         <init-param>
             <param-name>repository-name</param-name>



Mime
View raw message