You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by mo...@apache.org on 2002/09/20 23:19:38 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util PortletConfigState.java PortletSessionState.java
morciuch 2002/09/20 14:19:37
Modified: src/java/org/apache/jetspeed/portal/portlets JspPortlet.java
src/java/org/apache/jetspeed/util PortletConfigState.java
PortletSessionState.java
Added: src/java/org/apache/jetspeed/modules/actions JspAction.java
src/java/org/apache/jetspeed/modules/actions/portlets
JspPortletAction.java
Log:
Improvements to jsp support (see Bugzilla issue# 11864):
1. Implementation of JspAction and JspPortletAction.
2. Ability to use PortletConfigState and PortletSessionState with non-Velocity portlets.
3. Attribute "js_peid" is now available within underlying template for JspPortlet
Revision Changes Path
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JspAction.java
Index: JspAction.java
===================================================================
package org.apache.turbine.modules.actions;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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" and "Apache Software Foundation" and
* "Apache Turbine" 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",
* "Apache Turbine", 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 (INCLUDING, 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
// Turbine Stuff
import org.apache.turbine.util.RunData;
import org.apache.turbine.modules.screens.TemplateScreen;
import org.apache.turbine.modules.ActionEvent;
/**
* This class provides a convenience methods for Jsp Actions
* to use. Since this class is abstract, it should only be extended
* and not used directly.
*
* @author <a href="mailto:morciuch@apache.org">Mark ORciuch</a>
* @version $Id: JspAction.java,v 1.1 2002/09/20 21:19:37 morciuch Exp $
*/
public abstract class JspAction extends ActionEvent
{
/**
* Sets up the context and then calls super.perform(); thus,
* subclasses don't have to worry about getting a context
* themselves!
*
* @param data Turbine information.
* @exception Exception, a generic exception.
*/
protected void perform(RunData data)
throws Exception
{
super.perform(data);
}
/**
* This method is used when you want to short circuit an Action
* and change the template that will be executed next.
*
* @param data Turbine information.
* @param template The template that will be executed next.
*/
public void setTemplate(RunData data, String template)
{
TemplateScreen.setTemplate(data, template);
}
}
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/JspPortletAction.java
Index: JspPortletAction.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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" and "Apache Software Foundation" and
* "Apache Jetspeed" 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" or
* "Apache Jetspeed", 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 (INCLUDING, 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jetspeed.modules.actions.portlets;
// Java stuff
import java.lang.reflect.Method;
import java.util.Enumeration;
// Jetspeed stuff
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.util.PortletSessionState;
// Turbine stuff
import org.apache.turbine.util.Log;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.modules.actions.JspAction;
/**
* An abstract action class to build JspPortlet actions.
*
* <p>Don't call it from the URL, the Portlet and the Action are automatically
* associated through the registry PortletName
*
* @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
*
* @version $Id: JspPortletAction.java,v 1.1 2002/09/20 21:19:37 morciuch Exp $
*/
public abstract class JspPortletAction extends JspAction
{
/**
* This method is used when you want to short circuit an Action
* and change the template that will be executed next.
*
* @param data Turbine information.
* @param template The template that will be executed next.
*/
public void setTemplate(RunData data, String template)
{
data.getRequest().setAttribute("template", template);
}
/**
* Performs the action
*
* @param rundata
* @exception Exception
*/
public void doPerform(RunData rundata)
throws Exception
{
Portlet portlet = (Portlet) rundata.getRequest().getAttribute("portlet");
JetspeedRunData jdata = (JetspeedRunData) rundata;
if (Log.getLogger().isDebugEnabled())
{
Log.debug("JspPortletAction: retrieved portlet: " + portlet);
}
if (portlet != null)
{
// we're bein configured
if ((jdata.getMode() == jdata.CUSTOMIZE)
&& (portlet.getName().equals(jdata.getCustomized().getName())))
{
if (Log.getLogger().isDebugEnabled())
{
Log.debug("JspPortletAction: building customize");
}
buildConfigureContext(portlet, rundata);
return;
}
// we're maximized
if (jdata.getMode() == jdata.MAXIMIZE)
{
if (Log.getLogger().isDebugEnabled())
{
Log.debug("JspPortletAction: building maximize");
}
buildMaximizedContext(portlet, rundata);
return;
}
if (Log.getLogger().isDebugEnabled())
{
Log.debug("JspPortletAction: building normal");
}
buildNormalContext(portlet, rundata);
}
}
/**
* This method should be called to execute the event based system.
*
* @param data Turbine information.
* @exception Exception a generic exception.
*/
public void executeEvents(RunData data)
throws Exception
{
// Name of the button.
String theButton = null;
// Parameter parser.
ParameterParser pp = data.getParameters();
// The arguments to pass to the method to execute.
Object[] args = new Object[2];
// The arguments to the method to find.
Class[] classes = new Class[2];
classes[0] = RunData.class;
classes[1] = Portlet.class;
String button = pp.convert(BUTTON);
// Loop through and find the button.
for (Enumeration e = pp.keys() ; e.hasMoreElements() ;)
{
String key = (String) e.nextElement();
if (key.startsWith(button))
{
theButton = formatString(key);
break;
}
}
// Portlet context
Portlet portlet = (Portlet) data.getRequest().getAttribute("portlet");
// Ignore submits from other instances of the same portlet
if (theButton == null || !PortletSessionState.isMyRequest(data, portlet))
{
throw new NoSuchMethodException("JspActionEvent: The button was null or not my request");
}
Method method = getClass().getMethod(theButton, classes);
args[0] = data;
args[1] = portlet;
method.invoke(this, args);
}
/**
* Subclasses should override this method if they wish to
* build specific content when maximized. Default behavior is
* to do the same as normal content.
*/
protected void buildMaximizedContext(Portlet portlet, RunData rundata)
throws Exception
{
buildNormalContext(portlet, rundata);
}
/**
* Subclasses should override this method if they wish to
* provide their own customization behavior.
* Default is to use Portal base customizer action
*/
protected void buildConfigureContext(Portlet portlet, RunData rundata)
throws Exception
{
//FIXME: call the default CustomizePortlet action when written
}
/**
* Subclasses must override this method to provide default behavior
* for the portlet action
*/
protected abstract void buildNormalContext(Portlet portlet, RunData rundata)
throws Exception;
}
1.5 +3 -0 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java
Index: JspPortlet.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JspPortlet.java 28 Aug 2002 18:15:55 -0000 1.4
+++ JspPortlet.java 20 Sep 2002 21:19:37 -0000 1.5
@@ -120,6 +120,9 @@
// Allow access to portlet from .jsp template
rundata.getRequest().setAttribute("portlet", this);
+ // Add js_peid out of convenience
+ rundata.getRequest().setAttribute("js_peid", this.getID());
+
// Retrieve and execute the action object
String actionName = getPortletConfig().getInitParameter("action");
if (actionName != null)
1.2 +58 -6 jakarta-jetspeed/src/java/org/apache/jetspeed/util/PortletConfigState.java
Index: PortletConfigState.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/PortletConfigState.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PortletConfigState.java 26 Apr 2002 18:31:13 -0000 1.1
+++ PortletConfigState.java 20 Sep 2002 21:19:37 -0000 1.2
@@ -56,12 +56,14 @@
import org.apache.turbine.util.RunData;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
+import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletConfig;
/**
* Defines standard utility functions for config parameters
*
* @author <a href="mailto:david@apache.org">David Sean Taylor</a>
+ * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
* @version $Id$
*/
public class PortletConfigState
@@ -70,7 +72,7 @@
/**
Returns the parameter for this name from the xreg
*/
- public static String getConfigParameter(VelocityPortlet portlet,
+ public static String getConfigParameter(Portlet portlet,
String attrName,
String attrDefaultValue)
{
@@ -81,7 +83,7 @@
/**
Returns the parameter for this name from the psml
*/
- public static String getInstanceParameter(VelocityPortlet portlet,
+ public static String getInstanceParameter(Portlet portlet,
RunData rundata,
String attrName)
{
@@ -91,7 +93,7 @@
/**
* Sets the parameter in the psml
*/
- public static void setInstanceParameter(VelocityPortlet portlet,
+ public static void setInstanceParameter(Portlet portlet,
RunData rundata,
String attrName,
String attrValue)
@@ -99,7 +101,7 @@
portlet.setAttribute(attrName, attrValue, rundata);
}
- public static void clearInstanceParameter(VelocityPortlet portlet,
+ public static void clearInstanceParameter(Portlet portlet,
RunData rundata,
String attrName)
{
@@ -111,7 +113,7 @@
* Gets the parameter using the fallback routine - first checks PSML,
* in case it doesn't find it then it looks up the registry
*/
- public static String getParameter(VelocityPortlet portlet,
+ public static String getParameter(Portlet portlet,
RunData rundata,
String attrName,
String attrDefValue)
@@ -122,5 +124,55 @@
str = getConfigParameter(portlet, attrName, attrDefValue);
}
return str;
+ }
+
+ /**
+ Returns the parameter for this name from the xreg
+ */
+ public static String getConfigParameter(VelocityPortlet portlet,
+ String attrName,
+ String attrDefaultValue)
+ {
+ return getConfigParameter((Portlet) portlet, attrName, attrDefaultValue);
+ }
+
+ /**
+ Returns the parameter for this name from the psml
+ */
+ public static String getInstanceParameter(VelocityPortlet portlet,
+ RunData rundata,
+ String attrName)
+ {
+ return getInstanceParameter((Portlet) portlet, rundata, attrName);
+ }
+
+ /**
+ * Sets the parameter in the psml
+ */
+ public static void setInstanceParameter(VelocityPortlet portlet,
+ RunData rundata,
+ String attrName,
+ String attrValue)
+ {
+ setInstanceParameter((Portlet) portlet, rundata, attrName, attrValue);
+ }
+
+ public static void clearInstanceParameter(VelocityPortlet portlet,
+ RunData rundata,
+ String attrName)
+ {
+ clearInstanceParameter((Portlet) portlet,rundata,attrName);
+ }
+
+ /*
+ * Gets the parameter using the fallback routine - first checks PSML,
+ * in case it doesn't find it then it looks up the registry
+ */
+ public static String getParameter(VelocityPortlet portlet,
+ RunData rundata,
+ String attrName,
+ String attrDefValue)
+ {
+ return getParameter((Portlet) portlet, rundata, attrName, attrDefValue);
}
}
1.4 +116 -5 jakarta-jetspeed/src/java/org/apache/jetspeed/util/PortletSessionState.java
Index: PortletSessionState.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/PortletSessionState.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PortletSessionState.java 13 Sep 2002 21:55:23 -0000 1.3
+++ PortletSessionState.java 20 Sep 2002 21:19:37 -0000 1.4
@@ -57,12 +57,16 @@
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.Log;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
+import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletConfig;
+import org.apache.jetspeed.services.persistence.PersistenceManager;
+import org.apache.jetspeed.portal.PortletInstance;
/**
* Defines standard utility functions on session attributes
*
* @author <a href="mailto:david@apache.org">David Sean Taylor</a>
+ * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
* @version $Id$
*/
public class PortletSessionState
@@ -108,16 +112,93 @@
* Returns the parameter for this name from the Temp - session object
* Uses the portlet parameter to generate a unique key.
*/
- public static Object getAttribute(VelocityPortlet portlet, RunData rundata, String attrName)
+ public static Object getAttribute(Portlet portlet, RunData rundata, String attrName)
{
return rundata.getUser().getTemp(generateKey(portlet, attrName));
}
/**
+ * Returns the parameter for this name using the following search path:
+ * <ul>
+ * <li>request</li>
+ * <li>session</li>
+ * <li>instance</li>
+ * <li>config</li>
+ * <ul>
+ * Uses the portlet parameter to generate a unique key.
+ *
+ * @param portlet
+ * @param rundata
+ * @param attrName
+ * @return attribute value
+ */
+ public static Object getAttributeWithFallback(Portlet portlet, RunData rundata, String attrName)
+ {
+ Object result = null;
+
+ // Look in the request first
+ if(isMyRequest(rundata, portlet))
+ {
+ result = rundata.getParameters().getString(attrName);
+ if (result != null)
+ {
+ if (result.toString().trim().equalsIgnoreCase(""))
+ {
+ clearAttribute(portlet, rundata, attrName);
+ result = null;
+ }
+ else
+ {
+ setAttribute(portlet, rundata, attrName, result);
+ }
+ }
+ }
+
+ // Look in the session
+ if (result == null)
+ {
+ result = getAttribute(portlet, rundata, attrName);
+ }
+
+ // Look in the instance
+ if (result == null)
+ {
+ result = portlet.getAttribute(attrName, null, rundata);
+ }
+
+ // Finally, look in the config
+ if (result == null)
+ {
+ result = portlet.getPortletConfig().getInitParameter(attrName);
+ }
+
+ return result;
+
+ }
+
+ /**
+ * Returns true if the request pertains to current portlet instance
+ *
+ * @param rundata
+ * @return boolean
+ */
+ public static boolean isMyRequest(RunData rundata, Portlet portlet) {
+
+ PortletInstance instance = PersistenceManager.getInstance(portlet, rundata);
+ String peId = instance.getPortlet().getID();
+
+ //Log.debug("PortletSessionState.isMyRequest: portlet="+ portlet.getName() + ", peid=" + peId + ", js_peid=" + rundata.getParameters().getString("js_peid"));
+ if(peId != null && peId.equals(rundata.getParameters().getString("js_peid")))
+ return true;
+ else
+ return false;
+ }
+
+ /**
* Sets the parameter for this name in Temp
* Uses the portlet parameter to generate a unique key.
*/
- public static void setAttribute(VelocityPortlet portlet,
+ public static void setAttribute(Portlet portlet,
RunData rundata,
String attrName,
Object attrValue)
@@ -129,7 +210,7 @@
* Clears the parameter for this name from Temp
* Uses the portlet parameter to generate a unique key.
*/
- public static void clearAttribute(VelocityPortlet portlet, RunData rundata, String attrName)
+ public static void clearAttribute(Portlet portlet, RunData rundata, String attrName)
{
rundata.getUser().removeTemp(generateKey(portlet, attrName));
}
@@ -137,7 +218,7 @@
/**
* Uses the portlet parameter to generate a unique key, using the portlet.getId.
*/
- protected static String generateKey(VelocityPortlet portlet, String name)
+ protected static String generateKey(Portlet portlet, String name)
{
if (portlet != null)
{
@@ -148,6 +229,36 @@
Log.error("PortletSessionState: Passed null Velocity Portlet for name: " + name);
return name;
}
+ }
+
+ /**
+ * Returns the parameter for this name from the Temp - session object
+ * Uses the portlet parameter to generate a unique key.
+ */
+ public static Object getAttribute(VelocityPortlet portlet, RunData rundata, String attrName)
+ {
+ return getAttribute((Portlet) portlet, rundata, attrName);
+ }
+
+ /**
+ * Sets the parameter for this name in Temp
+ * Uses the portlet parameter to generate a unique key.
+ */
+ public static void setAttribute(VelocityPortlet portlet,
+ RunData rundata,
+ String attrName,
+ Object attrValue)
+ {
+ setAttribute((Portlet) portlet, rundata, attrName, attrValue);
+ }
+
+ /**
+ * Clears the parameter for this name from Temp
+ * Uses the portlet parameter to generate a unique key.
+ */
+ public static void clearAttribute(VelocityPortlet portlet, RunData rundata, String attrName)
+ {
+ clearAttribute((Portlet) portlet, rundata, attrName);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>