You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/11/14 10:09:31 UTC

svn commit: r344087 - in /lenya/trunk/src: java/org/apache/lenya/cms/ac/ java/org/apache/lenya/cms/cocoon/components/context/ webapp/WEB-INF/

Author: andreas
Date: Mon Nov 14 01:09:22 2005
New Revision: 344087

URL: http://svn.apache.org/viewcvs?rev=344087&view=rev
Log:
Added ContextUtility to allow the DocumentPolicyManagerWrapper to access the context on demand. This fixes bug #36494. Credits to Felix Roethenbacher.

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/context/
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/context/ContextUtility.java
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/ac/DocumentPolicyManagerWrapper.java
    lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl

Modified: lenya/trunk/src/java/org/apache/lenya/cms/ac/DocumentPolicyManagerWrapper.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/DocumentPolicyManagerWrapper.java?rev=344087&r1=344086&r2=344087&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ac/DocumentPolicyManagerWrapper.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/DocumentPolicyManagerWrapper.java Mon Nov 14 01:09:22 2005
@@ -19,20 +19,20 @@
 
 package org.apache.lenya.cms.ac;
 
+import java.util.Map;
+
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.parameters.ParameterException;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.avalon.framework.service.Serviceable;
-import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.components.CocoonComponentManager;
+import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.Accreditable;
@@ -42,6 +42,7 @@
 import org.apache.lenya.ac.impl.DefaultAccessController;
 import org.apache.lenya.ac.impl.DefaultPolicy;
 import org.apache.lenya.ac.impl.InheritingPolicyManager;
+import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentIdentityMap;
 import org.apache.lenya.cms.publication.Publication;
@@ -54,7 +55,7 @@
  * URL, e.g. <code>/foo/bar_de.print.html</code> is mapped to <code>/foo/bar</code>.
  */
 public class DocumentPolicyManagerWrapper extends AbstractLogEnabled implements
-        InheritingPolicyManager, Serviceable, Configurable, Disposable, Contextualizable {
+        InheritingPolicyManager, Serviceable, Configurable, Disposable {
 
     /**
      * Ctor.
@@ -77,11 +78,14 @@
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Resolving policy for webapp URL [" + webappUrl + "]");
         }
-
+        
+        
         Publication publication = getPublication(webappUrl);
         String url = null;
+        ContextUtility contextUtility = null;
         try {
-            Session session = RepositoryUtil.getSession(this.request, getLogger());
+            contextUtility = (ContextUtility)serviceManager.lookup(ContextUtility.ROLE);
+            Session session = RepositoryUtil.getSession(contextUtility.getRequest(), getLogger());
             DocumentIdentityMap map = new DocumentIdentityMap(session,
                     getServiceManager(),
                     getLogger());
@@ -95,8 +99,14 @@
                     }
                 }
             }
+        } catch (ServiceException e) {
+            throw new AccessControlException("Error looking up ContextUtility component", e);
         } catch (Exception e) {
             throw new AccessControlException(e);
+        } finally {
+            if (contextUtility != null) {
+                serviceManager.release(contextUtility);
+            }
         }
 
         if (url == null) {
@@ -290,11 +300,4 @@
             throws AccessControlException {
         getPolicyManager().accreditableAdded(manager, accreditable);
     }
-
-    private Request request;
-
-    public void contextualize(Context context) throws ContextException {
-        this.request = ContextHelper.getRequest(context);
-    }
-
 }

Added: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/context/ContextUtility.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/context/ContextUtility.java?rev=344087&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/context/ContextUtility.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/context/ContextUtility.java Mon Nov 14 01:09:22 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.lenya.cms.cocoon.components.context;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Response;
+
+/**
+ * Utility class for getting the context, request, response and
+ * object model of the current request.
+ */
+public class ContextUtility extends AbstractLogEnabled implements
+        Component, Contextualizable {
+    public static final String ROLE = ContextUtility.class.getName();
+
+    protected Context context;
+
+    
+    /**
+     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+     */
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    /**
+     * Get the context object of the current request.
+     * @return The context object of the current request.
+     */
+    public Context getContext() {
+        return context;
+    }
+    
+    /**
+     * Get the request object of the current request.
+     * @return The request object of the current request.
+     */
+    public Request getRequest() {
+        return ContextHelper.getRequest(context);
+    }
+    
+    /**
+     * Get the response object of the current request.
+     * @return The response object of the current request.
+     */
+    public Response getResponse() {
+        return ContextHelper.getResponse(context);
+    }
+    
+    /**
+     * Get the object model of the current request.
+     * @return The object model of the current request.
+     */
+    public Map getObjectModel() {
+        return ContextHelper.getObjectModel(context);
+    }
+}

Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?rev=344087&r1=344086&r2=344087&view=diff
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Mon Nov 14 01:09:22 2005
@@ -571,6 +571,10 @@
   <component role="org.apache.cocoon.components.cron.CronJob/usecase"
              class="org.apache.lenya.cms.usecase.scheduling.UsecaseCronJob"
              logger="cron.usecase"/>
+
+  <component role="org.apache.lenya.cms.cocoon.components.context.ContextUtility"
+             logger="lenya.cocoon.components"
+             class="org.apache.lenya.cms.cocoon.components.context.ContextUtility"/>
              
   <site-managers>
     <component-instance name="simple" logger="lenya.site"



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org