Update of 
/var/cvs/contributions/CMSContainer/cmsc/utilities/src/java/com/finalist/cmsc/struts
In directory 
james.mmbase.org:/tmp/cvs-serv13738/cmsc/utilities/src/java/com/finalist/cmsc/struts

Modified Files:
        WizardInitAction.java 
Log Message:
CMSC-992 Add logic to automatically resolve an editwizard when it's entry is 
missing in the database


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/utilities/src/java/com/finalist/cmsc/struts
See also: http://www.mmbase.org/jira/browse/CMSC-992


Index: WizardInitAction.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/utilities/src/java/com/finalist/cmsc/struts/WizardInitAction.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- WizardInitAction.java       16 May 2008 11:46:35 -0000      1.7
+++ WizardInitAction.java       1 Aug 2008 13:15:37 -0000       1.8
@@ -1,7 +1,6 @@
 package com.finalist.cmsc.struts;
 
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
@@ -79,21 +78,29 @@
             return ret;
          }
       }
-      session.setAttribute("contenttype", contenttype);
 
       String wizardConfigName = request.getParameter("wizardConfigName");
       if (StringUtils.isEmpty(wizardConfigName)) {
          NodeList list = null;
          NodeManager manager = cloud.getNodeManager("editwizards");
          list = manager.getList("nodepath = '" + contenttype + "'", null, 
null);
-         if (list.isEmpty()) {
+         if (!list.isEmpty()) {
+            Node wizard = list.getNode(0);
+            wizardConfigName = wizard.getStringValue("wizard");
+         }
+         else {
+            String typeWizard = "config/" + contenttype + "/" + contenttype;
+            if (editwizardExists(typeWizard)) {
+               wizardConfigName = typeWizard;
+            }
+            else {
             throw new IllegalStateException("Unable to find a wizard for 
contenttype " + contenttype + " or objectnumber "
                   + objectNumber);
          }
-
-         Node wizard = list.getNode(0);
-         wizardConfigName = wizard.getStringValue("wizard");
       }
+      }
+
+      session.setAttribute("contenttype", contenttype);
 
       String sessionkey = request.getParameter("sessionkey");
       if (sessionkey == null || sessionkey.length() == 0) {
@@ -120,4 +127,17 @@
       ret.setRedirect(true);
       return ret;
    }
+
+
+   private boolean editwizardExists(String wizard) {
+      String wizardSchema = "/editors/" + wizard + ".xml";
+      Set<String> webInfResources = 
this.getServlet().getServletContext().getResourcePaths(wizardSchema);
+      /*
+       * @see javax.servlet.ServletContext#getResourcePaths(String) 
getResourcePaths returns a Set
+       *      containing the directory listing, or null if there are no 
resources in the web
+       *      application whose path begins with the supplied path. we are 
using a full path instead
+       *      of a partial path. webInfResources.isEmpty() is true when the 
resource exists
+       */
+      return webInfResources != null;
+   }
 }
\ No newline at end of file
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to