morciuch 2002/09/04 09:06:37
Modified: src/java/org/apache/jetspeed/modules/actions/portlets
PsmlUpdateAction.java
Log:
General clean-up + constant usage where appropriate
Revision Changes Path
1.10 +129 -28
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PsmlUpdateAction.java 29 Aug 2002 21:14:25 -0000 1.9
+++ PsmlUpdateAction.java 4 Sep 2002 16:06:37 -0000 1.10
@@ -95,6 +95,9 @@
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.jetspeed.services.psmlmanager.PsmlManagerService;
import org.apache.jetspeed.om.profile.BasePSMLDocument;
+import org.apache.jetspeed.om.security.JetspeedUser;
+import org.apache.jetspeed.om.security.Role;
+import org.apache.jetspeed.om.security.Group;
//castor support
import org.exolab.castor.xml.MarshalException;
@@ -236,12 +239,24 @@
{
if (msgid == null)
{
- String exportPath =
JetspeedResources.getString("psml.export.default.path", "/tmp");
+ String tmpPath =
JetspeedResources.getString(JetspeedResources.TEMP_DIRECTORY_KEY, "/tmp");
+ String exportPath =
JetspeedResources.getString("psml.export.default.path",
+
TurbineServlet.getRealPath(tmpPath));
if(path == null)
{
-
context.put(COPY_TO, exportPath);
- context.put(COPY_FROM,
"user/anon/media-type/html/page/default.psml");
+ context.put(COPY_FROM,
+ Profiler.PARAM_USER +
+ File.separator +
+ Profiler.PARAM_ANON +
+ File.separator +
+ Profiler.PARAM_MEDIA_TYPE +
+ File.separator +
+ "html" +
+ File.separator +
+ Profiler.PARAM_PAGE +
+ File.separator +
+ Profiler.FULL_DEFAULT_PROFILE);
}
else
{
@@ -254,26 +269,26 @@
context.put("profile", profile);
}
- String categoryName = "group";
+ String categoryName = Profiler.PARAM_GROUP;
String categoryValue = tmpLocator.getGroupName();
if (categoryValue == null)
{
- categoryName = "role";
+ categoryName = Profiler.PARAM_ROLE;
categoryValue = tmpLocator.getRoleName();
if (categoryValue == null)
{
- categoryName = "user";
+ categoryName = Profiler.PARAM_USER;
categoryValue = tmpLocator.getUserName();
if (categoryValue == null)
{
- categoryName = "user";
- categoryValue = "anon";
+ categoryName = Profiler.PARAM_USER;
+ categoryValue = Profiler.PARAM_ANON;
}
}
}
- context.put(COPY_TO, exportPath+"/"+tmpLocator.getName());
+ context.put(COPY_TO, exportPath + File.separator +
tmpLocator.getName());
context.put(COPY_FROM, path);
}
}
@@ -314,22 +329,22 @@
if(path == null)
{
- context.put(CATEGORY_NAME, "user");
- context.put("categoryValue", "anon");
+ context.put(CATEGORY_NAME, Profiler.PARAM_USER);
+ context.put("categoryValue", Profiler.PARAM_ANON);
context.put("copyFrom",
root +
File.separator +
- "user" +
+ Profiler.PARAM_USER +
File.separator +
- "anon" +
+ Profiler.PARAM_ANON +
File.separator +
- "media-type" +
+ Profiler.PARAM_MEDIA_TYPE +
File.separator +
"html" +
File.separator +
- "page" +
+ Profiler.PARAM_PAGE +
File.separator +
- "default.psml");
+ Profiler.FULL_DEFAULT_PROFILE);
}
else
{
@@ -341,28 +356,27 @@
rundata.getUser().setTemp(TEMP_LOCATOR, tmpLocator);
context.put("profile", profile);
}
- String categoryName = "group";
+ String categoryName = Profiler.PARAM_GROUP;
String categoryValue = tmpLocator.getGroupName();
if (categoryValue == null)
{
- categoryName = "role";
+ categoryName = Profiler.PARAM_ROLE;
categoryValue = tmpLocator.getRoleName();
if (categoryValue == null)
{
- categoryName = "user";
+ categoryName = Profiler.PARAM_USER;
categoryValue = tmpLocator.getUserName();
if (categoryValue == null)
{
- categoryName = "user";
- categoryValue = "anon";
+ categoryName = Profiler.PARAM_USER;
+ categoryValue = Profiler.PARAM_ANON;
}
}
}
context.put(CATEGORY_NAME, categoryName);
context.put("categoryValue", categoryValue);
- StringBuffer filePath =
org.apache.jetspeed.util.StringUtils.replaceAll(new StringBuffer(path), "/",
File.separator);
- path.replace('/', File.separator.charAt(0));
+ String filePath = this.mapLocatorToFile(tmpLocator);
context.put("copyFrom", root + File.separator +
filePath.toString());
}
}
@@ -964,7 +978,7 @@
JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
.addPathInfo(SecurityConstants.PARAM_MODE,
-
SecurityConstants.PARAM_MODE_INSERT)
+ "import")
.addPathInfo(SecurityConstants.PARAM_MSGID,
SecurityConstants.MID_INVALID_ENTITY_NAME);
JetspeedLinkFactory.putInstance(link);
@@ -1029,7 +1043,7 @@
JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
.addPathInfo(SecurityConstants.PARAM_MODE,
- SecurityConstants.PARAM_MODE_INSERT)
+ "import")
.addPathInfo(SecurityConstants.PARAM_MSGID,
SecurityConstants.MID_UPDATE_FAILED);
JetspeedLinkFactory.putInstance(link);
@@ -1087,7 +1101,7 @@
{
String psml = ((File) it.next()).getPath();
String path = psml.substring(copyFrom.length() + 1);
- ProfileLocator locator = this.createFromPath(path);
+ ProfileLocator locator = this.mapFileToLocator(path);
PSMLDocument doc = this.loadDocument(psml);
@@ -1182,7 +1196,7 @@
* @param path fully qualified .psml file name
* @return profile locator
*/
- private ProfileLocator createFromPath(String path)
+ private ProfileLocator mapFileToLocator(String path)
throws Exception
{
if (Log.getLogger().isDebugEnabled())
@@ -1250,6 +1264,93 @@
return result;
}
+ /**
+ * Maps a ProfileLocator to a file.
+ *
+ * @param locator The profile locator describing the PSML resource to be found.
+ * @return the String path of the file.
+ */
+ private String mapLocatorToFile(ProfileLocator locator)
+ {
+ StringBuffer path = new StringBuffer();
+
+ // move the base dir is either user or role is specified
+ Role role = locator.getRole();
+ Group group = locator.getGroup();
+ JetspeedUser user = locator.getUser();
+
+ if (user != null)
+ {
+ path.append(Profiler.PARAM_USER);
+ String name = user.getUserName();
+ if (null != name && name.length() > 0)
+ {
+ path.append(File.separator)
+ .append(name);
+ }
+ }
+ else if (group != null)
+ {
+ path.append(Profiler.PARAM_GROUP);
+ String name = group.getName();
+ if (null != name && name.length() > 0)
+ {
+ path.append(File.separator)
+ .append(name);
+ }
+ }
+ else if (null != role)
+ {
+ path.append(Profiler.PARAM_ROLE);
+ String name = role.getName();
+ if (null != name && name.length() > 0)
+ {
+ path.append(File.separator)
+ .append(name);
+ }
+ }
+
+ // Media
+ if (null != locator.getMediaType())
+ {
+ path.append(File.separator)
+ .append(locator.getMediaType());
+ }
+ // Language
+ if (null != locator.getLanguage())
+ {
+ path.append(File.separator)
+ .append(locator.getLanguage());
+ }
+ // Country
+ if (null != locator.getCountry())
+ {
+ path.append(File.separator)
+ .append(locator.getCountry());
+ }
+ // Resource Name
+ if (null != locator.getName())
+ {
+ if (!(locator.getName().endsWith(Profiler.DEFAULT_EXTENSION)))
+ {
+ path.append(File.separator)
+ .append(locator.getName()).append(Profiler.DEFAULT_EXTENSION);
+ }
+ else
+ {
+ path.append(File.separator)
+ .append(locator.getName());
+ }
+ }
+ else
+ {
+ path.append(File.separator)
+ .append(Profiler.FULL_DEFAULT_PROFILE);
+ }
+
+ return path.toString();
+ }
+
/**
* Load a PSMLDOcument from disk
*
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>