cziegeler    2003/05/08 04:54:01

  Modified:    
src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl
                        URICopletAdapter.java
               src/blocks/portal/java/org/apache/cocoon/portal/impl
                        PortalServiceImpl.java
  Added:       src/blocks/portal/java/org/apache/cocoon/portal
                        Constants.java
               src/blocks/portal/java/org/apache/cocoon/portal/transformation
                        CopletTransformer.java EventLinkTransformer.java
               src/blocks/portal/java/org/apache/cocoon/portal/event/impl
                        LinkEvent.java
               
src/blocks/portal/java/org/apache/cocoon/portal/components/modules/input
                        CopletModule.java
               src/blocks/portal/conf modules.xconf
               src/blocks/portal/java/org/apache/cocoon/portal/acting
                        ObjectModelAction.java
  Log:
  Extending the portal functionality
  
  Revision  Changes    Path
  1.1                  
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/Constants.java
  
  Index: Constants.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal;
  
  /**
   * Defines constants used within portal classes.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: Constants.java,v 1.1 2003/05/08 11:54:00 cziegeler Exp $
   */
  public class Constants {
      
      /**
       * Names used in object model or parent context by CopletModule, 
CopletTransformer and CopletAdapter. 
       */
      public static final String COPLET_ID_KEY = "cocoon-portal-copletId";
      public static final String PORTAL_NAME_KEY = "cocoon-portal-portalName";
  }
  
  
  
  1.2       +29 -12    
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- URICopletAdapter.java     7 May 2003 06:22:30 -0000       1.1
  +++ URICopletAdapter.java     8 May 2003 11:54:00 -0000       1.2
  @@ -51,6 +51,7 @@
   package org.apache.cocoon.portal.coplet.adapter.impl;
   
   import java.io.IOException;
  +import java.util.HashMap;
   
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.component.ComponentException;
  @@ -60,6 +61,8 @@
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.source.SourceUtil;
  +import org.apache.cocoon.portal.PortalService;
  +import org.apache.cocoon.portal.Constants;
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
   import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
   import org.apache.excalibur.source.Source;
  @@ -96,17 +99,31 @@
       
       public void toSAX(CopletInstanceData coplet, ContentHandler 
contentHandler)
       throws SAXException {
  -        Source copletSource = null;
  -        try {
  -            copletSource = 
this.resolver.resolveURI((String)coplet.getCopletData().getAttribute("uri"));
  -            SourceUtil.toSAX(copletSource, contentHandler);
  -        } catch (IOException ioe) {
  -            throw new SAXException("IOException", ioe);
  -        } catch (ProcessingException pe) {
  -            throw new SAXException("ProcessingException", pe);
  -        } finally {
  -            this.resolver.release( copletSource );
  -        }
  +             String uri = (String)coplet.getCopletData().getAttribute("uri");
  +             Source copletSource = null;
  +             PortalService portalService = null;
  +             try {
  +                     if (uri.startsWith("cocoon:")) {
  +                             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.getCopletId());
  +            
  +                             copletSource = this.resolver.resolveURI(uri, 
null, par);
  +                     } else {
  +                             copletSource = this.resolver.resolveURI(uri);
  +                     }
  +                     SourceUtil.toSAX(copletSource, contentHandler);
  +             } catch (IOException ioe) {
  +                     throw new SAXException("IOException", ioe);
  +             } catch (ProcessingException pe) {
  +                     throw new SAXException("ProcessingException", pe);
  +             } catch (ComponentException ce) {
  +                     throw new SAXException("ComponentException", ce);
  +             } finally {
  +                     this.resolver.release(copletSource);
  +                     this.manager.release(portalService);
  +             }
       }
       
       public void init(CopletInstanceData coplet) {
  
  
  
  1.1                  
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
  
  Index: CopletTransformer.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.transformation;
  
  import java.io.IOException;
  import java.util.Map;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.portal.Constants;
  import org.apache.cocoon.portal.PortalService;
  import org.apache.cocoon.portal.profile.ProfileManager;
  import org.apache.cocoon.transformation.AbstractSAXTransformer;
  import org.apache.commons.jxpath.JXPathContext;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  
  /**
   * Includes coplet instance data by using JXPath expressions.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Björn Lütkemeier</a>
   * @version CVS $Id: CopletTransformer.java,v 1.1 2003/05/08 11:54:00 
cziegeler Exp $
   */
  public class CopletTransformer 
  extends AbstractSAXTransformer {
  
      /**
       * The namespace URI to listen for.
       */
      public static final String NAMESPACE_URI = 
"http://apache.org/cocoon/portal/coplet/1.0";;
      
      /**
       * The XML element name to listen for.
       */
      public static final String COPLET_ELEM = "coplet";
  
      /**
       * The attribute containing the JXPath expression.
       */
      public static final String SELECT_ATTR = "select";
  
      /**
       * Parameter name.
       */
      public static final String COPLET_ID_PARAM = "copletId";
      
      /**
       * Parameter name.
       */
      public static final String PORTAL_NAME_PARAM = "portalName";
      
      /**
       * Creates new CopletTransformer.
       */
      public CopletTransformer() {
          this.defaultNamespaceURI = NAMESPACE_URI;
      }
      
      /**
       * Overridden from superclass.
       */
      public void startTransformingElement(String uri, String name, String raw, 
Attributes attr) 
      throws ProcessingException, IOException, SAXException {
          if (name.equals(COPLET_ELEM)) {
              String expression = attr.getValue(SELECT_ATTR);
              if (expression == null) {
                  throw new ProcessingException("Attribute "+SELECT_ATTR+" must 
be spcified.");
              }
                  
              ProfileManager profileManager = null;
              try {
                  profileManager = 
(ProfileManager)this.manager.lookup(ProfileManager.ROLE);
  
                  // determine coplet id
                  String copletId = null;            
                  Map context = 
(Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
                  if (context != null) {
                      copletId = (String)context.get(Constants.COPLET_ID_KEY);
                      if (copletId == null) {
                          throw new ProcessingException("copletId must be 
passed as parameter or in the object model within the parent context.");
                      }
                  } else {
                                        try {
                                                copletId = 
this.parameters.getParameter(COPLET_ID_PARAM);
                                                
                                                // set portal name
                                                PortalService portalService = 
null;
                                                try {
                                                    portalService = 
(PortalService)this.manager.lookup(PortalService.ROLE);
                                                    
portalService.setPortalName(this.parameters.getParameter(PORTAL_NAME_PARAM));
                                                } finally {
                                                    
this.manager.release(portalService);
                                                }
                                        } catch (ParameterException e) {
                          throw new ProcessingException("copletId and 
portalName must be passed as parameter or in the object model within the parent 
context.");
                                        }
                  }
  
                  JXPathContext jxpathContext = 
JXPathContext.newContext(profileManager.getCopletInstanceData(copletId));
                  Object object = jxpathContext.getValue(expression);
                  
                  if (object == null) {
                      throw new ProcessingException("Could not find value for 
expression "+expression);
                  }
                  
                  String value = object.toString();
                  super.characters(value.toCharArray(), 0, value.length());
              } catch (ComponentException e) {
                  throw new ProcessingException("Error getting profile 
manager.", e);
              } finally {
                  this.manager.release(profileManager);
              }
              
          } else {
              super.startTransformingElement(uri, name, raw, attr);
          }
      }
  
      /**
       * Overridden from superclass.
       */
      public void endTransformingElement(String uri, String name, String raw) 
      throws ProcessingException, IOException, SAXException {
          if (!name.equals(COPLET_ELEM)) {
              super.endTransformingElement(uri, name, raw);
          }
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/EventLinkTransformer.java
  
  Index: EventLinkTransformer.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.transformation;
  
  import java.util.Stack;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.cocoon.portal.LinkService;
  import org.apache.cocoon.portal.event.impl.LinkEvent;
  import org.apache.cocoon.transformation.AbstractSAXTransformer;
  import org.w3c.dom.DocumentFragment;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  /**
   * This transformer searches for event descriptions in the XML. 
   * For each one an event is created and the event link is inserted into the 
XML 
   * instead of the description.
   *  
   * @author <a href="mailto:[EMAIL PROTECTED]">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: EventLinkTransformer.java,v 1.1 2003/05/08 11:54:00 
cziegeler Exp $
   */
  public class EventLinkTransformer 
  extends AbstractSAXTransformer {
      
      /**
       * The namespace URI to listen for.
       */
      public static final String NAMESPACE_URI = 
"http://apache.org/cocoon/portal/eventlink/1.0";;
      
      /**
       * The XML element name to listen for.
       */
      public static final String EVENT_ELEM = "event";
      
      /**
       * An attribute's name of EVENT_ELEMENT.
       */
      public static final String ATTRIBUTE_ATTR = "attribute";
      
      /**
       * An attribute's name of EVENT_ELEMENT.
       */
      public static final String ELEMENT_ATTR = "element";
  
      /**
       * Used to signal whether the transformer is inside an EVENT_ELEM tag.
       */
      private boolean insideEvent = false;
  
      /**
       * The attribute defining the link inside an EVENT_ELEM tag.
       */
      private String attributeName = null;
  
      /**
       * The element defining the link inside an EVENT_ELEM tag.
       */
      private String elementName = null;
      
      /**
       * Used to store elements' attributes between startTransformingElement 
and endTransformingElement. 
       */
      private Stack attrStack = new Stack();
  
      /**
       * Overridden from superclass.
       */
      public void recycle() {
          super.recycle();
          this.insideEvent = false;
          this.attributeName = null;
          this.elementName = null;
          this.attrStack.clear();
      }
  
      /**
       * Overridden from superclass.
       */
        public void startElement(String uri, String name, String raw, 
Attributes attr)
        throws SAXException {
  
          if (uri.equals(NAMESPACE_URI) && name.equals(EVENT_ELEM)) {
              if (this.insideEvent) {
                  throw new SAXException("Elements "+EVENT_ELEM+" must not be 
nested.");
              }
              this.insideEvent = true;
              
              // get element or attribute name that contains links
              this.attributeName = attr.getValue(ATTRIBUTE_ATTR);
              this.elementName = attr.getValue(ELEMENT_ATTR);
  
              // at least one of them must be set
              if (this.attributeName == null && this.elementName == null) {
                  throw new SAXException("Element "+EVENT_ELEM+" must have one 
of attributes "+ATTRIBUTE_ATTR+" and "+ELEMENT_ATTR+".");
              }
          } else {
              if (this.insideEvent) {
                  // store attributes for endTransformingElement
                  this.attrStack.push(new AttributesImpl(attr));
                  
                  /* Record element content. In case of an element we asume, 
that no
                   * children exist but only text content, since the text 
content shall 
                   * be the link. Therefore we do startTextRecording. Otherwise 
we 
                   * record the whole subtree.
                   */
                  if (this.elementName != null && 
name.equals(this.elementName)) {
                      this.startTextRecording();
                  } else {
                      this.startRecording();
                  }
              } else {
                  super.startElement(uri, name, raw, attr);
              }
          }
        }
  
      /**
       * Overridden from superclass.
       */
      public void endElement(String uri, String name, String raw)
      throws SAXException {
  
          if (uri.equals(NAMESPACE_URI) && name.equals(EVENT_ELEM)) {
              this.attributeName = null;
              this.elementName = null;
              this.insideEvent = false;
          } else {
              if (this.insideEvent) {
                  AttributesImpl attr = (AttributesImpl)this.attrStack.pop();
  
                  // process attribute that contains link
                  if (this.attributeName != null) {
                      int index = attr.getIndex(this.attributeName);
                      String link = attr.getValue(index);
  
                      // if attribute found that contains a link
                      if (link != null) {
                          LinkService linkService = null;
                          try {
                              linkService = 
(LinkService)this.manager.lookup(LinkService.ROLE);
          
                              // create event link
                              LinkEvent event = new LinkEvent(link);
                              String eventLink = linkService.getLinkURI(event);
          
                              // insert event link
                              attr.setValue(index, eventLink);
                          } catch (ComponentException e) {
                              throw new SAXException(e);
                          } finally {
                              this.manager.release(linkService);
                          }
                      }
                  }
                  
                  String eventLink = null;
                  DocumentFragment fragment = null;
                                  
                  // process element that contains link
                  if (this.elementName != null && 
name.equals(this.elementName)) {
                      String link = this.endTextRecording();
  
                      LinkService linkService = null;
                      try {
                          linkService = 
(LinkService)this.manager.lookup(LinkService.ROLE);
          
                          // create event link
                          LinkEvent event = new LinkEvent(link);
                          eventLink = linkService.getLinkURI(event);
                      } catch (ComponentException e) {
                          throw new SAXException(e);
                      } finally {
                          this.manager.release(linkService);
                      }
                  } else {
                      fragment = this.endRecording();
                  }
                  
                  // stream element
                  super.startElement(uri, name, raw, attr);
                  if (eventLink != null) {
                      // insert event link
                      super.characters(eventLink.toCharArray(), 0, 
eventLink.length());
                  } else if (fragment != null) {
                      super.sendEvents(fragment);
                  }
                  super.endElement(uri, name, raw);
              } else {
                  super.endElement(uri, name, raw);
              }
          }
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/event/impl/LinkEvent.java
  
  Index: LinkEvent.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. 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.event.Event;
  
  /**
   * This class realizes a link event created by the EventLinkTransformer.
   *  
   * @author <a href="mailto:[EMAIL PROTECTED]">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: LinkEvent.java,v 1.1 2003/05/08 11:54:00 cziegeler Exp $
   */
  public class LinkEvent
  implements Event {
      
      /**
       * The link to be handled by this event.
       */
      private String link;
      
      /**
       * Creates a new LinkEvent.
       */
      public LinkEvent(String link) {
          this.link = link;
      }
      
      /**
       * Gets this event's link.
       */
      public String getLink() {
          return this.link;
      }
  }
  
  
  
  1.2       +9 -1      
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java
  
  Index: PortalServiceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PortalServiceImpl.java    7 May 2003 06:22:26 -0000       1.1
  +++ PortalServiceImpl.java    8 May 2003 11:54:00 -0000       1.2
  @@ -67,6 +67,7 @@
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Session;
   import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.cocoon.portal.Constants;
   import org.apache.cocoon.portal.LinkService;
   import org.apache.cocoon.portal.PortalService;
   import org.xml.sax.SAXException;
  @@ -105,6 +106,13 @@
   
       public void setup(SourceResolver resolver, Map objectModel) throws 
ProcessingException, SAXException, IOException {
           this.objectModel = objectModel;
  +
  +             Map context = 
(Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
  +             if (context != null) {
  +                     String portalName = 
(String)context.get(Constants.PORTAL_NAME_KEY);
  +                     if (portalName != null)
  +                             this.setPortalName(portalName);
  +             }
       }
   
       public String getPortalName() {
  
  
  
  1.1                  
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/components/modules/input/CopletModule.java
  
  Index: CopletModule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.components.modules.input;
  
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Vector;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.components.modules.input.InputModule;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.portal.Constants;
  import org.apache.cocoon.portal.PortalService;
  import org.apache.cocoon.portal.profile.ProfileManager;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * Makes accessible coplet instance data by using JXPath expressions.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Björn Lütkemeier</a>
   * @version CVS $Id: CopletModule.java,v 1.1 2003/05/08 11:54:01 cziegeler 
Exp $
   */
  public class CopletModule 
  implements InputModule, Composable, ThreadSafe {
      
      /**
       * The component manager.
       */
      private ComponentManager manager;
      
      /**
       * Obtains the component manager.
       */
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      /**
       * Overridden from superclass.
       */
        public Object getAttribute(String name, Configuration modeConf, Map 
objectModel) 
      throws ConfigurationException {
          ProfileManager profileManager = null;
          try {
              profileManager = 
(ProfileManager)this.manager.lookup(ProfileManager.ROLE);
  
              // determine coplet id
              String copletId = null;            
              Map context = 
(Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
              if (context != null) {
                  copletId = (String)context.get(Constants.COPLET_ID_KEY);
              } else {
                  copletId = (String)objectModel.get(Constants.COPLET_ID_KEY);
                  
                  // set portal name
                  PortalService portalService = null;
                  try {
                      portalService = 
(PortalService)this.manager.lookup(PortalService.ROLE);
                      
portalService.setPortalName((String)objectModel.get(Constants.PORTAL_NAME_KEY));
                  } finally {
                      this.manager.release(portalService);
                  }
              }
              
              if (copletId == null) {
                  throw new ConfigurationException("copletId must be passed in 
the object model either directly (e.g. by using ObjectModelAction) or within 
the parent context.");
              }
              
              JXPathContext jxpathContext = 
JXPathContext.newContext(profileManager.getCopletInstanceData(copletId));
              Object value = jxpathContext.getValue(name);
                  
              if (value == null) {
                  throw new ConfigurationException("Could not find value for 
expression "+name);
              }
                  
              return value.toString();
              
          } catch (ComponentException e) {
              throw new ConfigurationException("ComponentException ", e);
          } finally {
              this.manager.release(profileManager);
          }
        }
  
      /**
       * Overridden from superclass.
       */
        public Iterator getAttributeNames(Configuration modeConf, Map 
objectModel) {
          return new Vector().iterator();
        }
  
      /**
       * Overridden from superclass.
       */
        public Object[] getAttributeValues(String name, Configuration modeConf, 
Map objectModel)
      throws ConfigurationException {
          Object[] result = new Object[1];
          result[0] = this.getAttribute(name, modeConf, objectModel);
          return result;
        }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/conf/modules.xconf
  
  Index: modules.xconf
  ===================================================================
  <?xml version="1.0"?>
  
  <xconf xpath="/cocoon/input-modules" unless="[EMAIL 
PROTECTED]'org.apache.cocoon.portal.components.modules.input.CopletModule']">
  
        <component-instance logger="core.modules.input" name="coplet" 
class="org.apache.cocoon.portal.components.modules.input.CopletModule"/>
  
  </xconf>
  
  
  1.1                  
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/acting/ObjectModelAction.java
  
  Index: ObjectModelAction.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.acting;
  
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.acting.AbstractAction;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  
  /**
   * Stores all parameters in the object model adding prefix "cocoon-portal-".
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Björn Lütkemeier</a>
   * @version CVS $Id: ObjectModelAction.java,v 1.1 2003/05/08 11:54:01 
cziegeler Exp $
   */
  public class ObjectModelAction 
  extends AbstractAction {
  
        public Map act(Redirector redirector, SourceResolver resolver, Map 
objectModel, String source, Parameters parameters) 
      throws Exception {
          Iterator names = parameters.getParameterNames();
          String name;
          while (names.hasNext()) {
              name = (String)names.next();
              objectModel.put("cocoon-portal-"+name, 
parameters.getParameter(name));
          }
          
                return EMPTY_MAP;
        }
  }
  
  
  

Reply via email to