Author: raintang Date: 2009-07-22 12:07:51 +0200 (Wed, 22 Jul 2009) New Revision: 37112
Removed: CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AttachmentUploadAction.java CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/ImageUploadAction.java Modified: CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AbstractUploadAction.java CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AssetUploadAction.java CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/WEB-INF/struts-repository.xml CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/editors/repository/assetupload.jsp CMSContainer/trunk/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java Log: CMSC-1472 Improve bulk image and attachment upload to show failed files in branch1.6 and trunk Modified: CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AbstractUploadAction.java =================================================================== --- CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AbstractUploadAction.java 2009-07-22 10:07:30 UTC (rev 37111) +++ CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AbstractUploadAction.java 2009-07-22 10:07:51 UTC (rev 37112) @@ -27,7 +27,6 @@ import org.mmbase.util.transformers.ByteToCharTransformer; import org.mmbase.util.transformers.ChecksumFactory; -import com.finalist.cmsc.mmbase.PropertiesUtil; import com.finalist.cmsc.services.versioning.Versioning; import com.finalist.cmsc.services.versioning.VersioningException; import com.finalist.cmsc.services.workflow.Workflow; @@ -36,7 +35,6 @@ 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; @@ -114,19 +112,4 @@ } } } - - public boolean maxFileSizeBiggerThan(int fileSize) { - int maxFileSize = 8 * 1024 * 1024; // Default value of 16MB - try { - 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/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AssetUploadAction.java =================================================================== --- CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AssetUploadAction.java 2009-07-22 10:07:30 UTC (rev 37111) +++ CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AssetUploadAction.java 2009-07-22 10:07:51 UTC (rev 37112) @@ -1,5 +1,6 @@ package com.finalist.cmsc.repository.forms; +import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -12,7 +13,6 @@ import org.apache.struts.upload.FormFile; import org.mmbase.bridge.Cloud; import org.mmbase.bridge.NodeManager; - import com.finalist.util.http.BulkUploadUtil; public class AssetUploadAction extends AbstractUploadAction { @@ -23,22 +23,16 @@ AssetUploadForm assetUploadForm = (AssetUploadForm) form; String parentchannel = assetUploadForm.getParentchannel(); - String insertAsset = assetUploadForm.getInsertAsset(); FormFile file = assetUploadForm.getFile(); - String exceed = "yes"; - String exist = "1"; - String emptyFile = "no"; String url = ""; - int nodeId = 0; int fileSize = file.getFileSize(); + int failed = 0; + int uploaded = 0; + List<String> notUploadedFiles = new ArrayList<String>(); + List<String> uploadedFiles = new ArrayList<String>(); - if( fileSize == 0 || StringUtils.isEmpty(file.getFileName())){ - emptyFile = "yes"; - } - - if (maxFileSizeBiggerThan(fileSize)&&emptyFile.equalsIgnoreCase("no")) { - exceed = "no"; + if (BulkUploadUtil.maxFileSizeBiggerThan(fileSize) && StringUtils.isNotEmpty(file.getFileName()) && fileSize != 0) { String assetType = ""; if (isImage(file.getFileName())) { assetType = "images"; @@ -49,40 +43,33 @@ NodeManager manager = cloud.getNodeManager(assetType); if (isNewFile(file, manager)) { - exist = "0"; List<Integer> nodes = null; - nodes = BulkUploadUtil.store(cloud, manager, parentchannel, file); + nodes = BulkUploadUtil.store(cloud, manager, parentchannel, file, notUploadedFiles, uploadedFiles); request.setAttribute("uploadedAssets", nodes); // to archive the upload asset if (nodes != null) { addRelationsForNodes(nodes, cloud); - nodeId = nodes.get(0); + uploaded = nodes.size(); } - } - } - if(emptyFile.equalsIgnoreCase("no")){ - if (StringUtils.isNotEmpty(insertAsset)) { - if (insertAsset.equalsIgnoreCase("insertAsset")) { - url = mapping.findForward("insertAsset").getPath() + "&uploadAction=select&exist=" + exist + "&exceed=" - + exceed + "&parentchannel=" + parentchannel + "&uploadedNodes=" + nodeId; - } } else { - url = mapping.findForward(SUCCESS).getPath() + "?type=asset&direction=down&exist=" + exist + "&exceed=" - + exceed + "&parentchannel=" + parentchannel; + notUploadedFiles.add(file.getFileName()); } - }else{ - if (StringUtils.isNotEmpty(insertAsset)) { - if (insertAsset.equalsIgnoreCase("insertAsset")) { - url = mapping.findForward("insertAsset").getPath() + "&uploadAction=select" + - "&parentchannel=" + parentchannel + "&uploadedNodes=" + nodeId+"&emptyFile="+ emptyFile; - } - } else { - url = mapping.findForward(SUCCESS).getPath() + "?type=asset&direction=down" + - "&parentchannel=" + parentchannel+"&emptyFile="+ emptyFile; - } + } else { + notUploadedFiles.add(file.getFileName()); } - - + failed = notUploadedFiles.size(); + uploaded = uploadedFiles.size(); + + if (notUploadedFiles != null) { + request.getSession().setAttribute("notUploadedFiles", notUploadedFiles); + } + if (uploadedFiles != null) { + request.getSession().setAttribute("uploadedFiles", uploadedFiles); + } + + url = mapping.findForward(SUCCESS).getPath() + "?type=asset&direction=down" + "&parentchannel=" + parentchannel + + "&uploaded=" + uploaded + "&failed=" + failed + "&uploadingDone=yes"; + return new ActionForward(url, true); } } Deleted: CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AttachmentUploadAction.java =================================================================== --- CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AttachmentUploadAction.java 2009-07-22 10:07:30 UTC (rev 37111) +++ CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/AttachmentUploadAction.java 2009-07-22 10:07:51 UTC (rev 37112) @@ -1,65 +0,0 @@ -package com.finalist.cmsc.repository.forms; - -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang.StringUtils; -import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionForward; -import org.apache.struts.action.ActionMapping; -import org.apache.struts.upload.FormFile; -import org.mmbase.bridge.Cloud; -import org.mmbase.bridge.NodeManager; - -import com.finalist.cmsc.repository.RepositoryUtil; -import com.finalist.util.http.BulkUploadUtil; - -public class AttachmentUploadAction extends AbstractUploadAction { - - private static final String ALL = "all"; - private static final String SITEASSETS = "siteassets"; - private static final String SESSION_CREATION = "creation"; - - @Override - public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response, Cloud cloud) throws Exception { - - AssetUploadForm attachmentUploadForm = (AssetUploadForm) form; - String parentchannel = attachmentUploadForm.getParentchannel(); - FormFile file = attachmentUploadForm.getFile(); - String strict = attachmentUploadForm.getStrict(); - - String exist = "1"; - String exceed = "yes"; - int nodeId = 0; - - if (parentchannel.equalsIgnoreCase(SITEASSETS)) { - parentchannel = RepositoryUtil.getRoot(cloud); - } else if (parentchannel.equalsIgnoreCase(ALL) || StringUtils.isEmpty(parentchannel)) { - parentchannel = (String) request.getSession().getAttribute(SESSION_CREATION); - } - int fileSize = file.getFileSize(); - if (maxFileSizeBiggerThan(fileSize)) { - NodeManager manager = cloud.getNodeManager("attachments"); - exceed = "no"; - if (isNewFile(file, manager)) { - exist = "0"; - List<Integer> nodes = null; - nodes = BulkUploadUtil.store(cloud, manager, parentchannel, file); - // to archive the upload asset - if (nodes != null) { - addRelationsForNodes(nodes, cloud); - nodeId = nodes.get(0); - } - } else { - exist = "1"; - } - } else { - exist = "0"; - } - return new ActionForward(mapping.findForward(SUCCESS).getPath() + "?uploadAction=select&strict=" + strict + "&exist=" + exist - + "&exceed=" + exceed + "&channelid=" + parentchannel + "&uploadedNodes=" + nodeId, true); - } -} Deleted: CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/ImageUploadAction.java =================================================================== --- CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/ImageUploadAction.java 2009-07-22 10:07:30 UTC (rev 37111) +++ CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/ImageUploadAction.java 2009-07-22 10:07:51 UTC (rev 37112) @@ -1,70 +0,0 @@ -package com.finalist.cmsc.repository.forms; - -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang.StringUtils; -import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionForward; -import org.apache.struts.action.ActionMapping; -import org.apache.struts.upload.FormFile; -import org.mmbase.bridge.Cloud; -import org.mmbase.bridge.NodeManager; - -import com.finalist.cmsc.repository.RepositoryUtil; -import com.finalist.util.http.BulkUploadUtil; - -public class ImageUploadAction extends AbstractUploadAction { - - private static final String ALL = "all"; - private static final String SITEASSETS = "siteassets"; - private static final String SESSION_CREATION = "creation"; - - @Override - public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response, Cloud cloud) throws Exception { - - AssetUploadForm imageUploadForm = (AssetUploadForm) form; - String parentchannel = imageUploadForm.getParentchannel(); - FormFile file = imageUploadForm.getFile(); - String strict = imageUploadForm.getStrict(); - - String exist = "1"; - String exceed = "yes"; - int nodeId = 0; - - if (parentchannel.equalsIgnoreCase(SITEASSETS)) { - parentchannel = RepositoryUtil.getRoot(cloud); - } else if (parentchannel.equalsIgnoreCase(ALL) || StringUtils.isEmpty(parentchannel)) { - parentchannel = (String) request.getSession().getAttribute(SESSION_CREATION); - } - if (isImage(file.getFileName())) { - int fileSize = file.getFileSize(); - if (maxFileSizeBiggerThan(fileSize)) { - NodeManager manager = cloud.getNodeManager("images"); - exceed = "no"; - if (isNewFile(file, manager)) { - exist = "0"; - List<Integer> nodes = null; - nodes = BulkUploadUtil.store(cloud, manager, parentchannel, file); - // to archive the upload asset - if (nodes != null) { - addRelationsForNodes(nodes, cloud); - nodeId = nodes.get(0); - } - } else { - exist = "1"; - } - } else { - exist = "0"; - } - } else { - exist = "0"; - exceed = "no"; - } - return new ActionForward(mapping.findForward(SUCCESS).getPath() + "?uploadAction=select&strict=" + strict + "&exist=" + exist - + "&exceed=" + exceed + "&channelid=" + parentchannel + "&uploadedNodes=" + nodeId, true); - } -} Modified: CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/WEB-INF/struts-repository.xml =================================================================== --- CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/WEB-INF/struts-repository.xml 2009-07-22 10:07:30 UTC (rev 37111) +++ CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/WEB-INF/struts-repository.xml 2009-07-22 10:07:51 UTC (rev 37112) @@ -226,7 +226,6 @@ <action path="/editors/repository/AssetUploadAction" type="com.finalist.cmsc.repository.forms.AssetUploadAction" name="AssetUploadForm" unknown="false" validate="true"> <forward name="success" path="/editors/repository/Asset.do" redirect="true" /> - <forward name="insertAsset" path="/editors/resources/attachmentupload.jsp?insertAsset=insertAsset" redirect="true" /> </action> <action path="/editors/repository/AssetDeleteAction" type="com.finalist.cmsc.repository.forms.AssetDeleteAction" unknown="false" validate="false"> Modified: CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/editors/repository/assetupload.jsp =================================================================== --- CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/editors/repository/assetupload.jsp 2009-07-22 10:07:30 UTC (rev 37111) +++ CMSContainer/trunk/CMSContainer/cmsc/contentrepository/src/webapp/editors/repository/assetupload.jsp 2009-07-22 10:07:51 UTC (rev 37112) @@ -1,4 +1,6 @@ -<%@ page import="com.finalist.util.http.BulkUploadUtil"%> +<%@ page import="com.finalist.util.http.BulkUploadUtil" +%><%@ page import="java.util.List"%> +<%...@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <script type="text/javascript"> function upload() { setTimeout('sayWait();',0); @@ -11,27 +13,11 @@ <html:form action="/editors/repository/AssetUploadAction.do" enctype="multipart/form-data" method="post"> <input type="hidden" id="assetType" name="assetType" value="attachments"/> -<input type="hidden" id="insertAsset" name="insertAsset" value="${param.insertAsset}"/> <input type="hidden" id="parentchannel" name="parentchannel" value="${parentchannel}"/> <table border="0"> <tr> <td><fmt:message key="asset.upload.explanation" /></td> </tr> - <c:if test="${param.exist=='1'}"> - <tr> - <td style="color:red;"><fmt:message key="asset.upload.existed" /></td> - </tr> - </c:if> - <c:if test="${param.emptyFile=='yes'}"> - <tr> - <td style="color:red;"><fmt:message key="asset.upload.emptyfile" /></td> - </tr> - </c:if> - <c:if test="${param.exceed == 'yes'}"> - <tr> - <td style="color:red;"><fmt:message key="asset.upload.size.exceed"/></td> - </tr> - </c:if> <tr> <td><html:file property="file" /></td> </tr> @@ -39,6 +25,34 @@ <td><html:submit property="uploadButton" onclick="upload();"> <fmt:message key='assets.upload.submit' /></html:submit></td> </tr> + <c:if test="${param.uploadingDone eq 'yes'}"> + <tr> + <td>Failed Attachments and Images: ${param.failed}</td> + </tr> + <c:if test="${param.failed != 0}" > + <tr> + <td> + <c:forEach var="fileName" items="${notUploadedFiles}" varStatus="fileAmount"> + ${fileName} + </c:forEach> + <c:remove var="notUploadedFiles" scope="session"/> + </td> + </tr> + </c:if> + <tr> + <td>Uploaded Attachments and Images: ${param.uploaded}</td> + </tr> + <c:if test="${param.uploaded != 0}" > + <tr> + <td> + <c:forEach var="fileName" items="${uploadedFiles}" varStatus="fileAmount" > + ${fileName} + </c:forEach> + <c:remove var="notUploadedFiles" scope="session"/> + </td> + </tr> + </c:if> + </c:if> </table> </html:form> <div id="busy"><fmt:message key="uploading.message.wait" /><br /> Modified: CMSContainer/trunk/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java =================================================================== --- CMSContainer/trunk/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java 2009-07-22 10:07:30 UTC (rev 37111) +++ CMSContainer/trunk/CMSContainer/cmsc/utilities/src/java/com/finalist/util/http/BulkUploadUtil.java 2009-07-22 10:07:51 UTC (rev 37112) @@ -49,6 +49,8 @@ private static final Log log = LogFactory.getLog(BulkUploadUtil.class); private static final int MAXSIZE = 256 * 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"; @@ -106,12 +108,13 @@ return nodes; } - public static List<Integer> store(Cloud cloud, NodeManager manager, String parentchannel, FormFile file) { + public static List<Integer> store(Cloud cloud, NodeManager manager, String parentchannel, FormFile file + ,List<String> notUploadedFiles, List<String> uploadedFiles) { List<Integer> nodes; if (StringUtils.isEmpty(parentchannel)) { throw new NullPointerException("parentchannel is null"); } - nodes = getNodeList(Integer.valueOf(parentchannel), manager, file, cloud); + nodes = getNodeList(Integer.valueOf(parentchannel), manager, file, cloud, notUploadedFiles, uploadedFiles); return nodes; } @@ -162,7 +165,8 @@ return node; } - private static List<Integer> getNodeList(Integer parentChannel, NodeManager manager, FormFile file, Cloud cloud) { + private static List<Integer> getNodeList(Integer parentChannel, NodeManager manager, FormFile file, Cloud cloud, + List<String> notUploadedFiles, List<String> uploadedFiles) { List<Integer> nodes = null; try { if (isZipFile(file.getContentType(), file.getFileName())) { @@ -183,11 +187,12 @@ InputStream is = new BufferedInputStream(bis); ZipInputStream zip = new ZipInputStream(is); - nodes = createNodesInZip(parentChannel, manager, zip, cloud); + nodes = createNodesInZip(parentChannel, manager, zip, cloud, notUploadedFiles, uploadedFiles); } else { Node node = createNode(parentChannel, manager, file.getFileName(), file.getInputStream(), file .getFileSize()); + uploadedFiles.add(file.getFileName()); if (node != null) { nodes = new ArrayList<Integer>(); nodes.add(node.getNumber()); @@ -246,7 +251,7 @@ } private static ArrayList<Integer> createNodesInZip(Integer parentChannel, NodeManager manager, ZipInputStream zip, - Cloud cloud) { + Cloud cloud, List<String> notUploadedFiles, List<String> uploadedFiles) { ZipEntry entry = null; int count = 0; @@ -271,8 +276,7 @@ } count++; long size = entry.getSize(); - - if (size < Integer.parseInt(PropertiesUtil.getProperty("uploaded.file.max.size")) * 1024 * 1024) { + if (maxFileSizeBiggerThan(size)) { ChecksumFactory checksumFactory = new ChecksumFactory(); ByteToCharTransformer transformer = (ByteToCharTransformer) checksumFactory .createTransformer(checksumFactory.createParameters()); @@ -292,9 +296,14 @@ Node node = createNode(parentChannel, manager, entry.getName(), is, size); if (node != null) { nodes.add(node.getNumber()); + uploadedFiles.add(entry.getName()); } is.close(); + } else { + notUploadedFiles.add(entry.getName()); } + } else { + notUploadedFiles.add(entry.getName()); } zip.closeEntry(); } @@ -371,4 +380,20 @@ System.out.println(isZipFile("application/x-zip-compressed","helloworld.zipper")); //Should be true System.out.println(isZipFile("content","helloworld.zipper")); //Should be false } + public static boolean maxFileSizeBiggerThan(long fileSize) { + int maxFileSize = MAXSIZE; + if (PropertiesUtil.getProperty(UPLOADED_FILE_MAX_SIZE) != null) { + try { + 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 = MAXSIZE; + } + } catch (NumberFormatException e) { + log.warn("System property '" + UPLOADED_FILE_MAX_SIZE + "' is not set. Please add it (units = MB)."); + } + } + return (fileSize <= maxFileSize); + } } \ No newline at end of file _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs