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 2005/05/11 03:33:13 UTC
cvs commit: jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html customizer-portlet.vm
morciuch 2005/05/10 18:33:13
Modified: src/java/org/apache/jetspeed/modules/actions/portlets
CustomizeAction.java
webapp/WEB-INF/conf admin.xreg
webapp/WEB-INF/templates/vm/portlets/html
customizer-portlet.vm
Log:
Added ability to set portlet control (decoration) in portler customizer (see issue http://issues.apache.org/jira/browse/JS1-545)
Revision Changes Path
1.32 +212 -86 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/CustomizeAction.java
Index: CustomizeAction.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/CustomizeAction.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- CustomizeAction.java 21 Mar 2005 18:21:36 -0000 1.31
+++ CustomizeAction.java 11 May 2005 01:33:13 -0000 1.32
@@ -17,45 +17,43 @@
package org.apache.jetspeed.modules.actions.portlets;
// Jetspeed Stuff
-import org.apache.jetspeed.modules.actions.portlets.CustomizeSetAction;
-import org.apache.jetspeed.portal.Portlet;
-import org.apache.jetspeed.portal.PortletConfig;
-import org.apache.jetspeed.portal.PortletException;
-import org.apache.jetspeed.portal.PortletSkin;
-import org.apache.jetspeed.portal.portlets.VelocityPortlet;
-import org.apache.jetspeed.services.persistence.PersistenceManager;
-import org.apache.jetspeed.services.Registry;
-import org.apache.jetspeed.services.resources.JetspeedResources;
-import org.apache.jetspeed.services.rundata.JetspeedRunData;
+import java.util.Iterator;
+import java.util.Vector;
+
import org.apache.jetspeed.om.BaseSecurityReference;
+import org.apache.jetspeed.om.SecurityReference;
+import org.apache.jetspeed.om.profile.Control;
import org.apache.jetspeed.om.profile.Entry;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.Skin;
+import org.apache.jetspeed.om.profile.psml.PsmlControl;
import org.apache.jetspeed.om.profile.psml.PsmlSkin;
-import org.apache.jetspeed.om.SecurityReference;
-import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.om.registry.Parameter;
+import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.om.registry.base.BaseParameter;
import org.apache.jetspeed.om.security.JetspeedUser;
+import org.apache.jetspeed.portal.Portlet;
+import org.apache.jetspeed.portal.PortletConfig;
+import org.apache.jetspeed.portal.PortletControl;
+import org.apache.jetspeed.portal.PortletException;
+import org.apache.jetspeed.portal.PortletInstance;
+import org.apache.jetspeed.portal.PortletSkin;
+import org.apache.jetspeed.portal.portlets.VelocityPortlet;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.services.PortalToolkit;
+import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
+import org.apache.jetspeed.services.persistence.PersistenceManager;
+import org.apache.jetspeed.services.resources.JetspeedResources;
+import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.services.security.PortalResource;
-import org.apache.jetspeed.portal.PortletInstance;
-import org.apache.jetspeed.util.MetaData;
import org.apache.jetspeed.services.statemanager.SessionState;
-
-// Turbine stuff
-import org.apache.turbine.util.RunData;
+import org.apache.jetspeed.util.MetaData;
import org.apache.turbine.modules.ActionLoader;
-
-// Velocity Stuff
+import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;
-import java.util.Vector;
-import java.util.Iterator;
-
/**
* This action implements the default portlet behavior customizer
*
@@ -71,9 +69,10 @@
/**
* Static initialization of the logger for this class
- */
- private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(CustomizeAction.class.getName());
-
+ */
+ private static final JetspeedLogger logger =
+ JetspeedLogFactoryService.getLogger(CustomizeAction.class.getName());
+
/**
* Subclasses must override this method to provide default behavior
* for the portlet action
@@ -90,42 +89,54 @@
* <tr><td>security_ref </td><td> Current securityRef for this portlet INSTANCE</td></tr>
* </table>
*/
- protected void buildNormalContext( VelocityPortlet portlet,
- Context context,
- RunData rundata )
+ protected void buildNormalContext(
+ VelocityPortlet portlet,
+ Context context,
+ RunData rundata)
{
-
// generic context stuff
- context.put("skins", CustomizeSetAction.buildList(rundata, Registry.SKIN));
- context.put("securitys", CustomizeSetAction.buildList(rundata, Registry.SECURITY));
+ context.put(
+ "skins",
+ CustomizeSetAction.buildList(rundata, Registry.SKIN));
+ context.put(
+ "securitys",
+ CustomizeSetAction.buildList(rundata, Registry.SECURITY));
// we should first retrieve the portlet to customize
- Portlet p = ((JetspeedRunData)rundata).getCustomized();
+ Portlet p = ((JetspeedRunData) rundata).getCustomized();
context.put("action", "portlets.CustomizeAction");
PortletInstance instance = PersistenceManager.getInstance(p, rundata);
- context.put("portlet_instance", PersistenceManager.getInstance(p, rundata));
+ context.put(
+ "portlet_instance",
+ PersistenceManager.getInstance(p, rundata));
- if (p==null) return;
+ if (p == null)
+ return;
// retrieve the portlet parameters
- PortletEntry entry = (PortletEntry)Registry.getEntry(Registry.PORTLET,p.getName());
+ PortletEntry entry =
+ (PortletEntry) Registry.getEntry(Registry.PORTLET, p.getName());
// save the entry in the session
Vector params = new Vector();
Iterator i = entry.getParameterNames();
//System.out.println("==========================================");
- while(i.hasNext())
+ while (i.hasNext())
{
- String name = (String)i.next();
+ String name = (String) i.next();
Parameter param = entry.getParameter(name);
// filter some "system" and hidden parameters
- if ( (!param.isHidden()) && (name.charAt(0)!='_') )
+ if ((!param.isHidden()) && (name.charAt(0) != '_'))
{
// check the user role
- if (JetspeedSecurity.checkPermission((JetspeedUser)rundata.getUser(), new PortalResource( entry, param), JetspeedSecurity.PERMISSION_CUSTOMIZE))
+ if (JetspeedSecurity
+ .checkPermission(
+ (JetspeedUser) rundata.getUser(),
+ new PortalResource(entry, param),
+ JetspeedSecurity.PERMISSION_CUSTOMIZE))
{
// Implementation of clone() is missing so we have do it "by hand"
Parameter clone = new BaseParameter();
@@ -138,9 +149,11 @@
clone.setValue(instance.getAttribute(name));
//System.out.println("Adding value from instance [" + name + "] = [" + clone.getValue() + "]");
}
- else if (p.getPortletConfig().getInitParameter(name) != null)
+ else if (
+ p.getPortletConfig().getInitParameter(name) != null)
{
- clone.setValue(p.getPortletConfig().getInitParameter(name));
+ clone.setValue(
+ p.getPortletConfig().getInitParameter(name));
//System.out.println("Adding value from init [" + name + "] = [" + clone.getValue() + "]");
}
else
@@ -154,7 +167,8 @@
}
// get the customization state for this page
- SessionState customizationState = ((JetspeedRunData)rundata).getPageSessionState();
+ SessionState customizationState =
+ ((JetspeedRunData) rundata).getPageSessionState();
customizationState.setAttribute("customize-parameters", params);
// populate the customizer context
@@ -163,12 +177,26 @@
context.put("customizer", portlet);
if (p.getPortletConfig().getSecurityRef() != null)
- context.put("security_ref", p.getPortletConfig().getSecurityRef().getParent());
+ context.put(
+ "security_ref",
+ p.getPortletConfig().getSecurityRef().getParent());
if (p.getPortletConfig().getSkin() != null)
- context.put("current_skin", p.getPortletConfig().getPortletSkin().getName());
-
- Profile profile = ((JetspeedRunData)rundata).getCustomizedProfile();
- String currentTitle = profile.getDocument().getEntryById(p.getID()).getTitle();
+ context.put(
+ "current_skin",
+ p.getPortletConfig().getPortletSkin().getName());
+
+ Entry psmlEntry =
+ ((JetspeedRunData) rundata)
+ .getProfile()
+ .getDocument()
+ .getEntryById(
+ p.getID());
+ if (psmlEntry.getControl() != null)
+ context.put("current_control", psmlEntry.getControl().getName());
+
+ Profile profile = ((JetspeedRunData) rundata).getCustomizedProfile();
+ String currentTitle =
+ profile.getDocument().getEntryById(p.getID()).getTitle();
if (currentTitle == null && p.getPortletConfig().getMetainfo() != null)
{
currentTitle = p.getPortletConfig().getMetainfo().getTitle();
@@ -180,17 +208,20 @@
/** Clean up the customization state */
public void doCancel(RunData rundata, Context context)
{
- ((JetspeedRunData)rundata).setCustomized(null);
- if (((JetspeedRunData)rundata).getCustomized()==null)
+ ((JetspeedRunData) rundata).setCustomized(null);
+ if (((JetspeedRunData) rundata).getCustomized() == null)
{
try
{
- String actionName = JetspeedResources.getString(JetspeedResources.CUSTOMIZATION_CANCEL_ACTION, "controls.EndCustomize");
- ActionLoader.getInstance().exec(rundata, actionName);
+ String actionName =
+ JetspeedResources.getString(
+ JetspeedResources.CUSTOMIZATION_CANCEL_ACTION,
+ "controls.EndCustomize");
+ ActionLoader.getInstance().exec(rundata, actionName);
}
catch (Exception e)
{
- logger.error("Unable to load action controls.EndCustomize ",e);
+ logger.error("Unable to load action controls.EndCustomize ", e);
}
}
}
@@ -202,7 +233,7 @@
* @param context
*/
public void doDefault(RunData rundata, Context context)
- {
+ {
// we should first retrieve the portlet to customize and its parameters
// definition
Portlet p = ((JetspeedRunData) rundata).getCustomized();
@@ -210,7 +241,8 @@
// Update paramaters
try
{
- PortletInstance instance = PersistenceManager.getInstance(p, rundata);
+ PortletInstance instance =
+ PersistenceManager.getInstance(p, rundata);
instance.removeAllAttributes();
@@ -220,19 +252,29 @@
}
catch (Exception e)
{
- logger.error("Unable to save profile ",e);
+ logger.error("Unable to save profile ", e);
}
//FIXME: this hack is due to the corrupted lifecycle of the portlet in the
//current API when caching is activated
try
{
- org.apache.jetspeed.util.PortletSessionState.setPortletConfigChanged(p, rundata);
+ org
+ .apache
+ .jetspeed
+ .util
+ .PortletSessionState
+ .setPortletConfigChanged(
+ p,
+ rundata);
p.init();
}
catch (PortletException e)
{
- logger.error("Customizer failed to reinitialize the portlet "+p.getName(), e);
+ logger.error(
+ "Customizer failed to reinitialize the portlet "
+ + p.getName(),
+ e);
}
// we're done, make sure clean up the
@@ -245,32 +287,43 @@
}
}
-
/** Updates the customized portlet entry */
public void doUpdate(RunData rundata, Context context)
{
// get the customization state for this page
- SessionState customizationState = ((JetspeedRunData)rundata).getPageSessionState();
+ SessionState customizationState =
+ ((JetspeedRunData) rundata).getPageSessionState();
// we should first retrieve the portlet to customize and its parameters
// definition
- Portlet p = ((JetspeedRunData)rundata).getCustomized();
- Vector params = (Vector) customizationState.getAttribute("customize-parameters");
- String newSecurityParent = rundata.getParameters().getString("_security_ref");
- String newSkinName = (String) rundata.getParameters().getString("_skin");
- String newTitle = (String) rundata.getParameters().getString("current_title");
-
- boolean changeRequested = ( (params != null) || (newSkinName != null) || (newSecurityParent != null) || (newTitle != null));
+ Portlet p = ((JetspeedRunData) rundata).getCustomized();
+ Vector params =
+ (Vector) customizationState.getAttribute("customize-parameters");
+ String newSecurityParent =
+ rundata.getParameters().getString("_security_ref");
+ String newSkinName =
+ (String) rundata.getParameters().getString("_skin");
+ String newTitle =
+ (String) rundata.getParameters().getString("current_title");
+ String newControlName =
+ (String) rundata.getParameters().getString("_control");
+
+ boolean changeRequested =
+ ((params != null)
+ || (newSkinName != null)
+ || (newSecurityParent != null)
+ || (newTitle != null)
+ || (newControlName != null));
boolean madePsChange = false;
boolean madePcChange = false;
- if ((p==null) || (changeRequested == false ))
+ if ((p == null) || (changeRequested == false))
{
doCancel(rundata, context);
return;
}
PortletConfig pc = p.getPortletConfig();
- Profile profile = ((JetspeedRunData)rundata).getCustomizedProfile();
+ Profile profile = ((JetspeedRunData) rundata).getCustomizedProfile();
Entry entry = profile.getDocument().getEntryById(p.getID());
// Only update the security ref if the parent changed
@@ -280,7 +333,9 @@
SecurityReference currentSecurityRef = pc.getSecurityRef();
if (currentSecurityRef != null)
{
- securityChanged = (newSecurityParent.equals(currentSecurityRef.getParent()) == false);
+ securityChanged =
+ (newSecurityParent.equals(currentSecurityRef.getParent())
+ == false);
}
else
{
@@ -292,7 +347,7 @@
if ((newSecurityParent.trim().length() > 0))
{
securityRef = new BaseSecurityReference();
- securityRef.setParent( newSecurityParent);
+ securityRef.setParent(newSecurityParent);
}
// Note: setting the portlet's config may not be a good idea -
// it might be used as the Portlet for other PSMLDocument Entries that
@@ -310,7 +365,7 @@
boolean skinChanged = false;
String currentSkinName = null;
- if (pc.getSkin() != null)
+ if (pc.getSkin() != null)
currentSkinName = pc.getPortletSkin().getName();
if (currentSkinName != null)
@@ -345,7 +400,12 @@
}
else
{
- logger.warn( "Unable to update skin for portlet entry " + entry.getId() + " because skin " + skin + " does not exist.");
+ logger.warn(
+ "Unable to update skin for portlet entry "
+ + entry.getId()
+ + " because skin "
+ + skin
+ + " does not exist.");
}
}
else
@@ -354,7 +414,7 @@
// it might be used as the Portlet for other PSMLDocument Entries that
// have a different idea of skin - and the caching of Portlets does
// NOT include skin -ggolden.
- pc.setPortletSkin( null);
+ pc.setPortletSkin(null);
entry.setSkin(null);
}
madePcChange = true;
@@ -368,7 +428,7 @@
String currentTitle = entry.getTitle();
MetaData md = pc.getMetainfo();
- if (currentTitle == null && md != null && md.getTitle() != null)
+ if (currentTitle == null && md != null && md.getTitle() != null)
currentTitle = md.getTitle();
if (currentTitle != null)
@@ -389,7 +449,8 @@
// it might be used as the Portlet for other PSMLDocument Entries that
// have a different idea of title - and the caching of Portlets does
// NOT include title -ggolden.
- if (md == null) {
+ if (md == null)
+ {
md = new MetaData();
pc.setMetainfo(md);
}
@@ -400,26 +461,79 @@
}
}
+ // Only update the control if the name changed
+ if (newControlName != null)
+ {
+ boolean controlChanged = false;
+ String currentControlName = null;
+
+ if (entry.getControl() != null)
+ currentControlName = entry.getControl().getName();
+
+ if (currentControlName != null)
+ {
+ controlChanged = (newControlName.equals(currentControlName) == false);
+ }
+ else
+ {
+ controlChanged = (newControlName.trim().length() > 0);
+ }
+
+ if (controlChanged == true)
+ {
+ PortletControl control = null;
+ if ((newControlName.trim().length() > 0))
+ {
+ control = PortalToolkit.getControl(newControlName);
+ if (control != null)
+ {
+ Control psmlControl = new PsmlControl();
+ psmlControl.setName(newControlName);
+ entry.setControl(psmlControl);
+ }
+ else
+ {
+ logger.warn(
+ "Unable to update control for portlet entry "
+ + entry.getId()
+ + " because control "
+ + newControlName
+ + " does not exist.");
+ }
+ }
+ else
+ {
+ entry.setControl(null);
+ }
+ madePcChange = true;
+ }
+ }
+
// Update paramaters
try
{
- PortletInstance instance = PersistenceManager.getInstance(p, rundata);
- PortletEntry regEntry = (PortletEntry) Registry.getEntry(Registry.PORTLET, p.getName());
+ PortletInstance instance =
+ PersistenceManager.getInstance(p, rundata);
+ PortletEntry regEntry =
+ (PortletEntry) Registry.getEntry(Registry.PORTLET, p.getName());
Iterator i = params.iterator();
//System.out.println("==========================================");
- while(i.hasNext())
+ while (i.hasNext())
{
- Parameter param = (Parameter)i.next();
+ Parameter param = (Parameter) i.next();
String name = param.getName();
String newValue = null;
String[] testArray = rundata.getParameters().getStrings(name);
if (testArray != null && testArray.length > 1)
{
- newValue = org.apache.jetspeed.util.StringUtils.arrayToString(testArray, ",");
+ newValue =
+ org.apache.jetspeed.util.StringUtils.arrayToString(
+ testArray,
+ ",");
}
- else
+ else
{
newValue = rundata.getParameters().getString(name);
if (newValue == null)
@@ -427,7 +541,8 @@
newValue = "";
}
}
- String regValue = regEntry.getParameter(name).getValue(); //param.getValue();
+ String regValue = regEntry.getParameter(name).getValue();
+ //param.getValue();
String psmlValue = instance.getAttribute(name);
//System.out.println(name + "= [" + psmlValue + "] in psml");
@@ -438,7 +553,8 @@
{
//System.out.println(name + "= [" + newValue + "] in request");
// New value differs from registry - record it in psml
- if (!regValue.equals(newValue) || !psmlValue.equals(newValue))
+ if (!regValue.equals(newValue)
+ || !psmlValue.equals(newValue))
{
instance.setAttribute(name, newValue);
psmlValue = newValue;
@@ -466,15 +582,25 @@
//FIXME: this hack is due to the corrupted lifecycle of the portlet in the
//current API when caching is activated
p.init();
- org.apache.jetspeed.util.PortletSessionState.setPortletConfigChanged(p, rundata);
+ org
+ .apache
+ .jetspeed
+ .util
+ .PortletSessionState
+ .setPortletConfigChanged(
+ p,
+ rundata);
}
catch (PortletException e)
{
- logger.error("Customizer failed to reinitialize the portlet "+p.getName(), e);
+ logger.error(
+ "Customizer failed to reinitialize the portlet "
+ + p.getName(),
+ e);
}
catch (Exception e)
{
- logger.error("Unable to save profile ",e);
+ logger.error("Unable to save profile ", e);
}
}
1.49 +10 -2 jakarta-jetspeed/webapp/WEB-INF/conf/admin.xreg
Index: admin.xreg
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/conf/admin.xreg,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- admin.xreg 4 May 2005 20:26:38 -0000 1.48
+++ admin.xreg 11 May 2005 01:33:13 -0000 1.49
@@ -42,6 +42,14 @@
<style-option name="registry" value="Skin"/>
</parameter-style>
</parameter>
+ <parameter name="_control" value="" type="style" hidden="false">
+ <security-ref parent="user-only"/>
+ <parameter-style name="RegistryEntryListBox">
+ <style-option name="registry" value="PortletControl"/>
+ <style-option name="select-hidden" value="true"/>
+ <style-option name="select-if-simple" value="true"/>
+ </parameter-style>
+ </parameter>
<category>admin</category>
<category>customize.portlet</category>
</portlet-entry>
@@ -72,7 +80,7 @@
<style-option name="javascript:onchange" value="this.form.submit()"/>
<style-option name="select-hidden" value="true"/>
<style-option name="select-if-simple" value="true"/>
- <style-option name="set-label" value="true"/>
+ <style-option name="set-label" value="true"/>
</parameter-style>
</parameter>
<parameter name="addRef" value="" type="style" hidden="false">
@@ -83,7 +91,7 @@
</parameter>
<parameter name="addRefDisabled" value="" type="style" hidden="false">
<parameter-style name="VelocityParameterPresentationStyle" template="Button.vm">
- <style-option name="disabled" value="true"/>
+ <style-option name="disabled" value="true"/>
<style-option name="no-access" value="addRefDisabled"/>
</parameter-style>
</parameter>
1.19 +14 -1 jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html/customizer-portlet.vm
Index: customizer-portlet.vm
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html/customizer-portlet.vm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- customizer-portlet.vm 29 Aug 2004 22:27:27 -0000 1.18
+++ customizer-portlet.vm 11 May 2005 01:33:13 -0000 1.19
@@ -60,7 +60,20 @@
</tr>
#end
-
+#if ($current_control)
+ #set ($controlListBox = $jetspeed.getPortletParameter($data, $customizer, "_control", $current_control))
+#else
+ #set ($controlListBox = $jetspeed.getPortletParameter($data, $customizer, "_control"))
+#end
+#if ($controlListBox)
+ <tr>
+ <td><b>$l10n.CUSTOMIZER_DECORATION</b></td>
+ <td>$controlListBox</td>
+ </tr>
+ <tr>
+ <td colspan="2"><hr/></td>
+ </tr>
+#end
#if ($security_ref && $securitySource == 0)
#set ($securityRefListBox = $jetspeed.getPortletParameter($data, $customizer, "_security_ref", $security_ref))
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org