taylor 2002/07/02 19:13:57
Modified: src/java/org/apache/jetspeed/modules/actions/portlets
PsmlBrowseAction.java PsmlUpdateAction.java
Log:
Added functionality to add, delete and clone psml files.
Revision Changes Path
1.2 +10 -7
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlBrowseAction.java
Index: PsmlBrowseAction.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlBrowseAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PsmlBrowseAction.java 2 Jul 2002 01:23:10 -0000 1.1
+++ PsmlBrowseAction.java 3 Jul 2002 02:13:57 -0000 1.2
@@ -54,26 +54,29 @@
package org.apache.jetspeed.modules.actions.portlets;
-import org.apache.jetspeed.portal.portlets.VelocityPortlet;
-import org.apache.jetspeed.services.Profiler;
-import org.apache.jetspeed.services.PsmlManager;
-
+//Jetspeed
+import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
import org.apache.jetspeed.om.profile.BaseProfile;
import org.apache.jetspeed.om.profile.BaseProfileLocator;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.ProfileException;
import org.apache.jetspeed.om.profile.ProfileLocator;
import org.apache.jetspeed.om.profile.QueryLocator;
-
import org.apache.jetspeed.om.profile.psml.PsmlEntry;
+import org.apache.jetspeed.portal.portlets.VelocityPortlet;
+import org.apache.jetspeed.services.Profiler;
+import org.apache.jetspeed.services.PsmlManager;
// Turbine stuff
import org.apache.turbine.util.Log;
+import org.apache.turbine.util.DynamicURI;
import org.apache.turbine.util.RunData;
+import org.apache.turbine.util.StringUtils;
// Velocity Stuff
import org.apache.velocity.context.Context;
+//Java
import java.util.Vector;
import java.util.Iterator;
@@ -117,7 +120,7 @@
while(i.hasNext())
{
Profile profile = (Profile)i.next();
- System.out.println("profile["+index+"]="+profile.getName()+"
count="+count);
+ //System.out.println("profile["+index+"]="+profile.getPath());
if (count < (next - 1) && index >= count)
{
entries.add(profile);
@@ -138,5 +141,5 @@
}
}
-}
+}
1.2 +188 -31
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlUpdateAction.java
Index: PsmlUpdateAction.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PsmlUpdateAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PsmlUpdateAction.java 2 Jul 2002 01:23:10 -0000 1.1
+++ PsmlUpdateAction.java 3 Jul 2002 02:13:57 -0000 1.2
@@ -75,9 +75,13 @@
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.ProfileException;
import org.apache.jetspeed.om.profile.ProfileLocator;
+import org.apache.jetspeed.om.profile.PSMLDocument;
+import org.apache.jetspeed.om.profile.Portlets;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
import org.apache.jetspeed.services.Profiler;
-import org.apache.jetspeed.services.PsmlManager;
+import org.apache.jetspeed.services.JetspeedSecurity;
+import org.apache.jetspeed.util.template.JetspeedLink;
+import org.apache.jetspeed.util.template.JetspeedLinkFactory;
import org.apache.jetspeed.services.resources.JetspeedResources;
/**
@@ -88,7 +92,10 @@
public class PsmlUpdateAction extends VelocityPortletAction
{
- protected static final String TEMP_PSML = "tempPsml";
+ protected static final String CATEGORY_NAME = "categoryName";
+ protected static final String CATEGORY_VALUE = "categoryValue";
+ protected static final String COPY_FROM = "copyFrom";
+ protected static final String TEMP_LOCATOR = "tempLocator";
/**
* Subclasses must override this method to provide default behavior
* for the portlet action
@@ -106,7 +113,6 @@
{
try
{
-
//
// if there was an error, display the message
//
@@ -118,12 +124,47 @@
context.put(SecurityConstants.PARAM_MSG,
SecurityConstants.MESSAGES[id]);
// get the bad entered data and put it back for convenient update
- Profile profile = (Profile)rundata.getUser().getTemp(TEMP_PSML);
- if (profile != null)
- context.put("psml", profile);
+ ProfileLocator locator =
(ProfileLocator)rundata.getUser().getTemp(TEMP_LOCATOR);
+ if (locator != null)
+ context.put("profile", new BaseProfile(locator));
+ }
+ String mode =
rundata.getParameters().getString(SecurityConstants.PARAM_MODE);
+ context.put(SecurityConstants.PARAM_MODE, mode);
+ String path =
rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID);
+
+ if(mode != null && mode.equals(SecurityConstants.PARAM_MODE_DELETE))
+ {
+ ProfileLocator locator = new BaseProfileLocator();
+ locator.createFromPath(path);
+ Profile profile = Profiler.getProfile(locator);
+ if (profile != null)
+ {
+ rundata.getUser().setTemp(TEMP_LOCATOR, locator);
+ context.put("profile", profile);
+ }
+ else
+ Log.error("Profile for Path:"+path+" Not Found!");
}
+ if(mode != null && mode.equals(SecurityConstants.PARAM_MODE_INSERT))
+ {
+ if (msgid == null)
+ {
+ context.put("categoryName", "user");
+ context.put("categoryValue", "anon");
+ if(path == null)
+ context.put("copyFrom",
"user/anon/media-type/html/page/default.psml");
+ else
+ context.put("copyFrom", path);
+ }
+ else
+ {
+ context.put("categoryName",
rundata.getUser().getTemp(CATEGORY_NAME));
+ context.put("categoryValue",
rundata.getUser().getTemp(CATEGORY_VALUE));
+ context.put("copyFrom", rundata.getUser().getTemp(COPY_FROM));
+ }
+ }
}
catch (Exception e)
{
@@ -143,34 +184,113 @@
public void doInsert(RunData rundata, Context context)
throws Exception
{
- Profile profile = null;
- ProfileLocator locator = null;
+ Profile profile = null;
+ ProfileLocator locator = null;
+ String categoryName = null;
+ String categoryValue = null;
+ String copyFrom = null;
+ String name = null;
+
try
{
+ categoryName = rundata.getParameters().getString("CategoryName");
+ categoryValue = rundata.getParameters().getString("CategoryValue");
+ copyFrom = rundata.getParameters().getString("CopyFrom");
+ name = rundata.getParameters().getString("name");
+ //
+ //create a new locator and set its values according to users input
+ //
+ locator = new BaseProfileLocator();
+ if (categoryName.equalsIgnoreCase(Profiler.PARAM_GROUP))
+ {
+ locator.setGroupByName(categoryValue);
+ }
+ else if (categoryName.equalsIgnoreCase(Profiler.PARAM_ROLE))
+ {
+ locator.setRoleByName(categoryValue);
+ }
+ else if (categoryName.equalsIgnoreCase(Profiler.PARAM_USER))
+ {
+ locator.setUser(JetspeedSecurity.getUser(categoryValue));
+ }
+ else
+ {
+ locator.setAnonymous(true);
+ }
+
+ String tempVar = rundata.getParameters().getString("MediaType");
+ if (tempVar != null && tempVar.trim().length() > 0)
+ {
+ locator.setMediaType(tempVar);
+ }
+
+ tempVar = rundata.getParameters().getString("Language");
+ if (tempVar != null && tempVar.trim().length() > 0)
+ {
+ locator.setLanguage(tempVar);
+ }
+
+ tempVar = rundata.getParameters().getString("Country");
+ if (tempVar != null && tempVar.trim().length() > 0)
+ {
+ locator.setCountry(tempVar);
+ }
+
+ locator.setName(name);
//
// validate that its not an 'blank' profile -- not allowed
//
- String name = rundata.getParameters().getString("name");
if (name == null || name.trim().length() == 0)
{
- DynamicURI duri = new DynamicURI (rundata);
- duri.addPathInfo(SecurityConstants.PANE_NAME, "PsmlForm");
- duri.addPathInfo(SecurityConstants.PARAM_MSGID,
SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri = link.getPaneByName("PsmlForm")
+ .addPathInfo(SecurityConstants.PARAM_MODE,
+
SecurityConstants.PARAM_MODE_INSERT)
+ .addPathInfo(SecurityConstants.PARAM_MSGID,
+
SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLinkFactory.putInstance(link);
rundata.setRedirectURI(duri.toString());
- // save values that user just entered so they don't have to re-enter
- if (profile != null)
- rundata.getUser().setTemp(TEMP_PSML, profile);
+
+ //save user entered values
+ if (locator != null)
+ rundata.getUser().setTemp(TEMP_LOCATOR, locator);
+ if (categoryName != null)
+ rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
+ if (categoryValue != null)
+ rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
+ if (copyFrom != null)
+ rundata.getUser().setTemp(COPY_FROM, copyFrom);
return;
}
+ //
+ // retrieve the profile to clone
+ //
+ ProfileLocator baseLocator = new BaseProfileLocator();
+ baseLocator.createFromPath(copyFrom);
+ Profile baseProfile = new BaseProfile(baseLocator);
+
//
// create a new profile
//
- locator = new BaseProfileLocator();
- rundata.getParameters().setProperties(locator);
- profile = new BaseProfile(locator);
- profile = Profiler.createProfile(rundata, profile);
+ if(baseProfile != null)
+ {
+ PSMLDocument doc = baseProfile.getDocument();
+ if(doc != null)
+ {
+ Portlets portlets = doc.getPortlets();
+ profile = Profiler.createProfile(locator, portlets);
+ }
+ else
+ {
+ profile = Profiler.createProfile(locator, null);
+ }
+ }
+ else
+ {
+ Log.error("Profile listed in Copy From Not Found!");
+ }
}
catch (EntityExistsException e)
{
@@ -180,14 +300,41 @@
//
// dup key found - display error message - bring back to same screen
//
- DynamicURI duri = new DynamicURI (rundata);
- duri.addPathInfo(SecurityConstants.PANE_NAME, "PsmlForm");
- duri.addPathInfo(SecurityConstants.PARAM_MSGID,
SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri = link.getPaneByName("PsmlForm")
+ .addPathInfo(SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_INSERT)
+ .addPathInfo(SecurityConstants.PARAM_MSGID,
+
SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ }
+ catch (Exception e)
+ {
+ // log the error msg
+ Log.error(e);
+
+ //
+ // dup key found - display error message - bring back to same screen
+ //
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri = link.getPaneByName("PsmlForm")
+ .addPathInfo(SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_INSERT)
+ .addPathInfo(SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_UPDATE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
rundata.setRedirectURI(duri.toString());
- // save values that user just entered so they don't have to re-enter
- if (profile != null)
- rundata.getUser().setTemp(TEMP_PSML, profile);
}
+ // save values that user just entered so they don't have to re-enter
+ if (locator != null)
+ rundata.getUser().setTemp(TEMP_LOCATOR, locator);
+ if (categoryName != null)
+ rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
+ if (categoryValue != null)
+ rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
+ if (copyFrom != null)
+ rundata.getUser().setTemp(COPY_FROM, copyFrom);
}
@@ -198,9 +345,15 @@
{
try
{
- ProfileLocator locator = new BaseProfileLocator();
- locator.createFromPath(rundata.getParameters().getString("link"));
- Profiler.removeProfile(locator);
+ ProfileLocator locator =
(ProfileLocator)rundata.getUser().getTemp(TEMP_LOCATOR);
+ if (locator != null)
+ {
+ Profiler.removeProfile(locator);
+ }
+ else
+ {
+ Log.error("ProfileLocator not found!");
+ }
}
catch(Exception e)
{
@@ -210,13 +363,17 @@
//
// dup key found - display error message - bring back to same screen
//
- DynamicURI duri = new DynamicURI (rundata);
- duri.addPathInfo(SecurityConstants.PANE_NAME, "PsmlForm");
- duri.addPathInfo(SecurityConstants.PARAM_MSGID,
SecurityConstants.MID_DELETE_FAILED);
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri = link.getPaneByName("PsmlForm")
+ .addPathInfo(SecurityConstants.PARAM_MODE,
SecurityConstants.PARAM_MODE_DELETE)
+ .addPathInfo(SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_DELETE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
rundata.setRedirectURI(duri.toString());
}
}
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>