ggolden 2002/09/27 10:02:25
Modified: src/java/org/apache/jetspeed/portal
JetspeedPortletInstance.java
Log:
The customizers, including the Portlet customizer, now work on a clone of the
current Profile / PSMLDocument rather than on the current ones. This is to
assure that if, due to new account creation and caching, there are two different
Profiles that use the same PSMLDocument, only the one being edited will be
modified. Also, as someone is modifying a Profile, other users won't see the
results until the modification is saved. If the modification is cancled, nothing
changes.
Some support was added to the JetspeedRunData and the Customize.java for this.
The JetspeedPortletInstance was changed to be aware of the clone used in
customization, and to make a clone if needed before modifying the current psml.
Revision Changes Path
1.5 +92 -38
jakarta-jetspeed/src/java/org/apache/jetspeed/portal/JetspeedPortletInstance.java
Index: JetspeedPortletInstance.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/JetspeedPortletInstance.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JetspeedPortletInstance.java 29 Jul 2002 02:25:27 -0000 1.4
+++ JetspeedPortletInstance.java 27 Sep 2002 17:02:25 -0000 1.5
@@ -58,6 +58,8 @@
import java.util.Iterator;
import java.util.List;
+import org.apache.turbine.util.Log;
+
// ECS imports
import org.apache.ecs.ClearElement;
import org.apache.ecs.ConcreteElement;
@@ -85,22 +87,30 @@
* <entry>
* <parameter name="someName" value="someValue"/>
*
+ * Since this modifies PSMLDocuments, it will make a clone once modification starts.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Weaver</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Glenn R. Golden</a>
* @version $Id$
*/
public class JetspeedPortletInstance implements PortletInstance
{
-
- private Profile profile;
- private PSMLDocument doc;
- private Entry entry;
- private JetspeedRunData rundata;
+ /** The Profile (and PSMLDocument) that we started with, considered RO */
+ private Profile m_profile = null;
+
+ /** The Profile (and PSMLDocument) that we cloned to edit. */
+ private Profile m_clonedProfile = null;
+
+ /** The rundata - WARNING: it is VERY DANGEROUS to store rundata like this.
+ Rundata objects are re-used, and are only good within one request.
+ This means that a PortletInstance CANNOTA BE STORED BEYOND A SINGLE
REQUEST! */
+ private JetspeedRunData m_rundata = null;
/**
* keeping an instance of the actual Portlet around helps us with
* getting information that is not directly available from the PSML profile
*/
- private Portlet portlet;
+ private Portlet m_portlet = null;
/**
* Constructs a PortletInstance from a Portlet and a RunData.
@@ -111,9 +121,12 @@
public JetspeedPortletInstance(Portlet portlet, RunData data)
{
this(portlet, ((JetspeedRunData) data).getProfile());
- this.rundata = (JetspeedRunData)data;
+ m_rundata = (JetspeedRunData)data;
+
+ // if we are in an edit already, use that as the clone
+ m_clonedProfile = ((JetspeedRunData)data).getCustomizedProfile();
}
-
+
/**
* Constructs a PortletInstance from a Portlet and a Profile
*
@@ -122,18 +135,10 @@
*/
public JetspeedPortletInstance(Portlet portlet, Profile profile)
{
- this.portlet = portlet;
-
- this.profile = profile;
-
- if (profile != null)
- {
- doc = profile.getDocument();
- entry = doc.getEntryById(portlet.getID());
- }
- }
-
-
+ m_portlet = portlet;
+ m_profile = profile;
+ }
+
/**
* Protect the constructor so it can only be instantitated by
* by the PortalPersistenceService
@@ -148,6 +153,8 @@
*/
public String getAttribute(String name, String dftValue)
{
+ Entry entry = getEntry();
+
if (entry == null)
{
return dftValue;
@@ -168,6 +175,8 @@
*/
public String getAttribute(String name)
{
+ Entry entry = getEntry();
+
if (entry == null)
{
return "";
@@ -188,7 +197,12 @@
*/
public void setAttribute(String name, String value)
{
- Parameter attr = entry.getParameter(name);
+ // make sure we are updating and using the clone now
+ setupForUpdate();
+
+ Entry entry = getEntry();
+
+ Parameter attr = entry.getParameter(name);
// Setting a attribute to null should just remove it.
if(value == null)
@@ -214,6 +228,11 @@
*/
public void removeAttribute(String name)
{
+ // make sure we are updating and using the clone now
+ setupForUpdate();
+
+ Entry entry = getEntry();
+
// I am assuming that we only allow one parameter per name
Iterator params = entry.getParameterIterator();
int index = -1;
@@ -242,6 +261,11 @@
*/
public void removeAllAttributes()
{
+ // make sure we are updating and using the clone now
+ setupForUpdate();
+
+ Entry entry = getEntry();
+
entry.removeAllParameter();
}
@@ -250,6 +274,8 @@
*/
public Iterator getAttributes()
{
+ Entry entry = getEntry();
+
return entry.getParameterIterator();
}
@@ -258,7 +284,7 @@
*/
public Iterator getAttributeNames()
{
- Iterator itr =getAttributes();
+ Iterator itr = getAttributes();
ArrayList list = new ArrayList();
while(itr.hasNext());
{
@@ -274,7 +300,7 @@
*/
public PSMLDocument getDocument()
{
- return doc;
+ return getProfile().getDocument();
}
/**
@@ -282,7 +308,10 @@
*/
public Profile getProfile()
{
- return profile;
+ // use the clone if we have made it
+ if (m_clonedProfile != null) return m_clonedProfile;
+
+ return m_profile;
}
/**
@@ -290,7 +319,7 @@
*/
public Entry getEntry()
{
- return entry;
+ return getDocument().getEntryById(m_portlet.getID());
}
/**
@@ -298,16 +327,18 @@
*/
public String getDescription()
{
+ Entry entry = getEntry();
+
String description = null;
- if (this.entry != null)
+ if (entry != null)
{
- MetaInfo metaInfo = this.entry.getMetaInfo();
+ MetaInfo metaInfo = entry.getMetaInfo();
if (metaInfo != null)
{
description = metaInfo.getDescription();
}
}
- return portlet.getDescription(description);
+ return m_portlet.getDescription(description);
}
/**
@@ -315,7 +346,7 @@
*/
public String getName()
{
- return entry.getParent();
+ return getEntry().getParent();
}
/**
@@ -323,16 +354,18 @@
*/
public String getTitle()
{
+ Entry entry = getEntry();
+
String title = null;
- if (this.entry != null)
+ if (entry != null)
{
- MetaInfo metaInfo = this.entry.getMetaInfo();
+ MetaInfo metaInfo = entry.getMetaInfo();
if (metaInfo != null)
{
title = metaInfo.getTitle();
}
}
- return portlet.getTitle(title);
+ return m_portlet.getTitle(title);
}
/**
@@ -340,16 +373,18 @@
*/
public String getImage()
{
+ Entry entry = getEntry();
+
String image = null;
if (entry != null)
{
- MetaInfo metaInfo = this.entry.getMetaInfo();
+ MetaInfo metaInfo = entry.getMetaInfo();
if (metaInfo != null)
{
return image = metaInfo.getImage();
}
}
- return portlet.getImage(image);
+ return m_portlet.getImage(image);
}
/**
@@ -357,7 +392,7 @@
*/
public Portlet getPortlet()
{
- return this.portlet;
+ return m_portlet;
}
/**
@@ -365,7 +400,7 @@
*/
public ConcreteElement getContent()
{
- return portlet.getContent(this.rundata);
+ return m_portlet.getContent(m_rundata);
}
/**
@@ -373,7 +408,26 @@
*/
public boolean isShowTitleBar()
{
- return portlet.isShowTitleBar(this.rundata);
+ return m_portlet.isShowTitleBar(m_rundata);
}
+ /**
+ * Setup for making a change to the Entry
+ * We must not change the PSMLDocument that we started with, instead we make a
clone
+ * and start using it.
+ */
+ private void setupForUpdate()
+ {
+ if (m_clonedProfile != null) return;
+
+ try
+ {
+ m_clonedProfile = (Profile) m_profile.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ Log.warn("JetspeedPortletInstance: cannot clone Profile!: " + e);
+ }
+ }
}
+
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>