Author: cziegeler
Date: Thu Oct  7 05:34:35 2004
New Revision: 53963

Added:
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java
Modified:
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplets/basket/BasketTransformer.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageImpl.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
   
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java
Log:
Minor improvements

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java   
    (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/LinkService.java   
    Thu Oct  7 05:34:35 2004
@@ -25,7 +25,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Volker Schmitt</a>
  * 
- * @version CVS $Id: LinkService.java,v 1.6 2004/06/07 09:53:34 cziegeler Exp $
+ * @version CVS $Id$
  */
 public interface LinkService extends Component {
 
@@ -33,6 +33,12 @@
     
     String DEFAULT_REQUEST_EVENT_PARAMETER_NAME = "cocoon-portal-event";
     
+    static class ParameterDescription {
+        public final String parameters;
+        public ParameterDescription(String parameters) {
+            this.parameters = parameters;
+        }
+    }
     /**
      * Get the uri for this coplet containing the additional event
      * @param event The event to add (null is also allowed for convenience)
@@ -41,8 +47,8 @@
     String getLinkURI(Event event);
 
     /**
-     * Get the uri for this coplet containing the additional events
-     * @param events The events to add
+     * Get the uri for this coplet containing the additional events.
+     * @param events The events to add: These can either be [EMAIL PROTECTED] 
Event}s or [EMAIL PROTECTED] #ParameterDescription}s.
      * @return A URI
      */
     String getLinkURI(List events);

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java
     (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/acting/BookmarkAction.java
     Thu Oct  7 05:34:35 2004
@@ -62,7 +62,7 @@
  * </bookmarks>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: BookmarkAction.java,v 1.5 2004/03/05 13:02:08 bdelacretaz 
Exp $
+ * @version CVS $Id$
 */
 public class BookmarkAction
 extends ServiceableAction
@@ -190,9 +190,9 @@
                     }
                 }
             }
