Author: billyxie Date: 2009-07-30 08:39:08 +0200 (Thu, 30 Jul 2009) New Revision: 37344
Modified: CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository.properties CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_nl.properties CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_zh.properties CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/resources/forms/AbstractUploadAction.java CMSContainer/branches/b1_5/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java Log: CMSC-1467 - Improve bulk image and attachment upload to show failed files for version 1.5 Modified: CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository.properties =================================================================== --- CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository.properties 2009-07-29 19:54:04 UTC (rev 37343) +++ CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository.properties 2009-07-30 06:39:08 UTC (rev 37344) @@ -343,7 +343,7 @@ images.upload.result=Uploaded {0} image(s) images.upload.filetypeinvalid=Please upload a local image or a ZIP-file containing multiple images. images.upload.emptyfile=Please upload a local image or a ZIP-file containing multiple images. -images.upload.bigfile=The file is too big(max 8MB). +images.upload.bigfile=The file is too big. images.upload.failedtip=Failed image(s): images.upload.uploadedtip=Uploaded image(s): images.upload.info=Info @@ -355,7 +355,7 @@ attachments.upload.explanation=Select a local attachment file or a ZIP-file containing multiple attachments attachments.upload.result=Uploaded {0} attachment(s) attachments.upload.emptyfile=Please select a attachment file or Zip file to upload. -attachments.upload.bigfile=The attachment(s) is too big(max 8MB). +attachments.upload.bigfile=The attachment is too big. attachments.upload.failedtip=Failed attachment(s): attachments.upload.uploadedtip=Uploaded attachment(s): attachments.upload.info=Info Modified: CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_nl.properties =================================================================== --- CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_nl.properties 2009-07-29 19:54:04 UTC (rev 37343) +++ CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_nl.properties 2009-07-30 06:39:08 UTC (rev 37344) @@ -344,7 +344,7 @@ images.upload.result=Aantal afbeeldingen geupload: {0} images.upload.filetypeinvalid=Please upload a local image or a ZIP-file containing multiple images. images.upload.emptyfile=Please upload a local image or a ZIP-file containing multiple images. -images.upload.bigfile=The file is too big(max 8MB). +images.upload.bigfile=The file is too big. images.upload.failedtip=Failed image(s): images.upload.uploadedtip=Uploaded image(s): images.upload.info=Info @@ -356,7 +356,7 @@ attachments.upload.explanation=Kies een lokale bijlage of een ZIP-bestand met meerdere bijlagen attachments.upload.result=Aantal bijlagen geupload: {0} attachments.upload.emptyfile=Please select a attachment file or Zip file to upload. -attachments.upload.bigfile=The attachment(s) is too big(max 8MB). +attachments.upload.bigfile=The attachment is too big. attachments.upload.failedtip=Failed attachment(s): attachments.upload.uploadedtip=Uploaded attachment(s): attachments.upload.info=Info Modified: CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_zh.properties =================================================================== --- CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_zh.properties 2009-07-29 19:54:04 UTC (rev 37343) +++ CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/resources/cmsc-repository_zh.properties 2009-07-30 06:39:08 UTC (rev 37344) @@ -342,7 +342,7 @@ images.upload.result=更新 {0} 个图片(s) images.upload.filetypeinvalid=请上传图片或zip文件格式的图片压缩包. images.upload.emptyfile=请上传图片或zip文件格式的图片压缩包. -images.upload.bigfile=文件太大(最大 8MB). +images.upload.bigfile=文件太大. images.upload.failedtip=上传失败的图片: images.upload.uploadedtip=上传成功的图片: images.upload.info=信息 @@ -354,7 +354,7 @@ attachments.upload.explanation=选择一个本地的附件或者包含若干附件的zip文件 attachments.upload.result=更新 {0} 个附件(s) attachments.upload.emptyfile=选择一个本地的附件或者包含若干附件的zip文件 -attachments.upload.bigfile=附件太大(最大 8MB). +attachments.upload.bigfile=附件太大. attachments.upload.failedtip=上传失败的附件: attachments.upload.uploadedtip=上传成功的附件: attachments.upload.info=信息 Modified: CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/resources/forms/AbstractUploadAction.java =================================================================== --- CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/resources/forms/AbstractUploadAction.java 2009-07-29 19:54:04 UTC (rev 37343) +++ CMSContainer/branches/b1_5/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/resources/forms/AbstractUploadAction.java 2009-07-30 06:39:08 UTC (rev 37344) @@ -22,7 +22,6 @@ import org.mmbase.bridge.Cloud; import org.mmbase.bridge.NodeManager; -import com.finalist.cmsc.mmbase.PropertiesUtil; import com.finalist.cmsc.struts.MMBaseAction; import com.finalist.util.http.BulkUploadUtil; @@ -32,14 +31,12 @@ */ public abstract class AbstractUploadAction extends MMBaseAction { - public static final String UPLOADED_FILE_MAX_SIZE = "uploaded.file.max.size"; - public static final String CONFIGURATION_RESOURCE_NAME = "/com/finalist/util/http/util.properties"; protected static Set<String> supportedImages; protected static final Log log = LogFactory.getLog(AbstractUploadAction.class); - + @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, Cloud cloud) throws Exception{ @@ -59,7 +56,7 @@ fileIsEmpty = true; return new ActionForward(mapping.findForward(SUCCESS).getPath() + "?fileIsEmpty=" + fileIsEmpty, true); } - if(!maxFileSizeBiggerThan(fileSize)){ + if(!BulkUploadUtil.isZipFile(file.getContentType(), file.getFileName()) && !validFileSize(fileSize)){ fileTooBig = true; return new ActionForward(mapping.findForward(SUCCESS).getPath() + "?fileTooBig=" + fileTooBig, true); } @@ -87,6 +84,10 @@ + numberOfFailedFiles, true); } + private boolean validFileSize(int fileSize) { + return BulkUploadUtil.validFileSize(fileSize); + } + protected abstract String getNodeManagerName(); protected abstract boolean validFileType(FormFile file); @@ -129,23 +130,6 @@ return fileName.substring(index); } - public boolean maxFileSizeBiggerThan(int fileSize) { - int maxFileSize = 8 * 1024 * 1024; // Default value of 16MB - try { - if(!StringUtil.isEmpty(PropertiesUtil.getProperty(UPLOADED_FILE_MAX_SIZE))){ - maxFileSize = Integer.parseInt(PropertiesUtil.getProperty(UPLOADED_FILE_MAX_SIZE)) * 1024 * 1024; - } - // check invalid value of UPLOADED_FILE_MAX_SIZE - if (maxFileSize <= 0) { - // PropertiesUtil.setProperty(UPLOADED_FILE_MAX_SIZE, "8"); - maxFileSize = 8 * 1024 * 1024; // set default value of 16MB - } - } - catch (NumberFormatException e) { - log.warn("System property '" + UPLOADED_FILE_MAX_SIZE - + "' is not set. Please add it (units = MB)."); - } - return (fileSize <= maxFileSize); - } + } Modified: CMSContainer/branches/b1_5/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java =================================================================== --- CMSContainer/branches/b1_5/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java 2009-07-29 19:54:04 UTC (rev 37343) +++ CMSContainer/branches/b1_5/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java 2009-07-30 06:39:08 UTC (rev 37344) @@ -30,6 +30,8 @@ import javax.servlet.http.HttpServletRequest; +import net.sf.mmapps.commons.util.StringUtil; + import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,14 +45,17 @@ import org.mmbase.util.transformers.ByteToCharTransformer; import org.mmbase.util.transformers.ChecksumFactory; +import com.finalist.cmsc.mmbase.PropertiesUtil; import com.finalist.cmsc.util.UploadUtil; public class BulkUploadUtil { private static final Log log = LogFactory.getLog(BulkUploadUtil.class); - private static final int MAXSIZE = 256 * 1024 * 1024; + private static final int MAXSIZE = 16 * 1024 * 1024; + public static final String UPLOADED_FILE_MAX_SIZE = "uploaded.file.max.size"; + private static final String CONFIGURATION_RESOURCE_NAME = "/com/finalist/util/http/util.properties"; private static final String ZIP_MIME_TYPES[] = new String[] { "application/x-zip-compressed", "application/zip", @@ -111,20 +116,8 @@ try { if (isZipFile(file.getContentType(), file.getFileName())) { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); InputStream in = file.getInputStream(); - byte[] temp = new byte[1024]; - int read; - - while ((read = in.read(temp)) > -1) { - buffer.write(temp, 0, read); - } - - byte[] fileData = buffer.toByteArray(); - - // byte[] fileData = file.getFileData(); - ByteArrayInputStream bis = new ByteArrayInputStream(fileData); - InputStream is = new BufferedInputStream(bis); + InputStream is = new BufferedInputStream(in); ZipInputStream zip = new ZipInputStream(is); createNodesInZip(manager, zip, cloud, nodes, uploadedFileList, failedFileList); @@ -148,6 +141,24 @@ } } + public static boolean validFileSize(int fileSize) { + int maxFileSize = MAXSIZE; + try { + if(!StringUtil.isEmpty(PropertiesUtil.getProperty(UPLOADED_FILE_MAX_SIZE))){ + maxFileSize = Integer.parseInt(PropertiesUtil.getProperty(UPLOADED_FILE_MAX_SIZE)) * 1024 * 1024; + } + // check invalid value of UPLOADED_FILE_MAX_SIZE + if (maxFileSize <= 0) { + maxFileSize = MAXSIZE; // set default value of 16MB + } + } + catch (NumberFormatException e) { + log.warn("System property '" + UPLOADED_FILE_MAX_SIZE + + "' is not set. Please add it (units = MB)."); + } + return (fileSize <= maxFileSize); + } + public static boolean isZipFile(String contentType, String fileName) { for (String element : ZIP_MIME_TYPES) { @@ -244,6 +255,10 @@ } count++; long size = entry.getSize(); + if(!validFileSize((int) size)){ + failedFileList.add(entry.getName()); + continue; + } ByteArrayOutputStream fileData = readFromZip(zip); boolean isNewFile = isNewFile(manager, fileData); _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs