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 ra...@apache.org on 2001/06/25 12:54:09 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls PanedPortletControl.java VelocityPortletControl.java VelocityPortletSetControl.java
raphael 01/06/25 03:54:09
Modified: src/java/org/apache/jetspeed/modules/actions/controllers
VelocityControllerAction.java
src/java/org/apache/jetspeed/modules/actions/portlets
CustomizeSetAction.java VelocityPortletAction.java
src/java/org/apache/jetspeed/portal/controllers
CardPortletController.java
VelocityPortletController.java
src/java/org/apache/jetspeed/portal/controls
PanedPortletControl.java
VelocityPortletControl.java
VelocityPortletSetControl.java
Added: src/java/org/apache/jetspeed/modules/actions/controllers
PanedControllerAction.java
src/java/org/apache/jetspeed/portal
PanedPortletController.java
src/java/org/apache/jetspeed/portal/controllers
VelocityPanedPortletController.java
Log:
- add some Velocity based Controller implementations
- fix a PortletAction processing bug
- implement default customization behavior for VelocityControllers
Revision Changes Path
1.2 +68 -7 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/controllers/VelocityControllerAction.java
Index: VelocityControllerAction.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/controllers/VelocityControllerAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- VelocityControllerAction.java 2001/06/09 15:35:39 1.1
+++ VelocityControllerAction.java 2001/06/25 10:53:30 1.2
@@ -54,11 +54,15 @@
package org.apache.jetspeed.modules.actions.controllers;
+import org.apache.jetspeed.portal.PortalState;
import org.apache.jetspeed.portal.PortletController;
+import org.apache.jetspeed.om.profile.PSMLDocument;
+import org.apache.jetspeed.services.rundata.JetspeedRunData;
// Turbine stuff
import org.apache.turbine.util.Log;
import org.apache.turbine.util.RunData;
+import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.modules.Action;
import org.apache.turbine.modules.actions.VelocityAction;
@@ -89,16 +93,28 @@
protected void perform( RunData rundata )
throws Exception
{
- try
+ // first try to see if there are some events registered for this
+ // action...
+ Context context = getContext(rundata);
+ if (context != null)
{
- // first try to see if there are some events registered for this
- // action...
- executeEvents(rundata, getContext(rundata) );
+ // if context is already defined, events have already been
+ // processed, call doPerform
+ doPerform(rundata);
}
- catch (NoSuchMethodException e)
+ else
{
- // no event selected
- doPerform(rundata);
+ context = TurbineVelocity.getContext();
+ rundata.getTemplateInfo().setTemplateContext("VelocityActionContext",context);
+ try
+ {
+ executeEvents(rundata, context );
+ }
+ catch (NoSuchMethodException e)
+ {
+ // no event selected
+ doPerform(rundata);
+ }
}
}
@@ -131,6 +147,16 @@
{
PortletController controller = (PortletController)context.get( "controller" );
+ String name = controller.getPortlets().getName();
+
+ // if we're in customization mode for the given set, handle
+ // customization
+ if ( (name != null) && (name.equals(PortalState.getCustomized(rundata))) )
+ {
+ buildCustomizeContext( controller, context, rundata);
+ return;
+ }
+
buildNormalContext( controller, context, rundata);
}
@@ -138,8 +164,43 @@
* Subclasses must override this method to provide default behavior
* for the portlet action
*/
+ protected void buildCustomizeContext( PortletController controller,
+ Context context,
+ RunData rundata )
+ {
+ String name = controller.getPortlets().getName();
+ String template = (String)context.get("template");
+
+ int dotIdx = template.lastIndexOf('.');
+ if (dotIdx > -1)
+ {
+ template = template.substring(0,dotIdx)
+ + "-customize.vm";
+ }
+ else
+ {
+ template = template+"-customize";
+ }
+
+ setTemplate(rundata, template);
+
+ context.put( "action", controller.getConfig().getInitParameter("action"));
+ context.put( "paneid", name );
+ }
+
+ /**
+ * Subclasses must override this method to provide default behavior
+ * for the portlet action
+ */
protected abstract void buildNormalContext( PortletController controller,
Context context,
RunData rundata );
+
+ /** Switch out of customize mode
+ */
+ public void doCancel(RunData data, Context context)
+ {
+ PortalState.reset(data);
+ }
}
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/controllers/PanedControllerAction.java
Index: PanedControllerAction.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.controllers;
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletSet;
import org.apache.jetspeed.portal.PortletController;
import org.apache.jetspeed.portal.PortletControllerConfig;
import org.apache.jetspeed.portal.PanedPortletController;
import org.apache.jetspeed.portal.PortalState;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
import org.apache.jetspeed.xml.api.portletmarkup.Entry;
import org.apache.jetspeed.xml.api.portletmarkup.Metainfo;
import org.apache.jetspeed.xml.api.portletmarkup.Layout;
// Turbine stuff
import org.apache.turbine.util.Log;
import org.apache.turbine.util.RunData;
// Velocity Stuff
import org.apache.velocity.context.Context;
import java.util.Enumeration;
/**
* This action builds a context suitable for controllers portlets
* in panes, ie with only a subsetof defined portlets defined at any
* time.
* Should be associated with a controller implementing PanedPortletController
* to work correctly
*
* @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
*/
public class PanedControllerAction extends VelocityControllerAction
{
/**
* Adds a "pane" portlet object in the context which represents the
* currently selected pane
*/
protected void buildNormalContext( PortletController controller,
Context context,
RunData rundata )
{
PanedPortletController cont = (PanedPortletController)controller;
PortletSet myPortlets = cont.getPortlets();
PortletControllerConfig conf = cont.getConfig();
String pane = cont.retrievePaneName(rundata);
Log.debug("PanedController: pane requested "+pane);
boolean searchTitle = false;
int paneNum = 0;
try
{
paneNum = Integer.parseInt( pane );
}
catch (Exception e)
{
paneNum = 0;
searchTitle = true;
}
if ( ( paneNum >= myPortlets.size() ) || ( paneNum <0 ) )
{
paneNum = 0;
}
boolean found = false;
// first search in the child titles
if ( searchTitle == true )
{
Enumeration en = myPortlets.getPortlets();
while ( en.hasMoreElements() && ( ! found ) )
{
Portlet p = (Portlet)en.nextElement();
if ( p.getTitle().equals(pane) )
{
context.put("pane", p );
pane = p.getTitle();
found=true;
}
}
}
// then in the explicit position field
if (!found)
{
Enumeration en = myPortlets.getPortlets();
while ( en.hasMoreElements() && ( ! found ) )
{
Portlet p = (Portlet)en.nextElement();
if ( p.getPortletConfig().getPosition() == paneNum )
{
context.put("pane", p );
pane = String.valueOf( paneNum );
found=true;
}
}
}
// then in the implicit position
if (!found)
{
context.put("pane",myPortlets.getPortletAt(paneNum));
pane = String.valueOf( paneNum );
}
Log.debug("PanedController: pane found "+pane+" context object "+context.get("pane"));
cont.savePaneName(rundata,pane);
}
/**
* This method is used to add a new pane in the current controller
* The pane is always added at the end of the current set.
* This methods expects the following parameters to work:
* - paneid: the id a the pane to modify within the current profile
* - title: the title for the new pane to be included
*/
public void doAdd(RunData data, Context context)
{
String paneid = data.getParameters().getString("paneid");
String title = data.getParameters().getString("title");
Profile profile = ((JetspeedRunData)data).getProfile();
if ((paneid != null) && (title != null))
{
Portlets set = profile.getDocument().getPortlets(paneid);
if (set != null)
{
Portlets newset = new Portlets();
Metainfo meta = new Metainfo();
meta.setTitle(title);
newset.setMetainfo(meta);
set.addPortlets(newset);
try
{
profile.store();
}
catch (Exception e)
{
Log.error("Error while saving profile",e);
}
}
}
}
/** Remove a pane from the current set
* This method expects the following parameters
* - paneid: the id a the pane to modify within the current profile
* - position: the position of the component to delete
*/
public void doDelete(RunData data, Context context)
{
String paneid = data.getParameters().getString("paneid");
int position = data.getParameters().getInt("position",-1);
Profile profile = ((JetspeedRunData)data).getProfile();
if ((paneid != null) && (position > -1))
{
Portlets set = profile.getDocument().getPortlets(paneid);
if (set != null)
{
// first try explicit portlets position
for(int i=0; i < set.getPortletsCount(); i++)
{
Portlets p = set.getPortlets(i);
Layout layout = p.getLayout();
if (layout!=null)
{
int lpos = Integer.parseInt(layout.getPosition());
if (lpos==position)
{
set.removePortlets(i);
try
{
profile.store();
}
catch (Exception e)
{
Log.error("Error while saving profile",e);
}
return;
}
}
}
// try explicit entry position
for(int i=0; i < set.getEntryCount(); i++)
{
Entry p = set.getEntry(i);
Layout layout = p.getLayout();
if (layout!=null)
{
int lpos = Integer.parseInt(layout.getPosition());
if (lpos==position)
{
set.removeEntry(i);
try
{
profile.store();
}
catch (Exception e)
{
Log.error("Error while saving profile",e);
}
return;
}
}
}
//else use implicit position
if (position < set.getPortletsCount())
{
set.removePortlets(position);
try
{
profile.store();
}
catch (Exception e)
{
Log.error("Error while saving profile",e);
}
return;
}
if (position < set.getEntryCount())
{
set.removeEntry(position);
try
{
profile.store();
}
catch (Exception e)
{
Log.error("Error while saving profile",e);
}
return;
}
}
}
}
/** Move a component up within the pane
* This method expects the following parameters
* - paneid: the id a the pane to modify within the current profile
* - position: move the component which occupies this position
*/
public void doUp(RunData data, Context context)
{
doMove(data,context,true);
}
/** Move a component down within the pane
* This method expects the following parameters
* - paneid: the id a the pane to modify within the current profile
* - position: move the component which occupies this position
*/
public void doDown(RunData data, Context context)
{
doMove(data,context,false);
}
/** Move a component within the pane
* This method expects the following parameters
* - paneid: the id a the pane to modify within the current profile
* - position: move the component which occupies this position
* The moveUp boolean determines the direction of the move
*/
public void doMove(RunData data, Context context, boolean moveUp)
{
String paneid = data.getParameters().getString("paneid");
int position = data.getParameters().getInt("position",-1);
Profile profile = ((JetspeedRunData)data).getProfile();
if ((paneid != null) && (position > -1))
{
int target = -1;
Portlets set = profile.getDocument().getPortlets(paneid);
Layout targetLayout = null;
Layout baseLayout = null;
if (set != null)
{
// check if we can possibly move as requested and calculate
// target position
if ( moveUp )
{
if ( (position >= set.getPortletsCount())
&& (position >= set.getEntryCount()) ) return;
target = position + 1;
}
else
{
if (position ==0) return;
target = position - 1;
}
// first find objects at explicit portlets position
for(int i=0; i < set.getPortletsCount(); i++)
{
if ((targetLayout!=null) && (baseLayout!=null)) break;
Portlets p = set.getPortlets(i);
Layout layout = p.getLayout();
if (layout!=null)
{
int lpos = Integer.parseInt(layout.getPosition());
if ((baseLayout == null) && (lpos==position))
{
baseLayout = layout;
}
if ((targetLayout == null) && (lpos==target))
{
targetLayout = layout;
}
}
}
// try explicit entry position
for(int i=0; i < set.getEntryCount(); i++)
{
if ((targetLayout!=null) && (baseLayout!=null)) break;
Entry p = set.getEntry(i);
Layout layout = p.getLayout();
if (layout!=null)
{
int lpos = Integer.parseInt(layout.getPosition());
if ((baseLayout == null) && (lpos==position))
{
baseLayout = layout;
}
if ((targetLayout == null) && (lpos==target))
{
targetLayout = layout;
}
}
}
//else use implicit position
if (baseLayout == null)
{
if (position < set.getPortletsCount())
{
Portlets p = set.getPortlets(position);
if (p.getLayout()==null)
{
p.setLayout(new Layout());
}
baseLayout=p.getLayout();
}
if (position < set.getEntryCount())
{
Entry p = set.getEntry(position);
if (p.getLayout()==null)
{
p.setLayout(new Layout());
}
baseLayout=p.getLayout();
}
}
if (targetLayout == null)
{
if (target < set.getPortletsCount())
{
Portlets p = set.getPortlets(target);
if (p.getLayout()==null)
{
p.setLayout(new Layout());
}
targetLayout=p.getLayout();
}
if (target < set.getEntryCount())
{
Entry p = set.getEntry(target);
if (p.getLayout()==null)
{
p.setLayout(new Layout());
}
targetLayout=p.getLayout();
}
}
//we should now have found both baseLayout and targetLayout, swap
//their positions using explicit positioning
if ((baseLayout == null) || (targetLayout == null)) return;
baseLayout.setPosition(String.valueOf(target));
targetLayout.setPosition(String.valueOf(position));
try
{
profile.store();
}
catch (Exception e)
{
Log.error("Error while saving profile",e);
}
}
}
}
}
1.2 +81 -11 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/CustomizeSetAction.java
Index: CustomizeSetAction.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/CustomizeSetAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CustomizeSetAction.java 2001/06/04 17:18:42 1.1
+++ CustomizeSetAction.java 2001/06/25 10:53:37 1.2
@@ -61,6 +61,11 @@
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.services.PortalToolkit;
+import org.apache.jetspeed.services.rundata.JetspeedRunData;
+import org.apache.jetspeed.om.profile.Profile;
+import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
+import org.apache.jetspeed.xml.api.portletmarkup.Skin;
+import org.apache.jetspeed.xml.api.portletmarkup.Controller;
// Turbine stuff
import org.apache.turbine.util.Log;
@@ -115,12 +120,12 @@
}
/** Updates the customized portlet entry */
- public void doUpdate(RunData rundata, Context context)
+ public void doLayout(RunData rundata, Context context)
{
// we should first retrieve the portlet to customize and its parameters
// definition
PortletSet set = (PortletSet)rundata.getSession().getAttribute("customize");
-
+
if (set==null)
{
//default to build normal
@@ -129,11 +134,8 @@
}
try
- {
- // FIXME: we need to make the change persistent
-
+ {
String controller = rundata.getParameters().getString("controller");
- String skin = rundata.getParameters().getString("skin");
if (controller!=null)
{
@@ -142,22 +144,90 @@
if (pc!=null)
{
set.setController(pc);
+
+ Profile profile = ((JetspeedRunData)rundata).getProfile();
+ Portlets portlets = profile.getDocument().getPortlets(set.getName());
+
+ Controller c = portlets.getController();
+ if (c == null)
+ {
+ c = new Controller();
+ portlets.setController(c);
+ }
+ c.setName(controller);
+
+ try
+ {
+ profile.store();
+ }
+ catch (Exception e)
+ {
+ Log.error("Exception occured while saving PSML",e);
+ }
}
}
+
+ // we're done, make sure clean up the
+ // session
+ doCancel(rundata, context);
+ }
+ catch (Exception e)
+ {
+ Log.error(e);
+ }
+
+ }
+
+ /** Updates the customized portlet entry */
+ public void doSkin(RunData rundata, Context context)
+ {
+ // we should first retrieve the portlet to customize and its parameters
+ // definition
+ PortletSet set = (PortletSet)rundata.getSession().getAttribute("customize");
+
+ if (set==null)
+ {
+ //default to build normal
+ buildNormalContext(null,context,rundata);
+ return;
+ }
+
+ try
+ {
+ String skin = rundata.getParameters().getString("skin");
+
if (skin!=null)
{
- PortletSkin skinObject = PortalToolkit.getSkin(skin);
+ PortletSkin s = PortalToolkit.getSkin(skin);
- if (skinObject!=null)
+ if (s!=null)
{
- set.getPortletConfig().setPortletSkin(skinObject);
+ set.getPortletConfig().setPortletSkin(s);
+
+ Profile profile = ((JetspeedRunData)rundata).getProfile();
+ Portlets portlets = profile.getDocument().getPortlets(set.getName());
+
+ Skin psmlSkin = portlets.getSkin();
+ if (psmlSkin == null)
+ {
+ portlets.setSkin(new Skin());
+ }
+ portlets.getSkin().setName(skin);
+
+ try
+ {
+ profile.store();
+ }
+ catch (Exception e)
+ {
+ Log.error("Exception occured while saving PSML",e);
+ }
}
}
// we're done, make sure clean up the
// session
- rundata.getSession().removeAttribute("customize");
- PortalState.reset(rundata);
+ doCancel(rundata, context);
}
catch (Exception e)
{
1.2 +20 -7 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/VelocityPortletAction.java
Index: VelocityPortletAction.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/VelocityPortletAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- VelocityPortletAction.java 2001/05/29 23:15:42 1.1
+++ VelocityPortletAction.java 2001/06/25 10:53:39 1.2
@@ -60,6 +60,7 @@
// Turbine stuff
import org.apache.turbine.util.Log;
import org.apache.turbine.util.RunData;
+import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.modules.Action;
import org.apache.turbine.modules.actions.VelocityAction;
@@ -90,16 +91,28 @@
protected void perform( RunData rundata )
throws Exception
{
- try
+ // first try to see if there are some events registered for this
+ // action...
+ Context context = getContext(rundata);
+ if (context != null)
{
- // first try to see if there are some events registered for this
- // action...
- executeEvents(rundata, getContext(rundata) );
+ // if context is already defined, events have already been
+ // processed, call doPerform
+ doPerform(rundata);
}
- catch (NoSuchMethodException e)
+ else
{
- // no event selected
- doPerform(rundata);
+ context = TurbineVelocity.getContext();
+ rundata.getTemplateInfo().setTemplateContext("VelocityActionContext",context);
+ try
+ {
+ executeEvents(rundata, context );
+ }
+ catch (NoSuchMethodException e)
+ {
+ // no event selected
+ doPerform(rundata);
+ }
}
}
1.5 +80 -285 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/PanedPortletController.java
1.18 +35 -1 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/CardPortletController.java
Index: CardPortletController.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/CardPortletController.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- CardPortletController.java 2001/06/06 22:29:01 1.17
+++ CardPortletController.java 2001/06/25 10:53:48 1.18
@@ -81,9 +81,10 @@
or with an invalid value, use the first portlet (position 0)</li>
</p>
@author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
-@version $Id: CardPortletController.java,v 1.17 2001/06/06 22:29:01 raphael Exp $
+@version $Id: CardPortletController.java,v 1.18 2001/06/25 10:53:48 raphael Exp $
*/
public class CardPortletController extends AbstractPortletController
+ implements PanedPortletController
{
public static final String DEFAULT_PARAMETER = "card";
@@ -272,6 +273,39 @@
}
return uri;
+ }
+
+ /**
+ * Returns the name of the parameter used for pane selection
+ */
+ public String retrievePaneName(RunData rundata)
+ {
+ String pane = rundata.getParameters().getString( getParameterName() );
+
+ if (pane == null)
+ {
+ // the parameter is undefined, search for sticky value in session
+ pane = (String)rundata.getUser().getTemp( "pane-"+getParameterName() );
+
+ if (pane == null)
+ {
+ // use default
+ pane = getConfig().getInitParameter( "defaultpane", "0" );
+ }
+ }
+
+ return pane;
+ }
+
+ /**
+ * Sets the name of the parameter that will define which pane should
+ * be displayed
+ *
+ * @param name the selection parameter name
+ */
+ public void savePaneName( RunData data, String name )
+ {
+ data.getUser().setTemp( "pane-"+getParameterName(), name );
}
/**
1.2 +5 -7 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/VelocityPortletController.java
Index: VelocityPortletController.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/VelocityPortletController.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- VelocityPortletController.java 2001/06/09 15:35:03 1.1
+++ VelocityPortletController.java 2001/06/25 10:53:51 1.2
@@ -74,7 +74,7 @@
import org.apache.turbine.util.Log;
/**
- * A Velocity based portlet implementation
+ * A Velocity based portlet controller implementation
*
* @author <a href="mailto:re_carrasco@bco011.sonda.cl">Roberto Carrasco</a>
* @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
@@ -86,10 +86,13 @@
// create a blank context and with all the global application
// Pull Tools inside
Context context = TurbineVelocity.getContext();
+
context.put( "data", rundata );
context.put( "controller", this );
+ context.put( "portlets", this.getPortlets().toArray() );
context.put( "conf", this.getConfig() );
-
+ context.put( "template", getConfig().getInitParameter("template") );
+
// Put the request and session based contexts
TurbinePull.populateContext(context, rundata);
@@ -118,11 +121,6 @@
// defined in the registry
String template = (String)context.get( "template" );
- if (template == null)
- {
- template = getConfig().getInitParameter("template");
- }
-
// generate the content
String s = null;
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controllers/VelocityPanedPortletController.java
Index: VelocityPanedPortletController.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.portal.controllers;
// Turbine stuff
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.DynamicURI;
// Jetspeed stuff
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PanedPortletController;
import org.apache.jetspeed.util.MetaData;
/**
* A Velocity based portlet controller implementation that can be used
* to manage paned content (ie, where a only a subset of all portlets
* is visible at any given time)
*
* @author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
*/
public class VelocityPanedPortletController extends VelocityPortletController
implements PanedPortletController
{
public static final String DEFAULT_PARAMETER = "pane";
/**
* Test whether the selected portlet is considered selected for the current
* request.
*
* @param p the Portlet to check
* @param rundata the RunData for the request
* @return true if the portlet is selected, false otherwise
*/
public boolean isSelected( Portlet p, RunData rundata )
{
String pane = retrievePaneName(rundata);
boolean searchTitle = false;
int paneNum = 0;
//should we test based on name/title or position
try
{
paneNum = Integer.parseInt( pane );
} catch (Exception e) {
paneNum = 0;
searchTitle = true;
}
// first search in the child titles...
if ( searchTitle == true )
{
return ( p.getName().equals(pane) || p.getTitle().equals(pane) );
}
else
{
// ...then explicit position parameters...
if ( p.getPortletConfig().getPosition() == paneNum )
{
return true;
}
}
// ...finally test implicit position
// sanity check: the position sought should be positive and lower than set size
if ( ( paneNum >= getPortlets().size() ) || ( paneNum <0 ) )
{
return false;
}
return ( getPortlets().getPortletAt( paneNum ) == p );
}
/**
Builds the link to access to a given pane.
*/
public DynamicURI getPortletURI( Portlet p, RunData rundata )
{
String title = p.getTitle();
DynamicURI uri = new DynamicURI( rundata );
uri.removePathInfo( getParameterName() );
uri.removeQueryData( getParameterName() );
if ( MetaData.DEFAULT_TITLE.equals( title ) )
{
uri.addPathInfo( getParameterName(), p.getPortletConfig().getPosition() );
}
else
{
uri.addPathInfo( getParameterName(), title );
}
return uri;
}
/**
* Sets the name of the parameter that will define which pane should
* be displayed
*
* @param name the selection parameter name
*/
public void setParameterName( String name )
{
getConfig().setInitParameter( "parameter", name );
}
/**
* Returns the name of the parameter used for pane selection
*/
public String getParameterName()
{
return getConfig().getInitParameter( "parameter", DEFAULT_PARAMETER );
}
/**
* Returns the name of the parameter used for pane selection
*/
public String retrievePaneName(RunData rundata)
{
String pane = rundata.getParameters().getString( getParameterName() );
if (pane == null)
{
// the parameter is undefined, search for sticky value in session
pane = (String)rundata.getUser().getTemp( "pane-"+getParameterName() );
if (pane == null)
{
// use default
pane = getConfig().getInitParameter( "defaultpane", "0" );
}
}
return pane;
}
/**
* Sets the name of the parameter that will define which pane should
* be displayed
*
* @param name the selection parameter name
*/
public void savePaneName( RunData data, String name )
{
data.getUser().setTemp( "pane-"+getParameterName(), name );
}
}
1.18 +5 -6 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls/PanedPortletControl.java
Index: PanedPortletControl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls/PanedPortletControl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- PanedPortletControl.java 2001/05/29 22:54:52 1.17
+++ PanedPortletControl.java 2001/06/25 10:53:57 1.18
@@ -59,7 +59,6 @@
import java.util.Enumeration;
import org.apache.jetspeed.portal.*;
-import org.apache.jetspeed.portal.controllers.CardPortletController;
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.turbine.util.DynamicURI;
import org.apache.turbine.util.RunData;
@@ -70,12 +69,12 @@
/**
The PanedPortletControl is a portletControl specifically designed
-to work with a CardPortletController to provide a pane functionality
+to work with a PanedPortletController to provide a pane functionality
<p>It draws in a vertical or horizontal bar titles "tabs" corresponding to each
portlet corresponding to the PortletSet managed</p>
@author <a href="mailto:raphael@apache.org">Rapha�l Luta</a>
-@version $Id: PanedPortletControl.java,v 1.17 2001/05/29 22:54:52 raphael Exp $
+@version $Id: PanedPortletControl.java,v 1.18 2001/06/25 10:53:57 raphael Exp $
*/
public class PanedPortletControl extends AbstractPortletControl {
@@ -296,7 +295,7 @@
TD[] cells = null;
int position = getPosition();
int selected = 0;
- CardPortletController controller = null;
+ PanedPortletController controller = null;
if ( portlet instanceof PortletSet ) {
p = ((PortletSet)portlet).toArray();
@@ -304,8 +303,8 @@
PortletController ctrlr = ((PortletSet)portlet).getController();
- if ( ctrlr instanceof CardPortletController ) {
- controller = (CardPortletController) ctrlr;
+ if ( ctrlr instanceof PanedPortletController ) {
+ controller = (PanedPortletController) ctrlr;
}
} else {
p = new Portlet[1];
1.7 +4 -47 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls/VelocityPortletControl.java
Index: VelocityPortletControl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls/VelocityPortletControl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- VelocityPortletControl.java 2001/06/09 15:34:35 1.6
+++ VelocityPortletControl.java 2001/06/25 10:53:59 1.7
@@ -129,15 +129,15 @@
context.put("actions", buildActionList( rundata, portlet ) );
context.put("config", getConfig() );
context.put("skin", portlet.getPortletConfig().getPortletSkin() );
+ context.put("customized", PortalState.getCustomized(rundata));
// Put the request and session based contexts
TurbinePull.populateContext(context, rundata);
- if ( portlet.getName().equals(PortalState.getCustomized(rundata))
+ if ( portlet.getName().equals(PortalState.getCustomized(rundata))
&& (! (portlet instanceof PortletCustomizer) ) )
- {
- Log.note("Portlet "+portlet.getName()+" customized, using default customizer");
- context.put("portlet",getCustomizer(portlet, rundata));
+ {
+ context.put("portlet",PortalState.getCustomizer(portlet, rundata));
}
else
{
@@ -147,8 +147,6 @@
// allow subclasses to add elements to the context
buildContext( rundata, context );
- //FIXME: add tree traversal for handling media types and languages
- //consolidate with the other tree traversal routines...
String theme = getConfig().getInitParameter("theme","default.vm");
String s = null;
@@ -165,47 +163,6 @@
TurbineVelocity.requestFinished(context);
return new StringElement( s );
- }
-
- /** This method retrieves the appropriate customizer portlet for the
- * current portlet
- *
- * @param p the portlet to customize
- * @param data the RunData for this request
- * @return the portlet object of the appropriate customizer
- */
- public Portlet getCustomizer(Portlet p, RunData data)
- {
- Portlet customizer = p;
-
- // if the portlet cannot customize itself...
- if (! (p instanceof PortletCustomizer) )
- {
-
- //look for the customizer name in the portlet
- //config (from Registry definition)
-
- String name = p.getPortletConfig().getInitParameter("_customizer");
-
- if (name == null)
- {
- String key = (p instanceof PortletSet)?"PortletSet":"Portlet";
-
- name = JetspeedResources.getString("customizer."+key,key+"Customizer");
- }
-
- try
- {
- customizer = PortletFactory.getPortlet(name);
- data.getSession().setAttribute("customize", p);
- }
- catch (Exception e)
- {
- Log.error(e);
- }
- }
-
- return customizer;
}
/**
1.2 +6 -6 jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls/VelocityPortletSetControl.java
Index: VelocityPortletSetControl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/controls/VelocityPortletSetControl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- VelocityPortletSetControl.java 2001/05/29 22:54:37 1.1
+++ VelocityPortletSetControl.java 2001/06/25 10:54:00 1.2
@@ -62,7 +62,7 @@
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletSet;
import org.apache.jetspeed.portal.PortletState;
-import org.apache.jetspeed.portal.controllers.CardPortletController;
+import org.apache.jetspeed.portal.PanedPortletController;
// Velocity Stuff
import org.apache.velocity.context.Context;
@@ -99,7 +99,7 @@
* Each tab represents a child portlet.
*
* This method works best if the child of this control is a PortletSet
- * whose controller implements the SelectableController interface.
+ * whose controller implements the PanedPortletController interface.
*
* @param portlet the base portlet to explore for children
* @
@@ -108,13 +108,13 @@
{
Vector tabs = new Vector();
- CardPortletController controller = null;
+ PanedPortletController controller = null;
// if portlet is a PortletSet, try to retrieve the Controller
- // we need a SelectableController to work properly.
- if ( portlets.getController() instanceof CardPortletController )
+ // we need a PanedPortletController to work properly.
+ if ( portlets.getController() instanceof PanedPortletController )
{
- controller = (CardPortletController) portlets.getController();
+ controller = (PanedPortletController) portlets.getController();
}
for ( Enumeration en = portlets.getPortlets(); en.hasMoreElements(); )
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org