-            Enumeration enum = request.getParameterNames();
-            while (enum.hasMoreElements()) {
-                String name = (String)enum.nextElement();
+            Enumeration enumeration = request.getParameterNames();
+            while (enumeration.hasMoreElements()) {
+                String name = (String)enumeration.nextElement();
                 String value = request.getParameter(name);
                 
                 Mapping m = (Mapping) this.eventMap.get(name);

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplets/basket/BasketTransformer.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplets/basket/BasketTransformer.java
  (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplets/basket/BasketTransformer.java
  Thu Oct  7 05:34:35 2004
@@ -60,7 +60,7 @@
      * Constructor
      */
     public BasketTransformer() {
-        super.defaultNamespaceURI = NAMESPACE_URI;
+        this.defaultNamespaceURI = NAMESPACE_URI;
     }
 
     /* (non-Javadoc)
@@ -112,9 +112,11 @@
             } finally {
                 this.manager.release(service);
             }
+
         } else if ( UPLOAD_ITEM_ELEMENT.equals(name) ) {
             this.uploadElements.add(attr.getValue("name"));
             this.startElement("", "input", "input", attr);
+
         } else if ( UPLOAD_FORM_ELEMENT.equals(name) ) {
             AttributesImpl ai = new AttributesImpl(attr);
             PortalService service = null;
@@ -135,9 +137,9 @@
             if ( parameters != null && parameters.length() > 0 ) {
                 // create hidden input fields
                 RequestParameters pars = new RequestParameters(parameters);
-                Enumeration enum = pars.getParameterNames();
-                while ( enum.hasMoreElements() ) {
-                    String pName = (String)enum.nextElement();
+                Enumeration enumeration = pars.getParameterNames();
+                while ( enumeration.hasMoreElements() ) {
+                    String pName = (String)enumeration.nextElement();
                     String pValue = pars.getParameter(pName);
                     AttributesImpl hiddenAttrs = new AttributesImpl();
                     hiddenAttrs.addCDATAAttribute("type", "hidden");
@@ -147,7 +149,8 @@
                     this.endElement("", "input", "input");
                 }
             }
+
         }
     }
 
-}
\ No newline at end of file
+}

Added: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java
==============================================================================
--- (empty file)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/generation/AbstractCopletGenerator.java
        Thu Oct  7 05:34:35 2004
@@ -0,0 +1,155 @@
+/*
+ * Copyright 1999-2002,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.generation;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.generation.ServiceableGenerator;
+import org.apache.cocoon.portal.Constants;
+import org.apache.cocoon.portal.PortalService;
+import org.apache.cocoon.portal.coplet.CopletInstanceData;
+import org.xml.sax.SAXException;
+
+/**
+ * Abstract generator implementation that provides a method 
getCopletInstanceData().
+ * There are two possibilities how the generator obtains the information 
required for 
+ * getting the coplet instance data:<br><br>
+ * 1) If it is used within a coplet pipeline and this pipeline is called using 
the "cocoon:" protocol,
+ * all required information are passed automatically.<br>
+ * 2) Otherwise the portal name and the coplet id must be passed to the 
generator 
+ * as paremeters in the following way:
+ *
+ * <pre>&lt;map:generator type="coplet"&gt;
+ *     &lt;map:parameter name="portalName" type="exampleportal"/&gt;
+ *     &lt;map:parameter name="copletId" type="examplecoplet"/&gt;
+ * &lt;/map:generator&gt;</pre>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
+ * @version CVS $Id: AbstractCopletTransformer.java 30941 2004-07-29 19:56:58Z 
vgritsenko $
+ */
+public abstract class AbstractCopletGenerator 
+extends ServiceableGenerator {
+
+    /**
+     * Parameter name.
+     */
+    public static final String COPLET_ID_PARAM = "copletId";
+
+    /**
+     * Parameter name.
+     */
+    public static final String PORTAL_NAME_PARAM = "portalName";
+
+    /** The portal service */
+    private PortalService _portalService;
+    
+    /**
+     * Try to get the coplet instance data belonging to the current request
+     * @return The coplet instance data
+     * @throws SAXException If an errors occurs or the instance data is not 
available
+     */
+    protected CopletInstanceData getCopletInstanceData() 
+    throws SAXException {
+        CopletInstanceData cid = this.getCopletInstanceData(null);
+        if ( cid == null ) {
+            throw new SAXException("Could not find coplet instance data for 
the current pipeline.");
+        }
+        return cid;
+    }
+    
+    
+    /**
+     * Get the portal service
+     */
+    protected PortalService getPortalService()
+    throws SAXException {
+        if ( this._portalService == null ) {
+            try {
+                this._portalService = 
(PortalService)this.manager.lookup(PortalService.ROLE);
+                
+                if ( this._portalService.getPortalName() == null ) {
+                    // set portal name
+                    String portalName = 
this.parameters.getParameter(PORTAL_NAME_PARAM, 
+                                                                    
(String)this.objectModel.get(Constants.PORTAL_NAME_KEY));
+                    if ( portalName == null ) {
+                        final Map context = 
(Map)this.objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
+                        if ( context != null ) {
+                            portalName = (String) 
context.get(Constants.PORTAL_NAME_KEY);
+                        }
+                    }
+                    if ( portalName == null ) {
+                        throw new SAXException("portalName must be passed as 
parameter or in the object model.");
+                    }
+                    this._portalService.setPortalName(portalName);
+                }
+            } catch (ServiceException se) {
+                throw new SAXException("Unable to get portal service.", se);
+            }
+        }
+        return this._portalService;
+    }
+    
+    
+    /**
+     * Try to get the coplet instance data with the given id
+     * @param copletId  The id of the coplet instance or null if this 
transformer
+     *                   is used inside a coplet pipeline
+     * @return The coplet instance data or null
+     * @throws SAXException If an error occurs
+     */
+    protected CopletInstanceData getCopletInstanceData(String copletId) 
+    throws SAXException {
+        final Map context = 
(Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
+        
+        if ( copletId == null ) {
+            // determine coplet id
+            if (context != null) {
+                copletId = (String)context.get(Constants.COPLET_ID_KEY);
+            } else {
+                copletId = (String)objectModel.get(Constants.COPLET_ID_KEY);
+                if ( copletId == null ) {
+                    try {
+                        copletId = 
this.parameters.getParameter(COPLET_ID_PARAM);
+                            
+                    } catch (ParameterException e) {
+                        throw new SAXException("copletId must be passed as 
parameter or in the object model within the parent context.");
+                    }
+                }
+            }
+        }
+        if (copletId == null) {
+            throw new SAXException("copletId must be passed as parameter or in 
the object model within the parent context.");
+        }
+
+        CopletInstanceData object = 
this.getPortalService().getComponentManager().getProfileManager().getCopletInstanceData(
 copletId );
+            
+        return object;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
+     */
+    public void recycle() {
+        if ( this._portalService != null ) {
+            this.manager.release( this._portalService );
+            this._portalService = null;            
+        }
+        super.recycle();
+    }
+}

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java
   (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/impl/DefaultLinkService.java
   Thu Oct  7 05:34:35 2004
@@ -44,7 +44,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Volker Schmitt</a>
  * 
- * @version CVS $Id: DefaultLinkService.java,v 1.15 2004/07/11 17:23:29 
antonio Exp $
+ * @version CVS $Id$
  */
 public class DefaultLinkService 
     extends AbstractLogEnabled
@@ -175,7 +175,7 @@
             Iterator eventIterator = events.iterator();
             boolean found = false;
             while (!found && eventIterator.hasNext()) {
-                Event inEvent = (Event)eventIterator.next();
+                final Object inEvent = eventIterator.next();
                 if ( inEvent instanceof ComparableEvent
                      && current.equalsEvent((ComparableEvent)inEvent)) {
                      found = true;
@@ -195,8 +195,18 @@
         // now add events
         iter = events.iterator();
         while ( iter.hasNext()) {
-            final Event current = (Event)iter.next();
-            hasParams = this.addEvent(buffer, current, hasParams);
+            final Object current = iter.next();
+            if ( current instanceof Event ) {
+                hasParams = this.addEvent(buffer, (Event)current, hasParams);
+            } else if ( current instanceof ParameterDescription ) {
+                if ( hasParams ) {
+                    buffer.append('&');
+                } else {
+                    buffer.append('?');
+                    hasParams = true;
+                }
+                buffer.append(((ParameterDescription)current).parameters);
+            }
         }
         return buffer.toString();
     }
@@ -263,9 +273,9 @@
                 info.linkBase.delete(pos, info.linkBase.length() + 1);
                 info.hasParameters = false;
                 
-                Enumeration enum = params.getParameterNames();
-                while ( enum.hasMoreElements() ) {
-                    final String paramName = (String)enum.nextElement();
+                Enumeration enumeration = params.getParameterNames();
+                while ( enumeration.hasMoreElements() ) {
+                    final String paramName = (String)enumeration.nextElement();
                     if ( !paramName.equals(name) ) {
                         String[] values = params.getParameterValues(paramName);
                         for( int i = 0; i < values.length; i++ ) {

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageImpl.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageImpl.java
      (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/pluto/om/common/LanguageImpl.java
      Thu Oct  7 05:34:35 2004
@@ -34,7 +34,7 @@
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  * 
- * @version CVS $Id: LanguageImpl.java,v 1.3 2004/03/05 13:02:15 bdelacretaz 
Exp $
+ * @version CVS $Id$
  */
 public class LanguageImpl implements Language, java.io.Serializable {
     // ResourceBundle creation part
@@ -91,8 +91,8 @@
 
         private void importData(ResourceBundle bundle) {
             if (bundle != null) {
-                for (Enumeration enum = bundle.getKeys(); 
enum.hasMoreElements();) {
-                    String key   = (String)enum.nextElement();
+                for (Enumeration enumeration = bundle.getKeys(); 
enumeration.hasMoreElements();) {
+                    String key   = (String)enumeration.nextElement();
                     Object value = bundle.getObject(key);
 
                     data.put(key, value);

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java
       (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/reading/ProxyReader.java
       Thu Oct  7 05:34:35 2004
@@ -45,7 +45,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Gernot Koller</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Friedrich Klenner</a> 
  * 
- * @version CVS $Id: ProxyReader.java,v 1.8 2004/07/13 14:30:11 cziegeler Exp $
+ * @version CVS $Id$
  */
 public class ProxyReader extends ServiceableReader {
 
@@ -156,13 +156,13 @@
         String cookie =
             (String) copletInstanceData.getAttribute(ProxyTransformer.COOKIE);
 
-        Enumeration enum = request.getParameterNames();
+        Enumeration enumeration = request.getParameterNames();
 
         boolean firstattribute = true;
         StringBuffer query = new StringBuffer();
 
-        while (enum.hasMoreElements()) {
-            String paramName = (String) enum.nextElement();
+        while (enumeration.hasMoreElements()) {
+            String paramName = (String) enumeration.nextElement();
 
             if (!paramName.startsWith("cocoon-portal-")) {
 
@@ -228,4 +228,4 @@
 
         }
     }
-}
\ No newline at end of file
+}

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java
  (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java
  Thu Oct  7 05:34:35 2004
@@ -41,7 +41,7 @@
  * &lt;/map:transform&gt;</pre>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: AbstractCopletTransformer.java,v 1.9 2004/03/16 09:16:59 
cziegeler Exp $
+ * @version CVS $Id$
  */
 public abstract class AbstractCopletTransformer 
 extends AbstractSAXTransformer {
@@ -122,11 +122,14 @@
             if (context != null) {
                 copletId = (String)context.get(Constants.COPLET_ID_KEY);
             } else {
-                try {
-                    copletId = this.parameters.getParameter(COPLET_ID_PARAM);
+                copletId = (String)objectModel.get(Constants.COPLET_ID_KEY);
+                if ( copletId == null ) {
+                    try {
+                        copletId = 
this.parameters.getParameter(COPLET_ID_PARAM);
                         
-                } catch (ParameterException e) {
-                    throw new SAXException("copletId must be passed as 
parameter or in the object model within the parent context.");
+                    } catch (ParameterException e) {
+                        throw new SAXException("copletId must be passed as 
parameter or in the object model within the parent context.");
+                    }
                 }
             }
         }

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
  (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
  Thu Oct  7 05:34:35 2004
@@ -82,6 +82,9 @@
     /** Create a link containing several events */
     public static final String LINKS_ELEM = "links";
 
+    /** Create a link containing several events */
+    public static final String PARAMETER_ELEM = "parameter";
+
     /** The content for the links element */
     public static final String CONTENT_ELEM = "content";
 
@@ -184,8 +187,17 @@
                     this.output(href, format, newAttrs );
                 }
             }
+        } else if (name.equals(PARAMETER_ELEM)) {
+            if (this.insideLinks) {
+                this.collectedEvents.add(new 
LinkService.ParameterDescription(attr.getValue("href")));
+            }
         } else if (name.equals(LINKS_ELEM) ) {
             this.insideLinks = true;
+            final AttributesImpl newAttrs = new AttributesImpl();
+            newAttrs.setAttributes(attr);
+            newAttrs.removeAttribute("format");
+            this.stack.push(newAttrs);
+            
             String format = attr.getValue("format");
             if ( format == null ) {
                 format = "html-link";
@@ -214,9 +226,9 @@
             this.insideLinks = false;
             final String format = (String)this.stack.pop();
             final LinkService linkService = 
this.getPortalService().getComponentManager().getLinkService();
-
             final String href = linkService.getLinkURI(this.collectedEvents);
-            final AttributesImpl newAttrs = new AttributesImpl();
+
+            AttributesImpl newAttrs = (AttributesImpl)this.stack.pop();
             this.output(href, format, newAttrs );
 
             this.collectedEvents.clear();
@@ -230,7 +242,7 @@
             }
         } else if ( name.equals(CONTENT_ELEM) && this.insideLinks ) {
             this.content = this.endSAXRecording();
-        } else if (!name.equals(COPLET_ELEM)) {
+        } else if (!name.equals(COPLET_ELEM) && !name.equals(PARAMETER_ELEM)) {
             super.endTransformingElement(uri, name, raw);
         }
     }
@@ -267,9 +279,9 @@
             if ( addParametersAsHiddenFields ) {
                 // create hidden input fields
                 RequestParameters pars = new RequestParameters(parameters);
-                Enumeration enum = pars.getParameterNames();
-                while ( enum.hasMoreElements() ) {
-                    String pName = (String)enum.nextElement();
+                Enumeration enumeration = pars.getParameterNames();
+                while ( enumeration.hasMoreElements() ) {
+                    String pName = (String)enumeration.nextElement();
                     String pValue = pars.getParameter(pName);
                     AttributesImpl hiddenAttrs = new AttributesImpl();
                     hiddenAttrs.addCDATAAttribute("type", "hidden");

Modified: 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java
==============================================================================
--- 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java
   (original)
+++ 
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/transformation/ProxyTransformer.java
   Thu Oct  7 05:34:35 2004
@@ -62,7 +62,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Friedrich Klenner</a>  
  * @author <a href="mailto:[EMAIL PROTECTED]">Gernot Koller</a>
  * 
- * @version CVS $Id: ProxyTransformer.java,v 1.12 2004/07/13 14:30:11 
cziegeler Exp $
+ * @version CVS $Id$
  */
 public class ProxyTransformer
     extends AbstractTransformer
@@ -242,12 +242,12 @@
             StringBuffer query = new StringBuffer();
 
             boolean firstparameter = true;
-            Enumeration enum = request.getParameterNames();
+            Enumeration enumeration = request.getParameterNames();
 
             boolean post = ("POST".equals(request.getMethod()));
 
-            while (enum.hasMoreElements()) {
-                String paramName = (String) enum.nextElement();
+            while (enumeration.hasMoreElements()) {
+                String paramName = (String) enumeration.nextElement();
 
                 if (!paramName.startsWith("cocoon-portal-")) {
                     String[] paramValues =
@@ -651,4 +651,4 @@
         }
     }
 
-}
\ No newline at end of file
+}

Reply via email to