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:
<portlet>
<portlet-name>CocoonPortlet</portlet-name>
...
<init-param>
<name>allow-preferences</name>
<value>true</value>
</init-param>
...
</portlet>
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:
<fragment id="dp-19" type="portlet" name="cocoon::CocoonPortlet">
<property name="row" value="6"/>
<property name="column" value="0"/>
<preference name="servlet-path" readOnly="true">
<value>samples/blocks/portal/portlets/helloworld</value>
</preference>
</fragment>
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