Author: simoneg
Date: Fri Jul 10 00:39:34 2009
New Revision: 792769

URL: http://svn.apache.org/viewvc?rev=792769&view=rev
Log:
LABS-379 : avoid "cookie lag"
LABS-380 : preliminary support of file upload directly in the binder.

Modified:
    
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java

Modified: 
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java
URL: 
http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java?rev=792769&r1=792768&r2=792769&view=diff
==============================================================================
--- 
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java
 (original)
+++ 
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/OnDemandBinder.java
 Fri Jul 10 00:39:34 2009
@@ -1,6 +1,8 @@
 package org.apache.magma.website.utils;
 
 import java.beans.Introspector;
+import java.io.File;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -12,6 +14,7 @@
 import javax.servlet.http.HttpSession;
 
 import org.apache.commons.fileupload.FileItem;
+import org.apache.magma.basics.MagmaException;
 import org.apache.magma.conversion.Converter;
 import org.apache.magma.conversion.Converters;
 
@@ -69,15 +72,25 @@
                        Map<String, String[]> params = new HashMap<String, 
String[]>();
                        for (Map.Entry<String, FileItem[]> entry : 
uploads.entrySet()) {
                                FileItem[] items = entry.getValue();
-                               if (items[0].isFormField()) {
-                                       String[] vals = new 
String[items.length];
-                                       for (int i = 0; i < vals.length; i++) {
-                                               //try {
-                                                       vals[i] = 
items[i].getString();
-                                               //} catch 
(UnsupportedEncodingException e) {}
+                               String[] vals = new String[items.length];
+                               for (int i = 0; i < vals.length; i++) {
+                                       if (items[0].isFormField()) {
+                                               vals[i] = items[i].getString();
+                                       } else {
+                                               File f;
+                                               try {
+                                                       f = 
File.createTempFile("magma_upload", ".raw");
+                                                       items[i].write(f);
+                                               } catch (Exception e) {
+                                                       throw new 
MagmaException(e, "Error saving temporary uploaded file");
+                                               }
+                                               String origname = 
items[i].getName();
+                                               origname = 
origname.replaceAll("\\\\", "/");
+                                               String[] split = 
origname.split("/");
+                                               vals[i] = split[split.length - 
1] + "/" + f.getAbsolutePath();
                                        }
-                                       params.put(entry.getKey(), vals);
                                }
+                               params.put(entry.getKey(), vals);
                        }
                        return params;
                }
@@ -213,21 +226,23 @@
                        cleanedCookies.remove(rawname);
                }
                
-               boolean found = false;
+               Cookie mycookie = null;
                if (cookies != null) {          
                        for (Cookie cookie : cookies) {
                                if (cookie.getName().equals(rawname)) {
-                                       found = true;
+                                       mycookie = cookie;
                                        break;
                                }
                        }
                }
                if (value != null) {
-                       Cookie ncookie = new Cookie(rawname,(String) 
convertStore(value));
+                       String nval = (String) convertStore(value);
+                       Cookie ncookie = new Cookie(rawname, nval);
                        ncookie.setMaxAge(2592000);
                        ncookie.setPath("/");
                        resp.addCookie(ncookie);
-               } else if (found && value == null) {
+                       if (mycookie != null) mycookie.setValue(nval);
+               } else if (mycookie != null && value == null) {
                        Cookie ncookie = new Cookie(rawname,"");
                        ncookie.setMaxAge(0);
                        ncookie.setPath("/");



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to