Date: 2005-03-10T15:26:05
   Editor: DakotaJack
   Wiki: Apache Struts Wiki
   Page: StrutsUpload
   URL: http://wiki.apache.org/struts/StrutsUpload

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -734,7 +734,7 @@
   private int     maxFileNumber  = -1;
   private long    maxFileSize    = 0x100000000L;
 
-  private boolean overwrite      = false;
+  private boolean overwrite      = true;
 
   public Upload() {}
 
@@ -956,7 +956,7 @@
         }
       }
     } else {
-      return included = false;
+      return included = true;
     }
     return included = false;
   }
@@ -964,8 +964,8 @@
   private void folder(MultipartFile uploadFile)
       throws UploadException,
              IOException {
-    if(uploadFile != null &&
-       uploadFile.getName() != null &&
+    if(uploadFile != null               &&
+       uploadFile.getName() != null     &&
        !uploadFile.getName().equals("") &&
        uploadFile.getSize() >= 0L) {
       if(uploadFile.getSize() > maxFileSize) {
@@ -985,36 +985,38 @@
 
       if(maxFileNumber == -1 || numberOfFiles < maxFileNumber) {
         if(extBarred(uploadFile.getName())) {
-          throw new UploadException(UploadConstant.UPLOAD_FILENAME_DENIED + " 
" + uploadFile.getName());
-        }
-
-        FileOutputStream fos             = null;
-        String           overwriteFileName  = null;
-
-        if(!isSameName) {
-          fos = new FileOutputStream(getStoreLocation() + 
UploadConstant.SEPARATOR + uploadFile.getName());
-        } else if(!overwrite) {
-          overwriteFileName = uploadFile.getName() + ".overwrite." + new 
Date().getTime();
-          fos = new FileOutputStream(getStoreLocation() + 
UploadConstant.SEPARATOR + overwriteFileName);
+          UploadParams uploadParams = new 
UploadParams(uploadFile.getName(),UploadConstant.FAILURE, uploadFile.getSize(), 
uploadFile.getContentType(), "directory", null, null);
+          history.add(uploadParams);
+          uploadFile.getInputStream().close();
         } else {
-          fos = new FileOutputStream(getStoreLocation() + 
UploadConstant.SEPARATOR + uploadFile.getName());
-        }
+          FileOutputStream fos                = null;
+          String           overwriteFileName  = null;
+
+          if(!isSameName) {
+            fos = new FileOutputStream(getStoreLocation() + 
UploadConstant.SEPARATOR + uploadFile.getName());
+          } else if(!overwrite) {
+            overwriteFileName = uploadFile.getName() + ".overwrite." + new 
Date().getTime();
+            fos = new FileOutputStream(getStoreLocation() + 
UploadConstant.SEPARATOR + overwriteFileName);
+          } else {
+            fos = new FileOutputStream(getStoreLocation() + 
UploadConstant.SEPARATOR + uploadFile.getName());
+          }
 
-        InputStream is = uploadFile.getInputStream();
+          InputStream is = uploadFile.getInputStream();
 
-        if(is != null) {
-          byte streamData [] = new byte[UploadConstant.BUFFER_SIZE];
+          if(is != null) {
+            byte streamData [] = new byte[UploadConstant.BUFFER_SIZE];
 
-          for(int i = 0; (i = is.read(streamData)) != -1;) {
-            fos.write(streamData, 0, i);
+            for(int i = 0; (i = is.read(streamData)) != -1;) {
+              fos.write(streamData, 0, i);
+            }
           }
-        }
 
-        fos.close();
-        is.close();
-        UploadParams uploadParams = new UploadParams(uploadFile.getName(), 
uploadFile.getSize(), uploadFile.getContentType(), UploadConstant.DIR, 
storeLocation, overwriteFileName);
-        history.add(uploadParams);
-        notify(uploadParams, uploadFile);
+          fos.close();
+          is.close();
+          UploadParams uploadParams = new UploadParams(uploadFile.getName(), 
UploadConstant.SUCCESS,uploadFile.getSize(), uploadFile.getContentType(), 
"directory", storeLocation, overwriteFileName);
+          history.add(uploadParams);
+          notify(uploadParams, uploadFile);
+        }
       } else {
         throw new UploadException(UploadConstant.UPLOAD_LIMIT_REACHED);
       }
@@ -1035,7 +1037,7 @@
 
       UploadStore uploadStore   = UploadStore.getInstance();
       String      altFileName   = uploadStore.append(storeLocation, 
uploadFile, maxFileNumber, overwrite);
-      UploadParams uploadParams = new UploadParams(uploadFile.getName(), 
uploadFile.getSize(), uploadFile.getContentType(), UploadConstant.ZIP, 
storeLocation, altFileName);
+      UploadParams uploadParams = new 
UploadParams(uploadFile.getName(),UploadConstant.SUCCESS, uploadFile.getSize(), 
uploadFile.getContentType(), "zip", storeLocation, altFileName);
 
       history.add(uploadParams);
       notify(uploadParams, uploadFile);
@@ -1059,7 +1061,7 @@
       }
 
       storeMemory.add(uploadFile);
-      UploadParams uploadParams = new UploadParams(uploadFile.getName(), 
uploadFile.getSize(), uploadFile.getContentType(), UploadConstant.MEM, 
UploadConstant.MEMORY, null);
+      UploadParams uploadParams = new 
UploadParams(uploadFile.getName(),UploadConstant.SUCCESS, uploadFile.getSize(), 
uploadFile.getContentType(), "memory", UploadConstant.MEMORY, null);
       history.add(uploadParams);
       notify(uploadParams, uploadFile);
     }
@@ -1105,11 +1107,11 @@
         }
       }
     } else {
-      return excluded = true;
+      return excluded = false;
     }
     return excluded;
   }
-}
+} ///;-)
 }}}
 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to