svn commit: r778147 - /lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Sun May 24 13:43:25 2009
New Revision: 778147

URL: http://svn.apache.org/viewvc?rev=778147&view=rev
Log:
Allow to pass pubId and area params to AccessControlSitetreeTransformer. The parameters are deprecated, they should be removed after the consolidation of the sitetree processing.

Modified:
    lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java

Modified: lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java?rev=778147&r1=778146&r2=778147&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/AccessControlSitetreeTransformer.java Sun May 24 13:43:25 2009
@@ -56,6 +56,16 @@
      */
     public static final String ATTRIBUTE_PROTECTED = "protected";
 
+    /**
+     * @deprecated, subject to removal in the next release.
+     */
+    public static final String PARAM_PUB_ID = "publication-id";
+
+    /**
+     * @deprecated, subject to removal in the next release.
+     */
+    public static final String PARAM_AREA = "area";
+
     private ServiceSelector serviceSelector;
     private PolicyManager policyManager;
     private AccessControllerResolver acResolver;
@@ -88,6 +98,9 @@
                 getLogger().debug("    Identity:       [" + this.identity + "]");
             }
 
+            this.area = par.getParameter(PARAM_AREA, null);
+            this.pubId = par.getParameter(PARAM_PUB_ID, null);
+
             this.serviceSelector = (ServiceSelector) this.manager
                     .lookup(AccessControllerResolver.ROLE + "Selector");
 
@@ -134,36 +147,16 @@
         Attributes attributes = attr;
 
         if (isFragmentElement(uri, localName)) {
-            this.pubId = attr.getValue(SitetreeFragmentGenerator.ATTR_PUBLICATION);
-            Assert.notNull("publication attribute", this.pubId);
-
-            String area = attr.getValue("area");
-            if (area != null) {
-                this.area = area;
-            }
-
-            String basePath = attr.getValue(SitetreeFragmentGenerator.ATTR_BASE);
-            this.basePath = basePath == null ? "" : basePath;
-
-            try {
-                AccessController accessController = this.acResolver.resolveAccessController("/"
-                        + this.pubId + "/");
-                this.accreditableManager = accessController.getAccreditableManager();
-                this.policyManager = accessController.getPolicyManager();
-            } catch (AccessControlException e) {
-                throw new SAXException(e);
-            }
-
+            extractContext(attr);
         } else if (isSiteElement(uri, localName)) {
-            this.area = attr.getValue("area");
-            Assert.notNull("area attribute", this.area);
+            extractContext(attr);
         } else if (isNodeElement(uri, localName)) {
             String id = attr.getValue(SitetreeFragmentGenerator.ATTR_ID);
             Assert.notNull("id attribute", id);
             this.pathElements.push(id);
 
             try {
-                Role[] roles = this.policyManager.getGrantedRoles(this.accreditableManager,
+                Role[] roles = getPolicyManager().getGrantedRoles(getAccreditableManager(),
                         this.identity, getUrl());
                 if (roles.length == 0 || roles.length == 1 && roles[0].getId().equals("session")) {
                     AttributesImpl attributesImpl = new AttributesImpl(attributes);
@@ -179,6 +172,54 @@
         super.startElement(uri, localName, raw, attributes);
     }
 
+    protected AccreditableManager getAccreditableManager() throws SAXException {
+        initAccessController();
+        return this.accreditableManager;
+    }
+
+    protected void extractContext(Attributes attr) {
+        extractPubId(attr);
+        extractArea(attr);
+        extractBasePath(attr);
+    }
+
+    protected void extractBasePath(Attributes attr) {
+        String basePath = attr.getValue(SitetreeFragmentGenerator.ATTR_BASE);
+        this.basePath = basePath == null ? "" : basePath;
+    }
+
+    protected void extractPubId(Attributes attr) {
+        String pubIdAttr = attr.getValue(SitetreeFragmentGenerator.ATTR_PUBLICATION);
+        if (pubIdAttr != null) {
+            this.pubId = pubIdAttr;
+        }
+    }
+
+    protected void initAccessController() throws SAXException {
+        if (this.accreditableManager == null) {
+            try {
+                AccessController accessController = this.acResolver.resolveAccessController("/"
+                        + this.pubId + "/");
+                this.accreditableManager = accessController.getAccreditableManager();
+                this.policyManager = accessController.getPolicyManager();
+            } catch (AccessControlException e) {
+                throw new SAXException(e);
+            }
+        }
+    }
+
+    protected void extractArea(Attributes attr) {
+        String area = attr.getValue(SitetreeFragmentGenerator.ATTR_AREA);
+        if (area != null) {
+            this.area = area;
+        }
+    }
+
+    protected PolicyManager getPolicyManager() throws SAXException {
+        initAccessController();
+        return this.policyManager;
+    }
+
     protected String getUrl() {
         Assert.notNull("pub ID", this.pubId);
         Assert.notNull("area", this.area);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.