Update of 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring
In directory 
james.mmbase.org:/tmp/cvs-serv9403/applications/vpro-wizards/src/org/mmbase/applications/vprowizards/spring

Modified Files:
        GlobalError.java ResultContainer.java WizardController.java 
        ReferrerResolver.java 
Log Message:
work in progress


See also: 
http://cvs.mmbase.org/viewcvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring


Index: GlobalError.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/GlobalError.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- GlobalError.java    8 Sep 2008 16:52:10 -0000       1.3
+++ GlobalError.java    8 Oct 2008 08:28:57 -0000       1.4
@@ -7,14 +7,13 @@
 
 public class GlobalError {
        
-
        /**
-        * This is the type of error that is created when something went wrong, 
and the transaction can not be committed in the end.
-        * A global error is a kind of error that will return an error page, in 
stead of the referrer page.
+     * This is the type of error that is created when something went wrong, 
and the transaction can not be committed in
+     * the end. A global error is a kind of error that will return an error 
page, in stead of the referrer page.
         * 
         * @author Ernst Bunders
         */
-       private ResourceBundle bundle;
+    private static ResourceBundle bundle = null;
        private String messageKey = "";
        private String[] properties = null;
 
@@ -22,18 +21,18 @@
         * @param messageKey
         *            the key of the error message in the resourceBundle with 
messages
         */
-       public GlobalError( String messageKey, Locale locale) {
+    public GlobalError(String messageKey, Locale locale) {
                this.messageKey = messageKey;
                initBundle(locale);
        }
 
        /**
-        * Use this constructor if the message is a template that contains 
certain
-        * placeholders to be replaced.
+     * Use this constructor if the message is a template that contains certain 
placeholders to be replaced.
+     * 
         * @param messageKey
         * @param properties
         */
-       public GlobalError( String messageKey, String[] properties, Locale 
locale) {
+    public GlobalError(String messageKey, String[] properties, Locale locale) {
                this.messageKey = messageKey;
                this.properties = properties;
                initBundle(locale);
@@ -43,29 +42,29 @@
                return messageKey;
        }
        
-       public String[] getProperties(){
+    public String[] getProperties() {
                return properties;
        }
 
        /**
-        * @return the message as defined in the mesasges resource bundle.
-        * @throws RuntimeException when the key was not found in the bundle
+     * @return the message as defined in the messages resource bundle.
+     * @throws RuntimeException
+     *             when the key was not found in the bundle
         */
        public String getMessage() {
                String message = bundle.getString(messageKey);
+        if (message == null || "".equals(message)) {
+            throw new RuntimeException("no message declared in bundle for key 
'" + messageKey + "'");
+        }
                int count = 0;
-               if(properties != null){
-                       while(message.contains("${"+count+"}") && 
properties.length > count){
-                               message.replace("${"+count+"}", 
properties[count]);
+        if (properties != null) {
+            while (message.contains("${" + count + "}") && properties.length > 
count) {
+                message = message.replace("${" + count + "}", 
properties[count]);
                                count++;
                        }
                }
-               if(message == null || "".equals(message)){
-                       throw new RuntimeException("no message declared in 
bundle for key '"+messageKey+"'");
-               }
                return message;
                
-               
        }
 
        @Override
@@ -74,9 +73,11 @@
        }
 
        private void initBundle(Locale locale) {
-               if(locale == null){
+        if (locale == null) {
                        throw new IllegalStateException("Locale should not be 
null");
                }
+        if (bundle == null) {
                bundle = 
ResourceBundle.getBundle("org.mmbase.applications.vprowizards.resources.messages",
 locale);
        }
+    }
 }


Index: ResultContainer.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/ResultContainer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ResultContainer.java        22 Sep 2008 14:33:46 -0000      1.3
+++ ResultContainer.java        8 Oct 2008 08:28:57 -0000       1.4
@@ -1,10 +1,6 @@
 package org.mmbase.applications.vprowizards.spring;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -29,8 +25,8 @@
 public class ResultContainer {
        private List<FieldError> fieldErrors = new ArrayList<FieldError>();
        private List<GlobalError> globalErrors = new ArrayList<GlobalError>();
-       private List<String> newObjects = new ArrayList<String>(5);
     private List<CacheFlushHint> cacheFlushHints = new 
ArrayList<CacheFlushHint>();
+    private Map<String,String> extraParams = new LinkedHashMap<String, 
String>();  
     private Transaction transaction = null;
     private Locale locale;
     private static final Logger log = 
Logging.getLoggerInstance(ResultContainer.class);
@@ -55,13 +51,12 @@
                return globalErrors;
        }
 
-       public List<String> getNewObject() {
-               return newObjects;
+       public void addParamToReturnURL(String name, String value){
+           extraParams.put(name, value);
        }
 
-       public void addNewObject(String newObject) {
-               this.newObjects.add(newObject);
-
+       public Map<String,String>getExtraParams(){
+           return extraParams;
        }
        
        public void addGlobalError(GlobalError e){


Index: WizardController.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/WizardController.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- WizardController.java       22 Sep 2008 14:33:46 -0000      1.3
+++ WizardController.java       8 Oct 2008 08:28:57 -0000       1.4
@@ -37,7 +37,7 @@
        private Locale locale;
        
        public WizardController(){
-               setLocale(new Locale("nl-NL"));/*default*/
+               setLocale(new Locale("nl", "NL"));/*default*/
        }
        
        
@@ -55,7 +55,6 @@
 
                Command command = commandFactory.getNewInstance();
                Transaction transaction = 
cloudFactory.createTransaction(request);
-               Map<String, Node> nodeMap = new HashMap<String, Node>();
                
                if(log.isDebugEnabled()){
                        log.debug("*********************************");
@@ -88,12 +87,6 @@
                        // set all the cache flush hints in the request.
                        
request.setAttribute(CacheHandlerInterceptor.PARAM_NAME, 
resultContainer.getCacheFlushHints());
 
-                       // Are there new objects?
-                       //TODO: this is wrong. hard coding that the id for new 
nodes is 'new' that way only one new node can be created. So: for now we must 
create an error when there are more create actions than one.
-                       if (nodeMap.containsKey("new")) {
-                               int number = nodeMap.get("new").getNumber();
-                               resultContainer.addNewObject("" + number);
-                       }
                }
 
                // return the proper view.
@@ -123,8 +116,8 @@
                this.commandFactory = commandFactory;
        }
 
-       public void setLocale(Locale locale2) {
-               this.locale = locale2;
+       public void setLocale(Locale locale) {
+               this.locale = locale;
        }
 
 


Index: ReferrerResolver.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/ReferrerResolver.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ReferrerResolver.java       8 Sep 2008 16:52:10 -0000       1.2
+++ ReferrerResolver.java       8 Oct 2008 08:28:57 -0000       1.3
@@ -1,16 +1,18 @@
 package org.mmbase.applications.vprowizards.spring;
 
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.mmbase.applications.vprowizards.spring.util.URLParamMap;
 import org.mmbase.util.logging.Logger;
 import org.mmbase.util.logging.Logging;
 import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.servlet.View;
 import org.springframework.web.servlet.view.RedirectView;
+import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
 
 /**
  * This return page resolver will return the referrer url wiht a parameter 
'nodenr' added when there is a new node in
@@ -27,16 +29,16 @@
 
        public ModelAndView getModelAndView(HttpServletRequest request, 
ResultContainer result) {
 
-               String newPage;
+               String callerPage;
                Map<String, Object> model = new HashMap<String, Object>();
+               ModelAndView errorMandv = new ModelAndView(errorPage);
                
-               //mainly for testing?
-               model.put("idmap", result.getIdMap());
 
                List<GlobalError> globalErrors = result.getGlobalErrors();
                if (result.hasGlobalErrors()) {
-                       model.put("globalerrors", globalErrors);
-                       return new ModelAndView(errorPage, model);
+                   errorMandv.addObject("globalErrors", globalErrors);
+                       log.debug("request has global errors, so the return 
page is: "+errorPage);
+                       return errorMandv;
                } 
                
                if (result.hasFieldErrors()) {
@@ -53,32 +55,34 @@
                // log.debug("object number " + newObject);
                // }
                // }
-
-               newPage = request.getHeader("Referrer");
-               if(newPage == null){
+               callerPage = request.getHeader("referer");
+               if(callerPage == null){
                        //this is an error for this view resolver
                        globalErrors.add(new 
GlobalError("error.no.referrer.header", result.getLocale()));
-                       model.put("globalerrors", globalErrors);
                        log.error("REFERRER NOT SET! This request's redirection 
wil fail.");
-                       return new ModelAndView(errorPage, model);
+            errorMandv.addObject("globalErrors", globalErrors);
+                       return errorMandv;
                }
                // add the node number of the new object to the referer url.
-               if (result.getNewObject().size() > 0) {
-                       if (log.isDebugEnabled()) {
-                               log.debug("new object created.");
-                       }
 
-                       // if (referer.indexOf('?') == -1) {
-                       // newPage = referer + "?nodenr=" + 
result.getNewObject();
-                       // } else {
-                       // newPage = referer + "&nodenr=" + 
result.getNewObject();
-                       // }
-
-                       // if we put the new node in the model, it should be 
added to the query string for redirect views.
-                       model.put("nodenr", result.getNewObject().get(0));
+//             if (result.getNewObject().size() > 0) {
+//                     if (log.isDebugEnabled()) {
+//                             log.debug("new object created.");
+//                     }
+//                     String newNodeNr = result.getNewObject().get(0);
+//                     //newPage = newPage.substring(0, newPage.indexOf("?") + 
1) + "nodenr=" + newNodeNr;
+//                     String newPage = new 
URLParamMap(callerPage).addParam("nodenr", newNodeNr, true).toString();
+//             }
+               
+               URLParamMap u = new URLParamMap(callerPage);
+               if(result.getExtraParams().size() > 0){
+                   for(String param: result.getExtraParams().keySet()){
+                       u.addParam(param, result.getExtraParams().get(param), 
true);
+                   }
                }
 
-               return new ModelAndView(new RedirectView(newPage), model);
+               RedirectView redirectView = new RedirectView(u.toString());
+        return new ModelAndView(redirectView, model);
        }
 
        public void setErrorPage(String errorPage) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to