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 DefaultJXPathEventSubscriber.java
Date Thu, 11 Dec 2003 09:30:17 GMT
cziegeler    2003/12/11 01:30:17

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/transformation
                        CopletTransformer.java
               src/blocks/portal/conf portal.xconf
  Added:       src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        CopletJXPathEvent.java JXPathEvent.java
               src/blocks/portal/java/org/apache/cocoon/portal/event/subscriber/impl
                        DefaultJXPathEventSubscriber.java
  Log:
  Adding new JXPathEvents
  Enhancing coplet transformer to generate JXPathEvents
  
  Revision  Changes    Path
  1.6       +21 -9     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
  
  Index: CopletTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CopletTransformer.java	9 Dec 2003 10:21:56 -0000	1.5
  +++ CopletTransformer.java	11 Dec 2003 09:30:16 -0000	1.6
  @@ -54,9 +54,12 @@
   
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.portal.LinkService;
   import org.apache.cocoon.portal.PortalService;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
  +import org.apache.cocoon.portal.event.CopletInstanceEvent;
   import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent;
  +import org.apache.cocoon.portal.event.impl.CopletJXPathEvent;
   import org.apache.cocoon.xml.AttributesImpl;
   import org.apache.commons.jxpath.JXPathContext;
   import org.xml.sax.Attributes;
  @@ -141,22 +144,31 @@
               PortalService portalService = null;
               try {
                   final CopletInstanceData cid = this.getCopletInstanceData();
  -                ChangeCopletInstanceAspectDataEvent event = new ChangeCopletInstanceAspectDataEvent(cid,
null, null);
  -                
                   portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
  -                String value = portalService.getComponentManager().getLinkService().getLinkURI(event);
  -                if (value.indexOf('?') == -1) {
  -                    value = value + '?' + attr.getValue("href");
  +
  +                final LinkService linkService = portalService.getComponentManager().getLinkService();
  +                if ( attr.getValue("href") != null ) {
  +                    ChangeCopletInstanceAspectDataEvent event = new ChangeCopletInstanceAspectDataEvent(cid,
null, null);
  +                    
  +                    String value = linkService.getLinkURI(event);
  +                    if (value.indexOf('?') == -1) {
  +                        value = value + '?' + attr.getValue("href");
  +                    } else {
  +                        value = value + '&' + attr.getValue("href");
  +                    }
  +                    newAttrs.addCDATAAttribute("href", value);
                   } else {
  -                    value = value + '&' + attr.getValue("href");
  +                    final String path = attr.getValue("path");
  +                    final String value = attr.getValue("value");
  +                    
  +                    CopletInstanceEvent event = new CopletJXPathEvent(cid, path, value);
  +                    newAttrs.addCDATAAttribute("href", linkService.getLinkURI(event));
                   }
  -                newAttrs.addCDATAAttribute("href", value);
               } catch (ServiceException e) {
                   throw new SAXException("Error getting portal service.", e);
               } finally {
                   this.manager.release( portalService );
               }
  -            
               
               super.startElement("", "a", "a", newAttrs);
           } else {
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/CopletJXPathEvent.java
  
  Index: CopletJXPathEvent.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.coplet.CopletInstanceData;
  import org.apache.cocoon.portal.event.CopletInstanceEvent;
  
  /**
   * This events changes the value of an instance
   *
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * 
   * @version CVS $Id: CopletJXPathEvent.java,v 1.1 2003/12/11 09:30:16 cziegeler Exp $
   */
  public class CopletJXPathEvent
      extends JXPathEvent
      implements CopletInstanceEvent {
  
      public CopletJXPathEvent(CopletInstanceData target, String path, Object value) {
          super( target, path, value );
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/JXPathEvent.java
  
  Index: JXPathEvent.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.coplet.CopletInstanceData;
  
  /**
   * This events changes the value of an instance
   *
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * 
   * @version CVS $Id: JXPathEvent.java,v 1.1 2003/12/11 09:30:16 cziegeler Exp $
   */
  public class JXPathEvent
      extends AbstractActionEvent {
  
      protected String path;
      
      protected Object value;
      
      /**
       * @return Returns the path.
       */
      public String getPath() {
          return path;
      }
  
      /**
       * @return Returns the value.
       */
      public Object getValue() {
          return value;
      }
  
      public JXPathEvent(CopletInstanceData target, String path, Object value) {
          super( target );
          this.path = path;
          this.value = value;
      }
  
  }
  
  
  
  1.28      +1 -0      cocoon-2.1/src/blocks/portal/conf/portal.xconf
  
  Index: portal.xconf
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/conf/portal.xconf,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- portal.xconf	10 Dec 2003 14:04:15 -0000	1.27
  +++ portal.xconf	11 Dec 2003 09:30:17 -0000	1.28
  @@ -21,6 +21,7 @@
       <!-- add a new instance of each class as a subscriber: -->
       <subscriber-classes>
           <class name="org.apache.cocoon.portal.event.subscriber.impl.DefaultChangeAspectDataEventSubscriber"/>
  +        <class name="org.apache.cocoon.portal.event.subscriber.impl.DefaultJXPathEventSubscriber"/>
       </subscriber-classes>
       <!-- add each component as a subscriber (the component should be thread safe): -->
       <subscriber-roles>
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/subscriber/impl/DefaultJXPathEventSubscriber.java
  
  Index: DefaultJXPathEventSubscriber.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.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.JXPathEvent;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * This subscriber processes JXPath events
   * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
   * 
   * @version CVS $Id: DefaultJXPathEventSubscriber.java,v 1.1 2003/12/11 09:30:17 cziegeler
Exp $
   */
  public final class DefaultJXPathEventSubscriber 
      implements Subscriber {
  
      public DefaultJXPathEventSubscriber() {
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.portal.event.Subscriber#getEventType()
       */
      public Class getEventType() {
          return JXPathEvent.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 JXPathEvent event = (JXPathEvent)e;
          JXPathContext jxpathContext = JXPathContext.newContext(event.getTarget());
          jxpathContext.setValue(event.getPath(), event.getValue());
      }
  
  }
  
  
  

Mime
View raw message