You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/05/26 12:34:53 UTC

cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event CopletInstanceEvent.java

cziegeler    2003/05/26 03:34:53

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl
                        URICopletAdapter.java
               src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        ChangeAspectDataEvent.java
  Added:       src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        ChangeCopletInstanceAspectDataEvent.java
               src/blocks/portal/java/org/apache/cocoon/portal/event
                        CopletInstanceEvent.java
  Log:
  Adding parameter filtering
  
  Revision  Changes    Path
  1.8       +79 -6     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java
  
  Index: URICopletAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/URICopletAdapter.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- URICopletAdapter.java	26 May 2003 10:15:01 -0000	1.7
  +++ URICopletAdapter.java	26 May 2003 10:34:52 -0000	1.8
  @@ -51,9 +51,12 @@
   package org.apache.cocoon.portal.coplet.adapter.impl;
   
   import java.io.IOException;
  +import java.util.ArrayList;
   import java.util.HashMap;
  +import java.util.List;
   
   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.cocoon.ProcessingException;
  @@ -61,6 +64,11 @@
   import org.apache.cocoon.portal.Constants;
   import org.apache.cocoon.portal.PortalService;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
  +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.Subscriber;
  +import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceResolver;
   import org.xml.sax.ContentHandler;
  @@ -76,7 +84,7 @@
    */
   public class URICopletAdapter 
       extends AbstractCopletAdapter
  -    implements Disposable {
  +    implements Disposable, Subscriber, Initializable {
   	
       /** The source resolver */
       protected SourceResolver resolver;
  @@ -98,18 +106,27 @@
   		PortalService portalService = null;
   		try {
   			if (uri.startsWith("cocoon:")) {
  +                portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
  +
                   Boolean handlePars = (Boolean)this.getConfiguration( coplet, "handleParameters");
                   
                   String sourceUri = uri;
                   
                   if ( handlePars != null && handlePars.booleanValue() ) {
  -                    // remove parameters
  -                    if (!uri.startsWith("cocoon:raw:") ) {
  -                        sourceUri = "cocoon:raw:" + uri.substring(7);
  +                    List list = (List) portalService.getAttribute(URICopletAdapter.class.getName());
  +                    if ( list != null && list.contains( coplet )) {
  +                        // add parameters
  +                        if ( uri.startsWith("cocoon:raw:") ) {
  +                            sourceUri = "cocoon:" + uri.substring(11); 
  +                        }
  +                    } else {
  +                        // remove parameters
  +                        if (!uri.startsWith("cocoon:raw:") ) {
  +                            sourceUri = "cocoon:raw:" + uri.substring(7);
  +                        }
                       }
                   }
                   
  -				portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
   				HashMap par = new HashMap();
   				par.put(Constants.PORTAL_NAME_KEY, portalService.getPortalName());
   				par.put(Constants.COPLET_ID_KEY, coplet.getId());
  @@ -136,9 +153,65 @@
        */
       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 ); 
  +            }
  +            
               this.manager.release( this.resolver );
               this.resolver = null;
               this.manager = null;
  +        }
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.portal.event.Subscriber#getEventType()
  +     */
  +    public Class getEventType() {
  +        return ChangeCopletInstanceAspectDataEvent.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) {
  +        ChangeCopletInstanceAspectDataEvent event = (ChangeCopletInstanceAspectDataEvent)e;
  +        PortalService service = null;
  +        try {
  +            service = (PortalService)this.manager.lookup(PortalService.ROLE);
  +            List list = (List)service.getTemporaryAttribute(URICopletAdapter.class.getName());
  +            if ( list == null ) {
  +                list = new ArrayList();
  +            }
  +            list.add(event.getCopletInstanceData());
  +            service.setTemporaryAttribute(URICopletAdapter.class.getName(), list);
  +        } catch (ComponentException ignore ) {            
  +        } finally {
  +            this.manager.release(service);
  +        }
  +    }
  +
  +    /* (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 );
           }
       }
   
  
  
  
  1.2       +6 -6      cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java
  
  Index: ChangeAspectDataEvent.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/ChangeAspectDataEvent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ChangeAspectDataEvent.java	23 May 2003 14:20:09 -0000	1.1
  +++ ChangeAspectDataEvent.java	26 May 2003 10:34:52 -0000	1.2
  @@ -54,20 +54,20 @@
   import org.apache.cocoon.portal.event.Event;
   
   /**
  - * This events set the aspect data for a layout object
  + * This events set the aspect data for an {@link Aspectalizable} object
    *
    * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
    * 
    * @version CVS $Id$
    */
  -public final class ChangeAspectDataEvent
  +public class ChangeAspectDataEvent
       implements Event {
   
  -    private Aspectalizable target;
  +    protected Aspectalizable target;
       
  -    private String aspectName;
  +    protected String aspectName;
       
  -    private Object data;
  +    protected Object data;
       
       public ChangeAspectDataEvent(Aspectalizable target, String aspectName, Object data) {
           this.target = target;
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/ChangeCopletInstanceAspectDataEvent.java
  
  Index: ChangeCopletInstanceAspectDataEvent.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  <st...@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.coplet.CopletInstanceData;
  import org.apache.cocoon.portal.event.CopletInstanceEvent;
  
  /**
   * This events set the aspect data for a coplet instance object
   *
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * 
   * @version CVS $Id: ChangeCopletInstanceAspectDataEvent.java,v 1.1 2003/05/26 10:34:52 cziegeler Exp $
   */
  public class ChangeCopletInstanceAspectDataEvent
      extends ChangeAspectDataEvent
      implements CopletInstanceEvent {
  
      public ChangeCopletInstanceAspectDataEvent(CopletInstanceData target, String aspectName, Object data) {
          super( target, aspectName, data );
      }
  
      public CopletInstanceData getCopletInstanceData() {
          return (CopletInstanceData)this.getTarget();
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/CopletInstanceEvent.java
  
  Index: CopletInstanceEvent.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.event;
  
  import org.apache.cocoon.portal.coplet.CopletInstanceData;
  
  /**
   * This interface marks an event as an event for a coplet instance.
   *
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * 
   * @version CVS $Id: CopletInstanceEvent.java,v 1.1 2003/05/26 10:34:53 cziegeler Exp $
   */
  public interface CopletInstanceEvent 
      extends Event {
          
      CopletInstanceData getCopletInstanceData();
  
  }