[prev in list] [next in list] [prev in thread] [next in thread]
List: jetspeed-dev
Subject: cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets PsmlUpdateAction.
From: morciuch () apache ! org
Date: 2002-08-29 21:14:25
[Download RAW message or body]
morciuch 2002/08/29 14:14:25
Modified: src/java/org/apache/jetspeed/modules/actions/portlets
PsmlUpdateAction.java
Log:
Added on-line import all/export all features (see Bugzilla issue# 11599)
Revision Changes Path
1.9 +338 -1 \
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PsmlUpdateAction.java 23 Aug 2002 17:25:54 -0000 1.8
+++ PsmlUpdateAction.java 29 Aug 2002 21:14:25 -0000 1.9
@@ -72,6 +72,9 @@
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.StringTokenizer;
//Jetspeed
import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
@@ -79,6 +82,7 @@
import org.apache.jetspeed.om.profile.BaseProfileLocator;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.ProfileLocator;
+import org.apache.jetspeed.om.profile.QueryLocator;
import org.apache.jetspeed.om.profile.PSMLDocument;
import org.apache.jetspeed.om.profile.Portlets;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
@@ -280,6 +284,22 @@
}
}
+ if(mode != null && mode.equals("export_all"))
+ {
+ if (msgid == null)
+ {
+ // get the PSML Root Directory
+ ResourceService serviceConf = \
((TurbineServices)TurbineServices.getInstance()) + \
.getResources(PsmlManagerService.SERVICE_NAME); + String root = \
serviceConf.getString("root", "/WEB-INF/psml"); + \
context.put(COPY_TO, TurbineServlet.getRealPath(root)); + }
+ else
+ {
+ context.put(COPY_TO, rundata.getUser().getTemp(COPY_TO));
+ }
+ }
+
if(mode != null && mode.equals("import"))
{
org.apache.jetspeed.om.registry.Registry mediaTypes = \
Registry.get(Registry.MEDIA_TYPE); @@ -354,6 +374,22 @@
}
}
+ if(mode != null && mode.equals("import_all"))
+ {
+ if (msgid == null)
+ {
+ // get the PSML Root Directory
+ ResourceService serviceConf = \
((TurbineServices)TurbineServices.getInstance()) + \
.getResources(PsmlManagerService.SERVICE_NAME); + String root = \
serviceConf.getString("root", "/WEB-INF/psml"); + \
context.put(COPY_FROM, TurbineServlet.getRealPath(root)); + }
+ else
+ {
+ context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
+ }
+ }
+
}
catch (Exception e)
{
@@ -642,6 +678,110 @@
}
+ /**
+ * File Export All Action for Psml.
+ *
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ */
+ public void doExportall(RunData rundata, Context context)
+ throws Exception
+ {
+ String copyTo = null;
+
+ Log.info("PsmlUpdateAction: Starting export all operation");
+
+ try
+ {
+ copyTo = rundata.getParameters().getString("CopyTo");
+
+ //
+ // retrieve the profiles to export
+ //
+ Iterator i = Profiler.query(new QueryLocator(QueryLocator.QUERY_ALL));
+ while (i.hasNext())
+ {
+ Profile profile = (Profile) i.next();
+ PSMLDocument doc = profile.getDocument();
+ if(doc != null)
+ {
+ // Build the fully qualified file name
+ StringBuffer copyToFile = new StringBuffer(copyTo);
+ copyToFile.append(File.separator);
+ if (profile.getGroupName() != null)
+ {
+ copyToFile.append("group");
+ copyToFile.append(File.separator);
+ copyToFile.append(profile.getGroupName());
+ copyToFile.append(File.separator);
+ }
+ else if (profile.getRoleName() != null)
+ {
+ copyToFile.append("role");
+ copyToFile.append(File.separator);
+ copyToFile.append(profile.getRoleName());
+ copyToFile.append(File.separator);
+ }
+ else if (profile.getUserName() != null)
+ {
+ copyToFile.append("user");
+ copyToFile.append(File.separator);
+ copyToFile.append(profile.getUserName());
+ copyToFile.append(File.separator);
+ }
+ if (profile.getMediaType() != null)
+ {
+ copyToFile.append(profile.getMediaType());
+ copyToFile.append(File.separator);
+ }
+ if (profile.getLanguage() != null)
+ {
+ copyToFile.append(profile.getLanguage());
+ copyToFile.append(File.separator);
+ }
+ if (profile.getCountry() != null)
+ {
+ copyToFile.append(profile.getCountry());
+ copyToFile.append(File.separator);
+ }
+ copyToFile.append(profile.getName());
+
+ if (!this.saveDocument(copyToFile.toString(), doc)) {
+ Log.error("Failed to save PSML document for [" + \
profile.getPath()); + } else {
+ String msg = "Profile [" + profile.getPath() + "] has been \
saved to disk in [" + copyToFile.toString() + "]"; + \
Log.info(msg); + rundata.setMessage(msg);
+ }
+ }
+ }
+
+ }
+ 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(PSML_UPDATE_PANE)
+ .addPathInfo(SecurityConstants.PARAM_MODE,
+ "export_all")
+ .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 (copyTo != null) {
+ rundata.getUser().setTemp(COPY_TO, copyTo);
+ }
+
+ Log.info("PsmlUpdateAction: Ending export all operation");
+ }
+
/** Save the PSML document on disk to the specififed fileOrUrl
*
* @param fileOrUrl a String representing either an absolute URL
@@ -654,6 +794,8 @@
if (doc == null) return false;
File f = new File(fileOrUrl);
+ File d = new File(f.getParent());
+ d.mkdirs();
FileWriter writer = null;
@@ -911,6 +1053,201 @@
rundata.getUser().setTemp(COPY_FROM, copyFrom);
}
+ }
+
+ /**
+ * File Import All Action for Psml.
+ *
+ *
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ */
+ public void doImportall(RunData rundata, Context context)
+ throws Exception
+ {
+ String copyFrom = null;
+
+ try
+ {
+ copyFrom = rundata.getParameters().getString("CopyFrom");
+
+ //
+ // Collect all .psml files from the root specified
+ //
+ Vector files = new Vector();
+ this.collectPsml(files, copyFrom);
+
+ //
+ // Process each file
+ //
+ for (Iterator it = files.iterator(); it.hasNext(); )
+ {
+ // If error occurs processing one entry, continue on with the \
others + try
+ {
+ String psml = ((File) it.next()).getPath();
+ String path = psml.substring(copyFrom.length() + 1);
+ ProfileLocator locator = this.createFromPath(path);
+
+ PSMLDocument doc = this.loadDocument(psml);
+
+ //
+ // create a new profile
+ //
+ if(doc != null)
+ {
+ Portlets portlets = doc.getPortlets();
+ //
+ // Profiler does not provide update capability - must \
remove before replacing + //
+ if (PsmlManager.getDocument(locator) != null)
+ {
+ Profiler.removeProfile(locator);
+ }
+ Profiler.createProfile(locator, portlets);
+ }
+ else
+ {
+ throw new Exception("Failed to load PSML document [" + \
psml + "] from disk"); + }
+ rundata.setMessage("Profile for [" + locator.getPath() + "] \
has been imported from file [" + psml + "]"); + \
setRefreshPsmlFlag(rundata, TRUE); + }
+ catch (Exception ouch)
+ {
+ Log.error(ouch);
+ }
+ }
+
+ }
+ 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(PSML_UPDATE_PANE)
+ .addPathInfo(SecurityConstants.PARAM_MODE,
+ "import_all")
+ .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 (copyFrom != null)
+ {
+ rundata.getUser().setTemp(COPY_FROM, copyFrom);
+ }
+
+ }
+
+ /**
+ * This method recursively collect all .psml documents starting at the given \
root + *
+ * @param v Vector to put the file into
+ * @param root Root directory for import
+ */
+ private void collectPsml(Vector v, String root)
+ {
+
+ File dir = new File(root);
+ File[] files = dir.listFiles();
+ for (int i = 0; i < files.length; i++)
+ {
+ if (files[i].isDirectory())
+ {
+ collectPsml(v, files[i].getPath());
+ }
+ else if (files[i].isFile() && files[i].getPath().endsWith(".psml"))
+ {
+ v.add(files[i]);
+ }
+ }
+
+ }
+
+ /**
+ * Creates profile locator from a given path in the format:
+ *
+ * user/<name>/<mediaType>/<language>/<country>/<page>/
+ *
+ * group/ ""
+ * role/ ""
+ *
+ * @param path The formatted profiler path string.
+ * @param path fully qualified .psml file name
+ * @return profile locator
+ */
+ private ProfileLocator createFromPath(String path)
+ throws Exception
+ {
+ if (Log.getLogger().isDebugEnabled())
+ {
+ Log.debug("PsmlUpdateAction.createFromPath: processing path = " + \
path); + }
+ ProfileLocator result = new BaseProfileLocator();
+
+ // Tokenize the file path into elements
+ StringTokenizer tok = new StringTokenizer(path, File.separator);
+
+ // Load path elements into a vector for random access
+ Vector tokens = new Vector();
+ while (tok.hasMoreTokens())
+ {
+ tokens.add(tok.nextToken());
+ }
+
+ // Assume that 1st element is the profile type (user|role|group) and 2nd \
is the name + if (tokens.size() > 1)
+ {
+ String type = (String) tokens.elementAt(0);
+ String name = (String) tokens.elementAt(1);
+ if (type.equals(Profiler.PARAM_USER))
+ {
+ result.setUser(JetspeedSecurity.getUser(name));
+ }
+ else if (type.equals(Profiler.PARAM_GROUP))
+ {
+ result.setGroup(JetspeedSecurity.getGroup(name));
+ }
+ else if (type.equals(Profiler.PARAM_ROLE))
+ {
+ result.setRole(JetspeedSecurity.getRole(name));
+ }
+ }
+
+ // Assume that the last element is the page name
+ if (tokens.size() > 0)
+ {
+ result.setName((String) tokens.lastElement());
+ }
+
+ // Based on the number of path elements set the other profile attributes
+ switch (tokens.size())
+ {
+ case 3: // user|role|group/name/page.psml
+ break;
+ case 4: // user|role|group/name/media-type/page.psml
+ result.setMediaType((String) tokens.elementAt(2));
+ break;
+ case 5: // user|role|group/name/media-type/language/page.psml
+ result.setMediaType((String) tokens.elementAt(2));
+ result.setLanguage((String) tokens.elementAt(3));
+ break;
+ case 6: // user|role|group/name/media-type/language/country/page.psml
+ result.setMediaType((String) tokens.elementAt(2));
+ result.setLanguage((String) tokens.elementAt(3));
+ result.setCountry((String) tokens.elementAt(4));
+ break;
+ default:
+ throw new Exception("Path must contain 3 to 6 elements: [" + path + \
"], and the size was: " + tokens.size()); + }
+
+ return result;
}
/**
--
To unsubscribe, e-mail: <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic