Update of
/var/cvs/contributions/CMSContainer/cmsc/edit-webapp/src/java/com/finalist/cmsc/editwizard
In directory
james.mmbase.org:/tmp/cvs-serv23572/cmsc/edit-webapp/src/java/com/finalist/cmsc/editwizard
Modified Files:
WizardWorkflowController.java WizardController.java
Log Message:
INtroduced some constants
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/edit-webapp/src/java/com/finalist/cmsc/editwizard
Index: WizardWorkflowController.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer/cmsc/edit-webapp/src/java/com/finalist/cmsc/editwizard/WizardWorkflowController.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- WizardWorkflowController.java 16 May 2008 11:46:32 -0000 1.6
+++ WizardWorkflowController.java 21 Jun 2008 12:34:24 -0000 1.7
@@ -15,19 +15,32 @@
import javax.servlet.http.HttpServletRequest;
import org.mmbase.applications.editwizard.Config;
-import org.mmbase.bridge.*;
+import org.mmbase.bridge.Cloud;
+import org.mmbase.bridge.Node;
import org.mmbase.util.logging.Logger;
import org.mmbase.util.logging.Logging;
+import com.finalist.cmsc.navigation.PagesUtil;
+import com.finalist.cmsc.repository.RepositoryUtil;
import com.finalist.cmsc.security.UserRole;
+import com.finalist.cmsc.services.publish.Publish;
import com.finalist.cmsc.services.workflow.Workflow;
import com.finalist.cmsc.services.workflow.WorkflowException;
-import com.finalist.cmsc.services.publish.Publish;
-import com.finalist.cmsc.repository.RepositoryUtil;
-import com.finalist.cmsc.navigation.PagesUtil;
public class WizardWorkflowController extends WizardController {
+ private static final String OFF = "off";
+
+ private static final String WORKFLOWCOMMAND = "workflowcommand";
+ private static final String WORKFLOWCOMMENT = "workflowcomment";
+ private static final String ERRORS = "errors";
+
+ private static final String CANCEL = "cancel";
+ private static final String FINISH = "finish";
+ private static final String ACCEPT = "accept";
+ private static final String REJECT = "reject";
+ private static final String PUBLISH = "publish";
+
/**
* MMbase logging system
*/
@@ -55,12 +68,12 @@
if (isMainWizard(ewconfig, config) && contenttype != null &&
!"".equals(contenttype)
&& Workflow.isWorkflowType(contenttype)) {
- params.put("WORKFLOW", "true");
+ params.put("WORKFLOW", TRUE);
params.put("WORKFLOW-ACCEPTED-ENABLED",
Boolean.toString(Workflow.isAcceptedStepEnabled()));
String activity = "DRAFT";
- if (!"new".equals(objectnr)) {
+ if (!NEW_OBJECT.equals(objectnr)) {
Node node = cloud.getNode(objectnr);
// The closeWizard() will create one if it is not present
if (Workflow.hasWorkflow(node)) {
@@ -81,7 +94,7 @@
}
if (!Workflow.mayEdit(node, userrole)) {
- params.put("READONLY", "true");
+ params.put("READONLY", TRUE);
if (Workflow.STATUS_PUBLISHED.equals(Workflow.getStatus(node)))
{
params.put("READONLY-REASON", "PUBLISH");
}
@@ -93,7 +106,7 @@
else {
if (PagesUtil.isPageType(cloud.getNodeManager(contenttype))) {
// disable workflow for a new page
- params.put("WORKFLOW", "off");
+ params.put("WORKFLOW", OFF);
}
}
log.debug("activity " + activity);
@@ -101,10 +114,10 @@
}
else {
if (contenttype != null && !"".equals(contenttype) &&
Workflow.isWorkflowType(contenttype)) {
- params.put("WORKFLOW", "false");
+ params.put("WORKFLOW", FALSE);
}
else {
- params.put("WORKFLOW", "off");
+ params.put("WORKFLOW", OFF);
}
}
}
@@ -118,39 +131,39 @@
String objectnr = wizardConfig.objectNumber;
- String workflowCommand = request.getParameter("workflowcommand");
- String workflowcomment = request.getParameter("workflowcomment");
+ String workflowCommand = request.getParameter(WORKFLOWCOMMAND);
+ String workflowcomment = request.getParameter(WORKFLOWCOMMENT);
if (wizardConfig.wiz.committed()) {
- if ("new".equals(objectnr)) {
+ if (NEW_OBJECT.equals(objectnr)) {
if (wizardConfig.wiz.committed() &&
!Workflow.hasWorkflow(editNode)) {
Workflow.create(editNode, workflowcomment);
}
}
else {
- if (!Workflow.hasWorkflow(editNode) &&
!"cancel".equals(workflowCommand)) {
+ if (!Workflow.hasWorkflow(editNode) &&
!CANCEL.equals(workflowCommand)) {
log.debug("object " + objectnr + " missing workflow.
creating one. ");
Workflow.create(editNode, "");
}
}
// wizard command is commit
- if ("finish".equals(workflowCommand)) {
+ if (FINISH.equals(workflowCommand)) {
log.debug("finishing object " + objectnr);
Workflow.finish(editNode, workflowcomment);
}
- if ("accept".equals(workflowCommand)) {
+ if (ACCEPT.equals(workflowCommand)) {
log.debug("accepting object " + objectnr);
Workflow.accept(editNode, workflowcomment);
}
- if ("publish".equals(workflowCommand)) {
+ if (PUBLISH.equals(workflowCommand)) {
log.debug("publishing object " + objectnr);
try {
Workflow.publish(editNode);
}
catch (WorkflowException wfe) {
List<Node> errors = wfe.getErrors();
- request.setAttribute("errors", errors);
+ request.setAttribute(ERRORS, errors);
log.error("Could not publish object");
for (Node errorNode : errors) {
log.error(errorNode.getNodeManager().getName() + " " +
errorNode.getNumber() + " ");
@@ -170,7 +183,7 @@
// wizard command is cancel. This command cannot be called on a new
// node
// so there is always a workflow
- if ("reject".equals(workflowCommand)) {
+ if (REJECT.equals(workflowCommand)) {
log.debug("rejecting object " + objectnr);
Workflow.reject(editNode, workflowcomment);
}
@@ -179,13 +192,13 @@
else {
if (editNode != null && !Workflow.isWorkflowType(contenttype)) {
- String workflowCommand = request.getParameter("workflowcommand");
- if ("publish".equals(workflowCommand)) {
+ String workflowCommand = request.getParameter(WORKFLOWCOMMAND);
+ if (PUBLISH.equals(workflowCommand)) {
// update only nodes in live clouds.
// PublishUtil.PublishOrUpdateNode(editNode);
}
- if (!"cancel".equals(workflowCommand)) {
+ if (!CANCEL.equals(workflowCommand)) {
if (RepositoryUtil.isContentChannel(editNode) ||
RepositoryUtil.isCollectionChannel(editNode)) {
if (!Workflow.hasWorkflow(editNode)) {
Publish.publish(editNode);
Index: WizardController.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer/cmsc/edit-webapp/src/java/com/finalist/cmsc/editwizard/WizardController.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- WizardController.java 16 May 2008 11:46:32 -0000 1.9
+++ WizardController.java 21 Jun 2008 12:34:24 -0000 1.10
@@ -4,8 +4,12 @@
*/
package com.finalist.cmsc.editwizard;
-import org.apache.commons.lang.StringUtils;
+import java.util.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang.StringUtils;
import org.mmbase.applications.editwizard.Config;
import org.mmbase.applications.editwizard.Config.WizardConfig;
import org.mmbase.bridge.Cloud;
@@ -23,10 +27,6 @@
import com.finalist.cmsc.services.versioning.Versioning;
import com.finalist.cmsc.services.versioning.VersioningException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import java.util.*;
-
/**
* @author Nico Klasens This class contains code which extends wizard.jsp
*/
@@ -37,6 +37,18 @@
*/
private static final Logger log =
Logging.getLoggerInstance(WizardController.class.getName());
+ protected static final String TRUE = "true";
+ protected static final String FALSE = "false";
+
+ protected static final String NEW_OBJECT = "new";
+
+ protected static final String SESSION_CONTENTTYPE = "contenttype";
+ protected static final String SESSION_CREATION = "creation";
+ protected static final String SESSION_READONLY = "readonly";
+
+ protected static final String ACTION_SAVE = "save";
+ protected static final String ACTION_CANCEL = "cancel";
+
/**
* Additional actions to open the wizard
@@ -57,8 +69,8 @@
HttpSession session = request.getSession();
String objectnr = config.objectNumber;
String contenttype = null;
- if (objectnr != null && "new".equals(objectnr)) {
- contenttype = (String) session.getAttribute("contenttype");
+ if (objectnr != null && NEW_OBJECT.equals(objectnr)) {
+ contenttype = (String) session.getAttribute(SESSION_CONTENTTYPE);
}
else {
Node node = cloud.getNode(objectnr);
@@ -66,9 +78,9 @@
}
log.debug("contenttype " + contenttype);
- String readonly = (String) session.getAttribute("readonly");
+ String readonly = (String) session.getAttribute(SESSION_READONLY);
if (StringUtils.isBlank(readonly)) {
- readonly = "false";
+ readonly = FALSE;
}
Map<String, String> params = new HashMap<String, String>();
@@ -78,21 +90,21 @@
Node creationNode = null;
if (StringUtils.isNotEmpty(contenttype)) {
- String creation = (String) session.getAttribute("creation");
+ String creation = (String) session.getAttribute(SESSION_CREATION);
if (StringUtils.isNotEmpty(creation)) {
creationNode = cloud.getNode(creation);
}
- if (creationNode == null && objectnr != null &&
!"new".equals(objectnr)) {
+ if (creationNode == null && objectnr != null &&
!NEW_OBJECT.equals(objectnr)) {
Node node = cloud.getNode(objectnr);
if (PagesUtil.isPageType(node)) {
creationNode = node;
- session.setAttribute("creation", "" + creationNode.getNumber());
+ session.setAttribute(SESSION_CREATION, "" +
creationNode.getNumber());
}
if (ContentElementUtil.isContentType(contenttype)) {
if (RepositoryUtil.hasCreationChannel(node)) {
creationNode = RepositoryUtil.getCreationChannel(node);
- session.setAttribute("creation", "" +
creationNode.getNumber());
+ session.setAttribute(SESSION_CREATION, "" +
creationNode.getNumber());
}
}
}
@@ -112,25 +124,25 @@
log.debug("role = " + userrole.getRole());
int roleId = userrole.getRole().getId();
if (roleId >= Role.WEBMASTER.getId()) {
- params.put("WEBMASTER", "true");
+ params.put("WEBMASTER", TRUE);
}
if (roleId >= Role.CHIEFEDITOR.getId()) {
- params.put("CHIEFEDITOR", "true");
+ params.put("CHIEFEDITOR", TRUE);
}
if (roleId >= Role.EDITOR.getId()) {
- params.put("EDITOR", "true");
+ params.put("EDITOR", TRUE);
}
if (roleId >= Role.WRITER.getId()) {
- params.put("WRITER", "true");
+ params.put("WRITER", TRUE);
}
else {
- params.put("READONLY", "true");
+ params.put("READONLY", TRUE);
params.put("READONLY-REASON", "RIGHTS");
}
}
else {
if (Rank.ADMIN_INT <= cloud.getUser().getRank().getInt()) {
- params.put("WEBMASTER", "true");
+ params.put("WEBMASTER", TRUE);
}
}
@@ -167,10 +179,10 @@
if (isMainWizard(ewconfig, wizardConfig)) {
if (wizardConfig.wiz.committed()) {
- session.setAttribute("wizardaction", "save");
+ session.setAttribute("wizardaction", ACTION_SAVE);
}
else {
- session.setAttribute("wizardaction", "cancel");
+ session.setAttribute("wizardaction", ACTION_CANCEL);
}
}
@@ -180,8 +192,8 @@
String objectnr = wizardConfig.objectNumber;
log.debug("objectnr " + objectnr);
if (StringUtils.isNotEmpty(objectnr)) {
- if (!"new".equals(objectnr) || wizardConfig.wiz.committed()) {
- if ("new".equals(objectnr)) {
+ if (!NEW_OBJECT.equals(objectnr) || wizardConfig.wiz.committed()) {
+ if (NEW_OBJECT.equals(objectnr)) {
// We are closing a wizard which was called with
// objectnumber=new.
// let's find out the objectnumber in mmbase
@@ -198,8 +210,8 @@
if (editNode != null) {
if (ContentElementUtil.isContentElement(editNode)) {
- if ("new".equals(objectnr)) {
- String channelnr = (String) session.getAttribute("creation");
+ if (NEW_OBJECT.equals(objectnr)) {
+ String channelnr = (String)
session.getAttribute(SESSION_CREATION);
log.debug("Creation " + channelnr);
// this has creation channel check is needed, because with it
@@ -224,7 +236,7 @@
}
if (!RepositoryUtil.hasCreationChannel(editNode)) {
- String channelnr = (String)
session.getAttribute("creation");
+ String channelnr = (String)
session.getAttribute(SESSION_CREATION);
log.debug("Creation " + channelnr);
if (StringUtils.isNotEmpty(channelnr)) {
@@ -269,9 +281,7 @@
*/
public static boolean isMainWizard(Config ewconfig, Config.WizardConfig
wconfig) {
Stack configs = ewconfig.subObjects;
- Iterator iter = configs.iterator();
- while (iter.hasNext()) {
- Object element = iter.next();
+ for(Object element : configs) {
if (element instanceof Config.WizardConfig) {
return element == wconfig;
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs