cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r487353 - in /cocoon/trunk/blocks/cocoon-portal: cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/ cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ cocoon-portal-impl/src/main/java/org/apache...
Date Thu, 14 Dec 2006 21:19:05 GMT
Author: cziegeler
Date: Thu Dec 14 13:19:04 2006
New Revision: 487353

URL: http://svn.apache.org/viewvc?view=rev&rev=487353
Log:
Split up profile preparation into several methods

Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspect.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspectContext.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/PageLabelProfileManagerAspect.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/support/ProfileManagerAspectContextImpl.java
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/TestProfileManager.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java?view=diff&rev=487353&r1=487352&r2=487353
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/AbstractProfileManager.java
Thu Dec 14 13:19:04 2006
@@ -188,13 +188,71 @@
     /**
      * Process a freshly loaded profile.
      */
-    protected Profile processProfile(Profile profile) {
-        // FIXME we should add the calls to prepareObject here as well
+    protected Collection processCopletTypes(Collection copletTypes)
+    throws LayoutException {
+        Collection result = copletTypes;
         if ( this.chain.hasAspects() ) {
-            ProfileManagerAspectContextImpl aspectContext = new ProfileManagerAspectContextImpl(this.portalService,
this.chain);
-            aspectContext.invokeNext(profile);
+            final ProfileManagerAspectContextImpl aspectContext = new ProfileManagerAspectContextImpl(this.portalService,
+                                                                                        
             this.chain,
+                                                                                        
             ProfileManagerAspectContextImpl.PHASE_COPLET_TYPES);
+            aspectContext.invokeNext(copletTypes);
+            result = (Collection)aspectContext.getResult();
         }
-        return profile;
+        this.prepareObject(null, result);
+        return result;
+    }
+
+    /**
+     * Process a freshly loaded profile.
+     */
+    protected Collection processCopletDefinitions(Collection copletDefinitions)
+    throws LayoutException {
+        Collection result = copletDefinitions;
+        if ( this.chain.hasAspects() ) {
+            final ProfileManagerAspectContextImpl aspectContext = new ProfileManagerAspectContextImpl(this.portalService,
+                                                                                        
             this.chain,
+                                                                                        
             ProfileManagerAspectContextImpl.PHASE_COPLET_DEFINITIONS);
+            aspectContext.invokeNext(copletDefinitions);
+            result = (Collection)aspectContext.getResult();
+        }
+        this.prepareObject(null, result);
+        return result;
+    }
+
+    /**
+     * Process a freshly loaded profile.
+     * TODO Why do we need the profile?
+     */
+    protected Collection processCopletInstances(Profile profile, Collection copletInstances)
+    throws LayoutException {
+        Collection result = copletInstances;
+        if ( this.chain.hasAspects() ) {
+            final ProfileManagerAspectContextImpl aspectContext = new ProfileManagerAspectContextImpl(this.portalService,
+                                                                                        
             this.chain,
+                                                                                        
             ProfileManagerAspectContextImpl.PHASE_COPLET_INSTANCES);
+            aspectContext.invokeNext(copletInstances);
+            result = (Collection)aspectContext.getResult();
+        }
+        this.prepareObject(profile, result);
+        return result;
+    }
+
+    /**
+     * Process a freshly loaded profile.
+     * TODO Why do we need the profile?
+     */
+    protected Layout processLayout(Profile profile, Layout layout)
+    throws LayoutException {
+        Layout result = layout;
+        if ( this.chain.hasAspects() ) {
+            final ProfileManagerAspectContextImpl aspectContext = new ProfileManagerAspectContextImpl(this.portalService,
+                                                                                        
             this.chain,
+                                                                                        
             ProfileManagerAspectContextImpl.PHASE_COPLET_LAYOUT);
+            aspectContext.invokeNext(layout);
+            result = (Layout)aspectContext.getResult();
+        }
+        this.prepareObject(profile, result);
+        return result;
     }
 
     /**

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java?view=diff&rev=487353&r1=487352&r2=487353
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/profile/impl/GroupBasedProfileManager.java
Thu Dec 14 13:19:04 2006
@@ -333,17 +333,16 @@
         } catch (Exception e) {
             throw new ProfileException("Unable to load profile '" + defaultProfileName +
"' for user " + user + ".", e);
         }
-        final Profile processedProfile = this.processProfile(profile);
-        this.storeUserProfile(processedProfile);
-        return processedProfile;
+        this.storeUserProfile(profile);
+        return profile;
     }
 
     protected void loadProfile(ProfileImpl profile, PortalUser user, String profileName)
     throws ProfileException {
         try {
-            if ( !this.getCopletInstanceDatas(profile, user, CATEGORY_USER, profileName)
) {
-                if ( user.getGroups().size() == 0 || !this.getCopletInstanceDatas(profile,
user, CATEGORY_GROUP, profileName)) {
-                    if ( !this.getCopletInstanceDatas(profile, user, CATEGORY_GLOBAL, profileName)
) {
+            if ( !this.getCopletInstances(profile, user, CATEGORY_USER, profileName) ) {
+                if ( user.getGroups().size() == 0 || !this.getCopletInstances(profile, user,
CATEGORY_GROUP, profileName)) {
+                    if ( !this.getCopletInstances(profile, user, CATEGORY_GLOBAL, profileName)
) {
                         throw new ProcessingException("No profile for copletinstancedatas
found.");
                     }
                 }
@@ -401,8 +400,10 @@
 
         // we have to load/reload
         synchronized ( this ) {
+            Collection collection = (Collection)loader.loadProfile(key, ProfileLS.PROFILETYPE_COPLETTYPE,
null);
+            collection = this.processCopletTypes(collection);
             final Map objects = new HashMap();
-            final Iterator i = ((Collection)loader.loadProfile(key, ProfileLS.PROFILETYPE_COPLETTYPE,
null)).iterator();
+            final Iterator i = collection.iterator();
             while ( i.hasNext() ) {
                 final CopletType current = (CopletType)i.next();
                 objects.put(current.getId(), current);
@@ -415,7 +416,7 @@
             // now invalidate coplet definitions
             this.copletDefinitions.objects = null;
             this.copletDefinitions.validity = null;
-            this.prepareObject(null, this.copletTypes.objects);
+
             return this.copletTypes.objects;
         }
     }
@@ -451,8 +452,10 @@
         }
 
         synchronized ( this ) {
+            Collection collection = (Collection)loader.loadProfile(key, ProfileLS.PROFILETYPE_COPLETDEFINITION,
profile.getCopletTypesMap());
+            collection = this.processCopletDefinitions(collection);
+            final Iterator i = collection.iterator();
             final Map objects = new HashMap();
-            final Iterator i = ((Collection)loader.loadProfile(key, ProfileLS.PROFILETYPE_COPLETDEFINITION,
profile.getCopletTypesMap())).iterator();
             while ( i.hasNext() ) {
                 final CopletDefinition current = (CopletDefinition)i.next();
                 // only add coplet data if coplet base data has been found
@@ -469,7 +472,7 @@
                 newValidity = loader.getValidity(key, ProfileLS.PROFILETYPE_COPLETDEFINITION);
             }
             this.copletDefinitions.validity = newValidity;
-            this.prepareObject(profile, this.copletDefinitions.objects);
+
             return this.copletDefinitions.objects;
         }
     }
@@ -485,10 +488,10 @@
         return false;
     }
 
-    protected boolean getCopletInstanceDatas(final ProfileImpl profile,
-                                             final PortalUser  info,
-                                             final String      category,
-                                             final String      layoutKey)
+    protected boolean getCopletInstances(final ProfileImpl profile,
+                                         final PortalUser  info,
+                                         final String      category,
+                                         final String      layoutKey)
     throws Exception {
         Map key = this.buildKey(category,
                                 ProfileLS.PROFILETYPE_COPLETINSTANCE,
@@ -497,8 +500,8 @@
                                 layoutKey);
         try {
             Collection cidm = (Collection)loader.loadProfile(key, ProfileLS.PROFILETYPE_COPLETINSTANCE,
profile.getCopletDefinitionsMap());
+            cidm = this.processCopletInstances(profile, cidm);
             profile.setCopletInstances(cidm);
-            this.prepareObject(profile, profile.getCopletInstancesMap());
 
             return true;
         } catch (Exception e) {
@@ -521,7 +524,7 @@
                                       layoutKey);
         try {
             Layout l = (Layout)loader.loadProfile(key, ProfileLS.PROFILETYPE_LAYOUT, profile.getCopletInstancesMap());
-            this.prepareObject(profile, l);
+            l = this.processLayout(profile, l);
             profile.setRootLayout(l);
 
             return true;

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspect.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspect.java?view=diff&rev=487353&r1=487352&r2=487353
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspect.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspect.java
Thu Dec 14 13:19:04 2006
@@ -16,7 +16,9 @@
  */
 package org.apache.cocoon.portal.services.aspects;
 
-import org.apache.cocoon.portal.scratchpad.Profile;
+import java.util.Collection;
+
+import org.apache.cocoon.portal.om.Layout;
 
 /**
  * The behaviour of the used profile manager can be extended by assigning one
@@ -27,6 +29,35 @@
  */
 public interface ProfileManagerAspect {
 
-    void prepare(ProfileManagerAspectContext context,
-                 Profile profile);
+    /**
+     * Prepare the coplet types directly after loading.
+     * @param context
+     * @param copletTypes
+     */
+    void prepareCopletTypes(ProfileManagerAspectContext context,
+                            Collection copletTypes);
+                 
+    /**
+     * Prepare the coplet definitions directly after loading.
+     * @param context
+     * @param copletDefinitions
+     */
+    void prepareCopletDefinitions(ProfileManagerAspectContext context,
+                                  Collection copletDefinitions);
+
+    /**
+     * Prepare the coplet instances directly after loading.
+     * @param context
+     * @param copletInstances
+     */
+    void prepareCopletInstances(ProfileManagerAspectContext context,
+                                Collection copletInstances);
+
+    /**
+     * Prepare the layout directly after loading.
+     * @param context
+     * @param layout
+     */
+    void prepareLayout(ProfileManagerAspectContext context,
+                       Layout layout);
 }

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspectContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspectContext.java?view=diff&rev=487353&r1=487352&r2=487353
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspectContext.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/ProfileManagerAspectContext.java
Thu Dec 14 13:19:04 2006
@@ -16,8 +16,6 @@
  */
 package org.apache.cocoon.portal.services.aspects;
 
-import org.apache.cocoon.portal.scratchpad.Profile;
-
 /**
  * The context for a {@link  ProfileManagerAspect}.
  *
@@ -29,5 +27,5 @@
     /**
      * Invoke next aspect .
      */
-    void invokeNext(Profile profile);
+    void invokeNext(Object object);
 }

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/PageLabelProfileManagerAspect.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/PageLabelProfileManagerAspect.java?view=diff&rev=487353&r1=487352&r2=487353
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/PageLabelProfileManagerAspect.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/PageLabelProfileManagerAspect.java
Thu Dec 14 13:19:04 2006
@@ -16,12 +16,13 @@
  */
 package org.apache.cocoon.portal.services.aspects.impl;
 
