cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/subscriber/impl DefaultChangeAspectDataEventSubscriber.java DefaultLayoutAspectDataEventSubscriber.java
Date Fri, 23 May 2003 14:20:10 GMT
cziegeler    2003/05/23 07:20:09

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl
                        FrameEventAspect.java
               src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        DefaultEventManager.java
               src/blocks/portal/java/org/apache/cocoon/portal/profile/impl
                        SimpleProfileManager.java
               src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl
                        FrameAspect.java TabContentAspect.java
  Added:       src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        ChangeAspectDataEvent.java
               src/blocks/portal/java/org/apache/cocoon/portal/event/subscriber/impl
                        DefaultChangeAspectDataEventSubscriber.java
  Removed:     src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        FrameSourceEvent.java LayoutAspectDataEvent.java
               src/blocks/portal/java/org/apache/cocoon/portal/event/subscriber/impl
                        DefaultLayoutAspectDataEventSubscriber.java
  Log:
  Refactoring
  
  Revision  Changes    Path
  1.4       +19 -77    cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl/FrameEventAspect.java
  
  Index: FrameEventAspect.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/aspect/impl/FrameEventAspect.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FrameEventAspect.java	22 May 2003 12:32:48 -0000	1.3
  +++ FrameEventAspect.java	23 May 2003 14:20:09 -0000	1.4
  @@ -50,8 +50,6 @@
   */
   package org.apache.cocoon.portal.event.aspect.impl;
   
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  @@ -61,13 +59,10 @@
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.portal.PortalService;
   import org.apache.cocoon.portal.event.Event;
  -import org.apache.cocoon.portal.event.EventManager;
  -import org.apache.cocoon.portal.event.Filter;
   import org.apache.cocoon.portal.event.Publisher;
  -import org.apache.cocoon.portal.event.Subscriber;
   import org.apache.cocoon.portal.event.aspect.EventAspect;
   import org.apache.cocoon.portal.event.aspect.EventAspectContext;
  -import org.apache.cocoon.portal.event.impl.FrameSourceEvent;
  +import org.apache.cocoon.portal.event.impl.ChangeAspectDataEvent;
   import org.apache.cocoon.portal.layout.Layout;
   import org.apache.cocoon.portal.profile.ProfileManager;
   
  @@ -80,7 +75,7 @@
    */
   public class FrameEventAspect
       extends AbstractLogEnabled
  -    implements EventAspect, ThreadSafe, Composable, Disposable, Subscriber, Initializable
{
  +    implements EventAspect, ThreadSafe, Composable {
   
       protected ComponentManager manager;
   
  @@ -88,7 +83,8 @@
        * @see org.apache.cocoon.portal.event.aspect.EventAspect#process(org.apache.cocoon.portal.event.aspect.EventAspectContext,
org.apache.cocoon.portal.PortalService)
        */
       public void process(EventAspectContext context, PortalService service) {
  -        final String requestParameterName = FrameSourceEvent.URI_PARAMETER;
  +        // TODO - make this configurable
  +        final String requestParameterName = "frame";
           final Request request = ObjectModelHelper.getRequest(context.getObjectModel());
           String[] values = request.getParameterValues(requestParameterName);
           if (values != null) {
  @@ -113,8 +109,20 @@
                           if (index != (value.length() - 1)) {
                               uri = value.substring(index + 1);
                           }
  -                        e = new FrameSourceEvent(id, uri);
  -                        publisher.publish(e);
  +                        
  +                        ProfileManager profileManager = null;
  +                        try {
  +                            profileManager = (ProfileManager)this.manager.lookup(ProfileManager.ROLE);
  +                            Layout layout = profileManager.getPortalLayout( id );
  +                            if ( layout != null ) {
  +                                e = new ChangeAspectDataEvent(layout, "frame", uri);
  +                                publisher.publish(e);
  +                            }
  +                        } catch (ComponentException ignore) {
  +                        } finally {
  +                            this.manager.release( profileManager );
  +                        }
  +                        
                           if (uri != null) {
                               service.getLinkService().addEventToLink(e);
                           }
  @@ -127,76 +135,10 @@
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.cocoon.portal.event.Subscriber#getEventType()
  -     */
  -    public Class getEventType() {
  -        return FrameSourceEvent.class;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.cocoon.portal.event.Subscriber#getFilter()
  -     */
  -    public Filter getFilter() {
  -        return null;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.cocoon.portal.event.Subscriber#inform(org.apache.cocoon.portal.event.Event)
  -     */
  -    public void inform(Event event) {
  -        FrameSourceEvent statusEvent = (FrameSourceEvent) event;
  -        final String layoutID = statusEvent.getLayoutId();
  -        ProfileManager profileManager = null;
  -        try {
  -            profileManager = (ProfileManager) this.manager.lookup(ProfileManager.ROLE);
  -            // TODO - does this work?
  -            Layout layout = profileManager.getPortalLayout( layoutID );
  -            String status = (String)layout.getAspectData("frame");
  -            String link = statusEvent.getLink();
  -            if (status == null) {
  -                if (link != null) {
  -                    layout.setAspectData("frame", link);
  -                }
  -            } else if (link != null) {
  -                layout.setAspectData("frame", link);
  -            }
  -        } catch (ComponentException ce) {
  -            // ignore
  -        } finally {
  -            this.manager.release(profileManager);
  -        }
  -    }
  -
  -    /* (non-Javadoc)
        * @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
        */
       public void compose(ComponentManager manager) throws ComponentException {
           this.manager = manager;
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.avalon.framework.activity.Initializable#initialize()
  -     */
  -    public void initialize() throws Exception {
  -        EventManager eventManager = null;
  -        try {
  -            eventManager = (EventManager) this.manager.lookup(EventManager.ROLE);
  -            eventManager.getRegister().subscribe(this);
  -        } finally {
  -            this.manager.release(eventManager);
  -        }
  -    }
  -
  -    public void dispose() {
  -        if (this.manager != null) {
  -            EventManager eventManager = null;
  -            try {
  -                eventManager = (EventManager) this.manager.lookup(EventManager.ROLE);
  -                eventManager.getRegister().unsubscribe(this);
  -            } catch (Exception ignore) {
  -            } finally {
  -                this.manager.release(eventManager);
  -            }
  -        }
  -    }
   }
  
  
  
  1.6       +3 -3      cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java
  
  Index: DefaultEventManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/DefaultEventManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultEventManager.java	23 May 2003 09:18:48 -0000	1.5
  +++ DefaultEventManager.java	23 May 2003 14:20:09 -0000	1.6
  @@ -80,7 +80,7 @@
   import org.apache.cocoon.portal.event.Subscriber;
   import org.apache.cocoon.portal.event.aspect.EventAspect;
   import org.apache.cocoon.portal.event.aspect.impl.SizingEventSubscriber;
  -import org.apache.cocoon.portal.event.subscriber.impl.DefaultLayoutAspectDataEventSubscriber;
  +import org.apache.cocoon.portal.event.subscriber.impl.DefaultChangeAspectDataEventSubscriber;
   import org.apache.cocoon.portal.event.subscriber.impl.DefaultLayoutEventSubscriber;
   
   /**
  @@ -156,7 +156,7 @@
   
           // FIXME (CZ,HIGH) : Make this configurable
           this.subscribe(new DefaultLayoutEventSubscriber(this.manager));
  -        this.subscribe(new DefaultLayoutAspectDataEventSubscriber(this.manager));
  +        this.subscribe(new DefaultChangeAspectDataEventSubscriber(this.manager));
           this.subscribe(new SizingEventSubscriber(this.manager));
       }
   
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java
  
  Index: ChangeAspectDataEvent.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.event.impl;
  
  import org.apache.cocoon.portal.aspect.Aspectalizable;
  import org.apache.cocoon.portal.event.Event;
  
  /**
   * This events set the aspect data for a layout object
   *
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * 
   * @version CVS $Id: ChangeAspectDataEvent.java,v 1.1 2003/05/23 14:20:09 cziegeler Exp
$
   */
  public final class ChangeAspectDataEvent
      implements Event {
  
      private Aspectalizable target;
      
      private String aspectName;
      
      private Object data;
      
      public ChangeAspectDataEvent(Aspectalizable target, String aspectName, Object data)
{
          this.target = target;
          this.aspectName = aspectName;
          this.data = data;
      }
  
      /**
       * @return
       */
      public String getAspectName() {
          return aspectName;
      }
  
      /**
       * @return
       */
      public Object getData() {
          return data;
      }
  
      /**
       * @return
       */
      public Aspectalizable getTarget() {
          return target;
      }
  
  }
  
  
  
  1.10      +41 -2     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/SimpleProfileManager.java
  
  Index: SimpleProfileManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/SimpleProfileManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SimpleProfileManager.java	23 May 2003 12:13:15 -0000	1.9
  +++ SimpleProfileManager.java	23 May 2003 14:20:09 -0000	1.10
  @@ -141,8 +141,28 @@
               }
               
               String portalPrefix = SimpleProfileManager.class.getName()+"/"+service.getPortalName();
  +            Layout layout = null;
  +
  +            if ( key != null ) {
  +                // now search for a layout
  +                Map layoutMap = (Map)service.getAttribute("layout-map");
  +                if ( layoutMap == null ) {
  +                    Object[] objects = (Object[])service.getAttribute(portalPrefix+"/Layout");
  +                    if (objects != null && objects[0] != null) {
  +                        layoutMap = new HashMap();
  +                        this.cacheLayouts(layoutMap, (Layout)objects[0]);
  +                        service.setAttribute("layout-map", layoutMap);
  +                    }
  +                }
  +                if ( layoutMap != null) {
  +                    layout = (Layout) layoutMap.get( key );
  +                    if ( layout != null) {
  +                        return layout;
  +                    }
  +                }
  +            }
  +            
   
  -			Layout layout = null;
   			Object[] objects = (Object[])service.getAttribute(portalPrefix+"/Layout");
   			if (objects != null)
   				layout = (Layout)objects[0];
  @@ -225,6 +245,25 @@
           }
       }
       
  +    /**
  +     * @param layoutMap
  +     * @param layout
  +     */
  +    private void cacheLayouts(Map layoutMap, Layout layout) {
  +        if ( layout != null ) {
  +            layoutMap.put( layout.getId(), layout );
  +            if ( layout instanceof CompositeLayout ) {
  +                CompositeLayout cl = (CompositeLayout)layout;
  +                Iterator i = cl.getItems().iterator();
  +                while ( i.hasNext() ) {
  +                    Item current = (Item)i.next();
  +                    this.cacheLayouts( layoutMap, current.getLayout() );
  +                }
  +            }
  +        }
  +        
  +    }
  +
       public void saveUserProfiles() {
   		MapSourceAdapter adapter = null;
   		PortalService service = null;
  
  
  
  1.5       +2 -3      cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/FrameAspect.java
  
  Index: FrameAspect.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/FrameAspect.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FrameAspect.java	22 May 2003 12:32:46 -0000	1.4
  +++ FrameAspect.java	23 May 2003 14:20:09 -0000	1.5
  @@ -73,8 +73,7 @@
               throw new SAXException("Wrong layout type, FrameLayout expected: " + layout.getClass().getName());
           }
   
  -        String status = (String)layout.getAspectData("frame");
  -        String source = (status == null ? null : status);
  +        String source = (String)layout.getAspectData("frame");
           if (source == null) {
               source = ((FrameLayout) layout).getSource();
           }
  
  
  
  1.6       +3 -3      cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java
  
  Index: TabContentAspect.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/TabContentAspect.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TabContentAspect.java	22 May 2003 15:19:38 -0000	1.5
  +++ TabContentAspect.java	23 May 2003 14:20:09 -0000	1.6
  @@ -55,7 +55,7 @@
   
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.cocoon.portal.PortalService;
  -import org.apache.cocoon.portal.event.impl.LayoutAspectDataEvent;
  +import org.apache.cocoon.portal.event.impl.ChangeAspectDataEvent;
   import org.apache.cocoon.portal.layout.CompositeLayout;
   import org.apache.cocoon.portal.layout.Layout;
   import org.apache.cocoon.portal.layout.NamedItem;
  @@ -112,7 +112,7 @@
                       if (j == selected) {
                           attributes.addCDATAAttribute("selected", "true");
                       } else {
  -                        LayoutAspectDataEvent event = new LayoutAspectDataEvent(tabLayout,
"tab", new Integer(j));
  +                        ChangeAspectDataEvent event = new ChangeAspectDataEvent(tabLayout,
"tab", new Integer(j));
                           attributes.addCDATAAttribute("parameter", portalService.getLinkService().getLinkURI(event));
                       }
                       XMLUtils.startElement(handler, "named-item", attributes);
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/subscriber/impl/DefaultChangeAspectDataEventSubscriber.java
  
  Index: DefaultChangeAspectDataEventSubscriber.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.event.subscriber.impl;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.cocoon.portal.aspect.Aspectalizable;
  import org.apache.cocoon.portal.event.Event;
  import org.apache.cocoon.portal.event.Filter;
  import org.apache.cocoon.portal.event.Subscriber;
  import org.apache.cocoon.portal.event.impl.ChangeAspectDataEvent;
  
  /**
   *
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * 
   * @version CVS $Id: DefaultChangeAspectDataEventSubscriber.java,v 1.1 2003/05/23 14:20:09
cziegeler Exp $
   */
  public final class DefaultChangeAspectDataEventSubscriber 
      implements Subscriber {
  
      private ComponentManager manager;
  
      public DefaultChangeAspectDataEventSubscriber(ComponentManager manager) {
          this.manager = manager;
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.portal.event.Subscriber#getEventType()
       */
      public Class getEventType() {
          return ChangeAspectDataEvent.class;
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.portal.event.Subscriber#getFilter()
       */
      public Filter getFilter() {
          return null;
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.portal.event.Subscriber#inform(org.apache.cocoon.portal.event.Event)
       */
      public void inform(Event e) {
          final ChangeAspectDataEvent event = (ChangeAspectDataEvent)e;
          final Aspectalizable target = event.getTarget();
          target.setAspectData(event.getAspectName(), event.getData());
      }
  
  }
  
  
  

Mime
View raw message