cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Woon-San Ko <woon_...@yahoo.com>
Subject CocoonPortlet needs to allow overriding servlet-path parameter with preferences.
Date Fri, 30 Jun 2006 12:22:43 GMT
Hi, all.

The CocoonPortlet in BRANCH_2_1_X does not allow overriding the *servlet-path* init parameter
by
preferences.
So, portal users have to add portlet tags in the portlet.xml whenever they need to use another
coplet in the portal site.

If the CocoonPortlet reads preferences to override the *servlet-path*, portal users can use
many
coplet fragments without tedious portlet tag additions.

In the Portals Bridges project, *GenericServletPortlet* provides this kind of functionality.
GenericServletPortlet reads the init parameters initially to set *ViewPage*, *EditPage*, and
*HelpPage*, but if it finds preferences with same name, then it replaces the page URLs with
the
preference values. (GenericServletPortlet reads request attributes before reading preferences,
actually.)

I made this kind of implementation and pasted the patch at the bottom for
*src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java*.

To test properly, you should add init-parameter in the cocoon/WEB-INF/portlet.xml like the
following:

  &lt;portlet&gt;
    &lt;portlet-name&gt;CocoonPortlet&lt;/portlet-name&gt;
    ...
    &lt;init-param&gt;
      &lt;name&gt;allow-preferences&lt;/name&gt;
      &lt;value&gt;true&lt;/value&gt;
    &lt;/init-param&gt;
    ...
  &lt;/portlet&gt;

ManagedCocoonPortlet will read preferences just when the above parameter is set to true. (I
borrowed this from GenericServletPortlet.)

I've tested this modification under Jetspeed-2 (/WEB-INF/pages/default-page.psml).
The portlet fragment can be added with preferences like the following:

        &lt;fragment id="dp-19" type="portlet" name="cocoon::CocoonPortlet"&gt;
            &lt;property name="row" value="6"/&gt;
            &lt;property name="column" value="0"/&gt;
            &lt;preference name="servlet-path" readOnly="true"&gt;
                &lt;value&gt;samples/blocks/portal/portlets/helloworld</value&gt;
            &lt;/preference&gt;
        &lt;/fragment&gt;


Thanks for reading.
Any comment welcomed.

-Woonsan Ko


Index: ManagedCocoonPortlet.java

===================================================================

--- ManagedCocoonPortlet.java	(revision 418241)

+++ ManagedCocoonPortlet.java	(working copy)

@@ -50,6 +50,7 @@

 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.PortletRequest;
+import javax.portlet.PortletPreferences;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -172,6 +173,11 @@

     protected boolean storeSessionPath;
 
     /**
+     * Allow preferences to be set by preferences.
+     */
+    private boolean allowPreferences = false;
+
+    /**
      * Initialize this <code>CocoonPortlet</code> instance.
      *
      * <p>Uses the following parameters:
@@ -353,6 +359,8 @@

         }
 
         this.storeSessionPath = getInitParameterAsBoolean("store-session-path", false);
+
+        this.allowPreferences = getInitParameterAsBoolean("allow-preferences", false);
     }
 
     public void processAction(ActionRequest req, ActionResponse res)
@@ -400,6 +408,28 @@

         if (servletPath == null) {
             servletPath = "portlets/" + getPortletConfig().getPortletName();
         }
+
+        // allow servlet-path override by the request
+        String reqServletPath = (String) request.getAttribute("servlet-path");
+        if (reqServletPath != null) {
+            this.servletPath = reqServletPath;
+        } 
+        // allow servlet-path override by the preferences
+        else if (this.allowPreferences == true) {
+            PortletPreferences prefs = request.getPreferences();
+            
+            if (prefs != null && reqServletPath == null) {
+                this.servletPath = prefs.getValue("servlet-path", this.servletPath);
+            }          
+        }
+
+        if (this.servletPath.startsWith("/")) {
+            this.servletPath = this.servletPath.substring(1);
+        }
+        if (this.servletPath.endsWith("/")) {
+            this.servletPath = servletPath.substring(0, servletPath.length() - 1);
+        }
+
         String pathInfo = getPathInfo(request);
 
         String uri = servletPath;
@@ -547,6 +577,28 @@

         if (servletPath == null) {
             servletPath = "portlets/" + getPortletConfig().getPortletName();
         }
+
+        // allow servlet-path override by the request
+        String reqServletPath = (String) request.getAttribute("servlet-path");
+        if (reqServletPath != null) {
+            this.servletPath = reqServletPath;
+        } 
+        // allow servlet-path override by the preferences
+        else if (this.allowPreferences == true) {
+            PortletPreferences prefs = request.getPreferences();
+            
+            if (prefs != null && reqServletPath == null) {
+                this.servletPath = prefs.getValue("servlet-path", this.servletPath);
+            }          
+        }
+
+        if (this.servletPath.startsWith("/")) {
+            this.servletPath = this.servletPath.substring(1);
+        }
+        if (this.servletPath.endsWith("/")) {
+            this.servletPath = servletPath.substring(0, servletPath.length() - 1);
+        }
+
         String pathInfo = getPathInfo(request);
 
         String uri = servletPath;


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Mime
View raw message