Author: xlawrence
Date: Tue May 15 13:11:35 2007
New Revision: 17307

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17307&repname=
=3Djahia
Log:
added method getFormFieldName in order to retrieve the form input's origina=
l name
added getter and setter on parameter map
some optimizations
avoid NPE if in method getParameterValues if parameter passed does not exist

Modified:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/tools/files/FileUp=
load.java

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/tools/files/=
FileUpload.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/tools/files/FileUpload.java&rev=3D17307&rep=
name=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/tools/files/FileUp=
load.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/tools/files/FileUp=
load.java Tue May 15 13:11:35 2007
@@ -61,15 +61,15 @@
      * @param savePath the path where files should be saved
      * @param fileMaxSize the max size of file to upload
      */
-    public FileUpload(HttpServletRequest req,
-                      String savePath, int fileMaxSize)
+    public FileUpload(final HttpServletRequest req,
+                      final String savePath,
+                      final int fileMaxSize)
         throws IOException {
 =

         this.req =3D req;
         this.fileMaxSize =3D fileMaxSize;
         this.savePath =3D savePath;
         init();
-
     }
 =

     /**
@@ -87,21 +87,21 @@
 =

         if (checkSavePath(savePath)) {
             try {
-                DiskFileItemFactory factory =3D new DiskFileItemFactory();
+                final DiskFileItemFactory factory =3D new DiskFileItemFact=
ory();
                 factory.setSizeThreshold(1);
                 factory.setRepository(new File(savePath));
 =

-                ServletFileUpload upload =3D new ServletFileUpload(factory=
);
+                final ServletFileUpload upload =3D new ServletFileUpload(f=
actory);
 =

-                List items =3D upload.parseRequest(req);
+                final List items =3D upload.parseRequest(req);
 =

-                Iterator iter =3D items.iterator();
+                final Iterator iter =3D items.iterator();
                 while (iter.hasNext()) {
-                    DiskFileItem item =3D (DiskFileItem) iter.next();
+                    final DiskFileItem item =3D (DiskFileItem) iter.next();
 =

                     if (item.isFormField()) {
-                        String name =3D item.getFieldName();
-                        List v ;
+                        final String name =3D item.getFieldName();
+                        final List v ;
                         if (params.containsKey(name)) {
                             v =3D (List) params.get(name);
                         } else {
@@ -137,14 +137,23 @@
         return params.keySet();
     }
 =

+    public Map getParameterMap () {
+        return params;
+    }
+
+    public void setParameterMap(Map params) {
+        this.params =3D params;
+    }
+
     /**
      * Return the values of a parameter
      *
      * @param paramName the name of the parameter
      * @return the values of a paramater as a String Array
      */
-    public String[] getParameterValues (String paramName) {
-        List list =3D ((List) params.get(paramName));
+    public String[] getParameterValues (final String paramName) {
+        final List list =3D ((List) params.get(paramName));
+        if (list =3D=3D null) return null;
         String[] res =3D new String[list.size()];
         list.toArray(res);
         return res;
@@ -167,6 +176,10 @@
         return ((DiskFileItem) files.get(n)).getName();
     }
 =

+    public String getFormFieldName(String n) {
+        return ((DiskFileItem) files.get(n)).getFieldName();
+    }
+
     public String getFileContentType(String n) {
         return ((DiskFileItem) files.get(n)).getContentType();
     }
@@ -207,15 +220,15 @@
             return;
         }
 =

-        StringTokenizer tokenizer =3D new StringTokenizer(req.getQueryStri=
ng(),
+        final StringTokenizer tokenizer =3D new StringTokenizer(req.getQue=
ryString(),
                 "&");
         while (tokenizer.hasMoreTokens()) {
-            String param =3D tokenizer.nextToken();
+            final String param =3D tokenizer.nextToken();
             int pos =3D param.indexOf("=3D");
             if (pos > 0) {
-                String name =3D param.substring(0, pos);
-                String value =3D param.substring(pos + 1, param.length());
-                List v ;
+                final String name =3D param.substring(0, pos);
+                final String value =3D param.substring(pos + 1, param.leng=
th());
+                final List v ;
                 if (params.containsKey(name)) {
                     v =3D (List) params.get(name);
                 } else {

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to