+import java.util.Collection;
+
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.portal.om.CompositeLayout;
 import org.apache.cocoon.portal.om.Item;
 import org.apache.cocoon.portal.om.Layout;
 import org.apache.cocoon.portal.om.NamedItem;
-import org.apache.cocoon.portal.scratchpad.Profile;
 import org.apache.cocoon.portal.services.aspects.ProfileManagerAspect;
 import org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext;
 
@@ -32,17 +33,37 @@
     implements ProfileManagerAspect, ThreadSafe {
 
     /**
-     * @see org.apache.cocoon.portal.services.aspects.ProfileManagerAspect#prepare(org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext,
org.apache.cocoon.portal.scratchpad.Profile)
+     * @see org.apache.cocoon.portal.services.aspects.ProfileManagerAspect#prepareCopletDefinitions(org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext,
java.util.Collection)
+     */
+    public void prepareCopletDefinitions(ProfileManagerAspectContext context, Collection
copletDefinitions) {
+        context.invokeNext(copletDefinitions);
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.services.aspects.ProfileManagerAspect#prepareCopletInstances(org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext,
java.util.Collection)
+     */
+    public void prepareCopletInstances(ProfileManagerAspectContext context, Collection copletInstances)
{
+        context.invokeNext(copletInstances);
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.services.aspects.ProfileManagerAspect#prepareCopletTypes(org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext,
java.util.Collection)
+     */
+    public void prepareCopletTypes(ProfileManagerAspectContext context, Collection copletTypes)
{
+        context.invokeNext(copletTypes);
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.services.aspects.ProfileManagerAspect#prepareLayout(org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext,
org.apache.cocoon.portal.om.Layout)
      */
-    public void prepare(ProfileManagerAspectContext context, Profile profile) {
-        final Layout rootLayout = profile.getRootLayout();
+    public void prepareLayout(ProfileManagerAspectContext context, Layout rootLayout) {
         if ( rootLayout instanceof CompositeLayout ) {
             this.populate((CompositeLayout)rootLayout, "");
         }
-        context.invokeNext(profile);
+        context.invokeNext(rootLayout);
     }
 
-    private void populate(CompositeLayout layout, String name) {
+    protected void populate(CompositeLayout layout, String name) {
         for (int j = 0; j < layout.getSize(); j++) {
             final Item tab = layout.getItem(j);
             final StringBuffer label = new StringBuffer(name);

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/support/ProfileManagerAspectContextImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/support/ProfileManagerAspectContextImpl.java?view=diff&rev=487353&r1=487352&r2=487353
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/support/ProfileManagerAspectContextImpl.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/services/aspects/impl/support/ProfileManagerAspectContextImpl.java
Thu Dec 14 13:19:04 2006
@@ -16,8 +16,10 @@
  */
 package org.apache.cocoon.portal.services.aspects.impl.support;
 
+import java.util.Collection;
+
 import org.apache.cocoon.portal.PortalService;
-import org.apache.cocoon.portal.scratchpad.Profile;
+import org.apache.cocoon.portal.om.Layout;
 import org.apache.cocoon.portal.services.aspects.ProfileManagerAspect;
 import org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext;
 import org.apache.cocoon.portal.services.aspects.support.AspectChain;
@@ -26,24 +28,46 @@
 /**
  * The aspect context is passed to every aspect.
  * @since 2.2
+ *
  * @version $Id$
  */
 public final class ProfileManagerAspectContextImpl
     extends BasicAspectContextImpl
     implements ProfileManagerAspectContext {
 
+    public static final int PHASE_COPLET_TYPES = 0;
+    public static final int PHASE_COPLET_DEFINITIONS = 1;
+    public static final int PHASE_COPLET_INSTANCES =2;
+    public static final int PHASE_COPLET_LAYOUT = 3;
+
+    protected int phase;
+    protected Object result;
+
     public ProfileManagerAspectContextImpl(PortalService service,
-                                              AspectChain   chain) {
+                                           AspectChain   chain,
+                                           int           phase) {
         super(service, chain);
     }
 
-	/**
-	 * @see org.apache.cocoon.portal.services.aspects.ProfileManagerAspectContext#invokeNext(org.apache.cocoon.portal.scratchpad.Profile)
-	 */
-	public void invokeNext(Profile portalProfile) {
+	public void invokeNext(Object object) {
         final ProfileManagerAspect aspect = (ProfileManagerAspect)this.getNext();
         if ( aspect != null ) {
-            aspect.prepare(this, portalProfile);
+            switch (phase) {
+                case PHASE_COPLET_TYPES : aspect.prepareCopletTypes(this, (Collection)object);
+                                          break;
+                case PHASE_COPLET_DEFINITIONS : aspect.prepareCopletDefinitions(this, (Collection)object);
+                                                break;
+                case PHASE_COPLET_INSTANCES : aspect.prepareCopletInstances(this, (Collection)object);
+                                              break;
+                case PHASE_COPLET_LAYOUT : aspect.prepareLayout(this, (Layout)object);
+                                           break;
+            }
+        } else {
+            this.result = object;
         }
+    }
+
+    public Object getResult() {
+        return this.result;
     }
 }

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/TestProfileManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/TestProfileManager.java?view=diff&rev=487353&r1=487352&r2=487353
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/TestProfileManager.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/TestProfileManager.java
Thu Dec 14 13:19:04 2006
@@ -102,14 +102,11 @@
                         }
                     }
                 }
-                profile.setCopletInstances(instances);
-                this.prepareObject(profile, instances);
-                this.prepareObject(profile, rootLayout);
-                profile.setRootLayout(rootLayout);
+                profile.setCopletInstances(this.processCopletInstances(profile, instances));
+                profile.setRootLayout(this.processLayout(profile, rootLayout));
     
-                final Profile processedProfile = this.processProfile(profile);    
-                this.storeUserProfile(processedProfile);
-                return processedProfile;
+                this.storeUserProfile(profile);
+                return profile;
             } catch (ProfileException e) {
                 throw e;
             } catch (Exception e) {



Mime
View raw message