roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r370514 - in /incubator/roller/trunk: src/org/roller/presentation/website/actions/ src/org/roller/presentation/website/formbeans/ web/WEB-INF/classes/ web/theme/scripts/ web/website/
Date Thu, 19 Jan 2006 16:02:25 GMT
Author: snoopdave
Date: Thu Jan 19 08:02:11 2006
New Revision: 370514

URL: http://svn.apache.org/viewcvs?rev=370514&view=rev
Log:
Fixes ROL-858 mutli-file upload

Modified:
    incubator/roller/trunk/src/org/roller/presentation/website/actions/UploadFileFormAction.java
    incubator/roller/trunk/src/org/roller/presentation/website/formbeans/UploadFileForm.java
    incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties
    incubator/roller/trunk/web/theme/scripts/roller.js
    incubator/roller/trunk/web/website/UploadFile.jsp

Modified: incubator/roller/trunk/src/org/roller/presentation/website/actions/UploadFileFormAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/website/actions/UploadFileFormAction.java?rev=370514&r1=370513&r2=370514&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/website/actions/UploadFileFormAction.java
(original)
+++ incubator/roller/trunk/src/org/roller/presentation/website/actions/UploadFileFormAction.java
Thu Jan 19 08:02:11 2006
@@ -8,7 +8,6 @@
 import java.util.List;
 
 import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -19,6 +18,8 @@
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
 import org.apache.struts.actions.DispatchAction;
 import org.apache.struts.upload.FormFile;
 import org.roller.RollerException;
@@ -29,6 +30,7 @@
 import org.roller.model.RollerFactory;
 import org.roller.pojos.WebsiteData;
 import org.roller.presentation.BasePageModel;
+import org.roller.presentation.RollerContext;
 import org.roller.presentation.RollerRequest;
 import org.roller.presentation.RollerSession;
 import org.roller.presentation.website.formbeans.UploadFileForm;
@@ -83,15 +85,18 @@
         
         ActionForward fwd = mapping.findForward("access-denied"); 
         WebsiteData website = getWebsite(request);
-        RollerMessages msgs = new RollerMessages();
+        RollerMessages rollerMessages = new RollerMessages();
         RollerSession rses = RollerSession.getRollerSession(request);
+        List lastUploads = new ArrayList();
         
         if ( rses.isUserAuthorizedToAuthor(website)) {
             
+            FileManager fmgr = RollerFactory.getRoller().getFileManager();
             fwd = mapping.findForward("uploadFiles.page");
+            ActionMessages messages = new ActionMessages();
             ActionErrors errors = new ActionErrors();
             UploadFileForm theForm = (UploadFileForm)actionForm;
-            if ( theForm.getUploadedFile() != null ) {
+            if (theForm.getUploadedFiles().length > 0) {
                 ServletContext app = servlet.getServletConfig().getServletContext();
 
                 boolean uploadEnabled =
@@ -112,8 +117,7 @@
                 }
 
                 //retrieve the file representation
-                //FormFile[] files = theForm.getUploadedFiles();
-                FormFile[] files = new FormFile[]{theForm.getUploadedFile()};
+                FormFile[] files = theForm.getUploadedFiles();
                 int fileSize = 0;
                 try {
                     for (int i=0; i<files.length; i++) {
@@ -130,12 +134,12 @@
                         fileSize = files[i].getFileSize();
 
                         //retrieve the file data
-                        FileManager fmgr = RollerFactory.getRoller().getFileManager();
-                        if (fmgr.canSave(website.getHandle(), fileName, fileSize, msgs))
{
+                        if (fmgr.canSave(website.getHandle(), fileName, fileSize, rollerMessages))
{
                             InputStream stream = files[i].getInputStream();
                             fmgr.saveFile(website.getHandle(), fileName, fileSize, stream);
+                            lastUploads.add(fileName);
                         }
-
+                        
                         //destroy the temporary file created
                         files[i].destroy();
                     }
@@ -145,16 +149,27 @@
                 }
             }        
             UploadFilePageModel pageModel = new UploadFilePageModel(
-                request, response, mapping, website.getHandle());
+                request, response, mapping, website.getHandle(), lastUploads);
             request.setAttribute("model", pageModel);
             pageModel.setWebsite(website);
+            
+            RollerContext rctx = RollerContext.getRollerContext();
+		    String baseURL = rctx.getAbsoluteContextUrl(request);
+            String resourcesBaseURL = baseURL + fmgr.getUploadUrl() + "/" + website.getHandle();
+            Iterator uploads = lastUploads.iterator();
+            while (uploads.hasNext()) {                
+                messages.add(ActionMessages.GLOBAL_MESSAGE, 
+                    new ActionMessage("uploadFiles.uploadedFile", 
+                        resourcesBaseURL + "/" + (String)uploads.next()));
+            }
+            saveMessages(request, messages);
 
-            Iterator iter = msgs.getErrors();
+            Iterator iter = rollerMessages.getErrors();
             while (iter.hasNext()) {
                 RollerMessages.RollerMessage error =
-                        (RollerMessages.RollerMessage) iter.next();
+                    (RollerMessages.RollerMessage)iter.next();
                 errors.add(ActionErrors.GLOBAL_ERROR,
-                        new ActionError(error.getKey(), error.getArgs()));
+                    new ActionError(error.getKey(), error.getArgs()));
             }
             saveErrors(request, errors);
         }
@@ -171,11 +186,13 @@
             HttpServletResponse response)
             throws Exception {
 
+        ActionMessages messages = new ActionMessages();
         ActionErrors errors = new ActionErrors();
         UploadFileForm theForm = (UploadFileForm)actionForm;
         ActionForward fwd = mapping.findForward("access-denied");        
         WebsiteData website = getWebsite(request);
 
+        int count = 0;
         RollerSession rses = RollerSession.getRollerSession(request);
         if (rses.isUserAuthorizedToAuthor(website)) {
             fwd = mapping.findForward("uploadFiles.page"); 
@@ -189,6 +206,7 @@
                         // ignore absolute paths, or paths that contiain '..'
                     } else {
                         fmgr.deleteFile(website.getHandle(), deleteFiles[i]);
+                        count++;
                     }
                 }
             } catch (Exception e) {
@@ -196,6 +214,11 @@
                         new ActionError("error.upload.file",e.toString()));
                 saveErrors(request,errors);
             }
+            
+            messages.add(ActionMessages.GLOBAL_MESSAGE, 
+                new ActionMessage("uploadFiles.deletedFiles", new Integer(count)));
+            saveMessages(request, messages);
+            
             UploadFilePageModel pageModel = new UploadFilePageModel(
                 request, response, mapping, website.getHandle());
             pageModel.setWebsite(website);
@@ -222,6 +245,7 @@
         return website;
     }
     
+    
     /** All information we'll need on the UploadFile page */
     public class UploadFilePageModel extends BasePageModel {
         private String resourcesBaseURL = null;
@@ -231,12 +255,22 @@
         private String maxFileMB = null; // in megabytes
         private List files = null;
         private long totalSize = 0;
+        private List lastUploads = null;
         
         public UploadFilePageModel(
                 HttpServletRequest req, 
                 HttpServletResponse res, 
                 ActionMapping mapping,
                 String weblogHandle) throws RollerException {
+            this(req, res, mapping, weblogHandle, null);
+        }
+       
+        public UploadFilePageModel(
+                HttpServletRequest req, 
+                HttpServletResponse res, 
+                ActionMapping mapping,
+                String weblogHandle,
+                List lastUploads) throws RollerException {
             
             super("uploadFiles.title", req, res, mapping);
             
@@ -249,8 +283,8 @@
             
             RollerRequest rreq = RollerRequest.getRollerRequest(req);
             WebsiteData website = UploadFileFormAction.getWebsite(req);            
-            String maxDirMB = RollerRuntimeConfig.getProperty("uploads.dir.maxsize");
-            String maxFileMB = RollerRuntimeConfig.getProperty("uploads.file.maxsize");
+            maxDirMB = RollerRuntimeConfig.getProperty("uploads.dir.maxsize");
+            maxFileMB = RollerRuntimeConfig.getProperty("uploads.file.maxsize");
                      
             overQuota = fmgr.overQuota(weblogHandle);
             uploadEnabled = RollerRuntimeConfig.getBooleanProperty("uploads.enabled");  
@@ -282,6 +316,9 @@
         }
         public List getFiles() {
             return files;
+        }
+        public List getLastUploads() {
+            return lastUploads;
         }
     }
     

Modified: incubator/roller/trunk/src/org/roller/presentation/website/formbeans/UploadFileForm.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/website/formbeans/UploadFileForm.java?rev=370514&r1=370513&r2=370514&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/website/formbeans/UploadFileForm.java
(original)
+++ incubator/roller/trunk/src/org/roller/presentation/website/formbeans/UploadFileForm.java
Thu Jan 19 08:02:11 2006
@@ -1,48 +1,87 @@
 
 package org.roller.presentation.website.formbeans;
 
+import java.util.ArrayList;
+import org.apache.commons.lang.StringUtils;
 import org.apache.struts.upload.FormFile;
 
 
 /**
- * Allows the user to upload a set of files.
+ * Form holds data for 5 uploaded files and array of file names of files to be deleted.
  * @struts.form name="uploadFiles"
  */
 public class UploadFileForm
-    extends    org.apache.struts.action.ActionForm
-{
-    //protected FormFile[] mUploadedFiles = null;
-    protected transient FormFile mUploadedFile = null;
-
-    // The name of file to be deleted
-    protected String[] mDeleteFiles;
-
-    public UploadFileForm()
-    {
+        extends org.apache.struts.action.ActionForm {
+    
+    // TODO: can file-upload be improved to allow an arbitrary number of files?
+    protected transient FormFile upload0 = null;
+    protected transient FormFile upload1 = null;
+    protected transient FormFile upload2 = null;
+    protected transient FormFile upload3 = null;
+    protected transient FormFile upload4 = null;
+    protected transient FormFile upload5 = null;
+    protected transient FormFile upload6 = null;
+    protected transient FormFile upload7 = null;
+    protected transient FormFile upload8 = null;
+    protected transient FormFile upload9 = null;
+    
+    protected String[] deleted;
+    
+    public UploadFileForm() {
         super();
     }
-
-    //------------------------------------------------- Property uploadedFiles
-
-    /** files to be written to disk */
-    //public void setUploadedFiles(FormFile[] files) { mUploadedFiles = files; }
-
-    /** files to be written to disk */
-    //public FormFile[] getUploadedFiles() { return mUploadedFiles; }
-
-    /** files to be written to disk */
-    public void setUploadedFile(FormFile file) { mUploadedFile = file; }
-
-    /** files to be written to disk */
-    public FormFile getUploadedFile() { return mUploadedFile; }
-
-    /** files to be deleted from disk **/
-    public void setDeleteFiles(String[] fileNames)
-    {
-        mDeleteFiles = fileNames;
+    
+    public FormFile[] getUploadedFiles() {
+        ArrayList formFiles = new ArrayList();
+        if (upload0 != null && !StringUtils.isEmpty(upload0.getFileName())) 
+            formFiles.add(upload0);
+        if (upload1 != null && !StringUtils.isEmpty(upload1.getFileName())) 
+            formFiles.add(upload1);
+        if (upload2 != null && !StringUtils.isEmpty(upload2.getFileName())) 
+            formFiles.add(upload2);
+        if (upload3 != null && !StringUtils.isEmpty(upload3.getFileName())) 
+            formFiles.add(upload3);
+        if (upload4 != null && !StringUtils.isEmpty(upload4.getFileName())) 
+            formFiles.add(upload4);
+        if (upload5 != null && !StringUtils.isEmpty(upload5.getFileName())) 
+            formFiles.add(upload5);
+        if (upload6 != null && !StringUtils.isEmpty(upload6.getFileName())) 
+            formFiles.add(upload6);
+        if (upload7 != null && !StringUtils.isEmpty(upload7.getFileName())) 
+            formFiles.add(upload7);
+        if (upload8 != null && !StringUtils.isEmpty(upload8.getFileName())) 
+            formFiles.add(upload8);
+        if (upload9 != null && !StringUtils.isEmpty(upload9.getFileName())) 
+            formFiles.add(upload9);
+        return (FormFile[])formFiles.toArray(new FormFile[formFiles.size()]);
     }
-
-    /** files to be deleted from disk **/
-    public String[] getDeleteFiles() { return mDeleteFiles; }
+    
+    public void setUploadedFile0(FormFile file) { upload0 = file; }
+    public void setUploadedFile1(FormFile file) { upload1 = file; }
+    public void setUploadedFile2(FormFile file) { upload2 = file; }
+    public void setUploadedFile3(FormFile file) { upload3 = file; }
+    public void setUploadedFile4(FormFile file) { upload4 = file; }    
+    public void setUploadedFile5(FormFile file) { upload5 = file; }
+    public void setUploadedFile6(FormFile file) { upload6 = file; }
+    public void setUploadedFile7(FormFile file) { upload7 = file; }
+    public void setUploadedFile8(FormFile file) { upload8 = file; }
+    public void setUploadedFile9(FormFile file) { upload9 = file; }
+    
+    public FormFile getUploadedFile0() { return upload0; }
+    public FormFile getUploadedFile1() { return upload1; }
+    public FormFile getUploadedFile2() { return upload2; }
+    public FormFile getUploadedFile3() { return upload3; }
+    public FormFile getUploadedFile4() { return upload4; }   
+    public FormFile getUploadedFile5() { return upload5; }
+    public FormFile getUploadedFile6() { return upload6; }
+    public FormFile getUploadedFile7() { return upload7; }
+    public FormFile getUploadedFile8() { return upload8; }
+    public FormFile getUploadedFile9() { return upload9; }
+    
+    public void setDeleteFiles(String[] fileNames) {
+        deleted = fileNames;
+    }
+    
+    public String[] getDeleteFiles() { return deleted; }
 }
 

Modified: incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties?rev=370514&r1=370513&r2=370514&view=diff
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties (original)
+++ incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties Thu Jan 19
08:02:11 2006
@@ -1130,6 +1130,8 @@
 uploadFiles.noFiles=No files found.
 
 uploadFiles.button.delete=Delete Selected
+uploadFiles.uploadedFile=Uploaded file: {0}
+uploadFiles.deletedFiles=Deleted {0} file(s)
 
 # ------------------------------------------------------------------- User admin
 
@@ -1334,6 +1336,8 @@
 weblogEdit.trackbackUrl=Trackback URL
 weblogEdit.trackbackResults=<b>Trackback response (error code 0 indicates \
 success):</b><br /><br />{0}
+weblogEdit.trackbackStatusCodeGood=Target blog returned HTTP response code {0} 
+weblogEdit.trackbackStatusCodeBad=ERROR: Target blog returned HTTP response code {0} 
 
 weblogEdit.hasComments=Comments [{0}]
 

Modified: incubator/roller/trunk/web/theme/scripts/roller.js
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/theme/scripts/roller.js?rev=370514&r1=370513&r2=370514&view=diff
==============================================================================
--- incubator/roller/trunk/web/theme/scripts/roller.js (original)
+++ incubator/roller/trunk/web/theme/scripts/roller.js Thu Jan 19 08:02:11 2006
@@ -151,6 +151,13 @@
     }
 }
 
+function isblank(s) {
+   for (var i=0; i<s.length; s++) {
+      var c = s.charAt(i);
+      if ((c!=' ') && (c!='\n') && (c!='')) return false;
+   }
+    return true;
+}
 
 // Show the document's title on the status bar
 window.defaultStatus=document.title;

Modified: incubator/roller/trunk/web/website/UploadFile.jsp
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/website/UploadFile.jsp?rev=370514&r1=370513&r2=370514&view=diff
==============================================================================
--- incubator/roller/trunk/web/website/UploadFile.jsp (original)
+++ incubator/roller/trunk/web/website/UploadFile.jsp Thu Jan 19 08:02:11 2006
@@ -8,6 +8,55 @@
 ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
 %>
 
+<script type="text/javascript">
+<!--
+var max = 9;
+var count = 0;
+function toggleMore(targetId) {
+    if (document.getElementById) {
+        ++count;
+        var id = targetId + count;
+        target = document.getElementById(id);
+        target.style.display = "inline";
+        if (count == max) {
+           target = document.getElementById("moreToggle");
+           target.style.display = "none";
+        }
+        target = document.getElementById("lessToggle");
+        target.style.display = "inline";
+    }
+}
+function toggleLess(targetId) {
+    if (document.getElementById) {
+        var id = targetId + count;
+        target = document.getElementById(id);
+        target.style.display = "none";
+        field = document.getElementById("uploadFile" + count);
+        field.value = "";
+        count--;
+        if (count == 0) {
+           target = document.getElementById("lessToggle");
+           target.style.display = "none";
+        }
+        target = document.getElementById("moreToggle");
+        target.style.display = "inline";
+   } 
+   fileChanged();
+}
+function fileChanged() {
+   disabled = true;
+   for (i=0; i<=9; i++) {
+      field = document.getElementById("uploadFile" + i);
+      if (!isblank(field.value)) {
+         disabled = false;
+         break;
+      }
+   }
+   document.forms[0].submitButton.disabled = disabled;
+}
+-->
+</script>
+
 <p class="subtitle">
     <fmt:message key="uploadFiles.subtitle" >
         <fmt:param value="${model.website.handle}" />
@@ -16,6 +65,12 @@
 <p class="pagetip">
     <fmt:message key="uploadFiles.tip" />
 </p>
+<p class="pagetip">
+<fmt:message key="uploadFiles.quotaNote">
+   <fmt:param value="${model.maxFileMB}" />
+   <fmt:param value="${model.maxDirMB}" />
+</fmt:message>
+</p>
 
 <%-- --------------------------
 File upload form, but only if it's enabled and weblog is under quota
@@ -34,16 +89,65 @@
            "uploadFiles", null, null, null, new Hashtable(), null, false); %>
         <form name="uploadFiles" method="post" action="<%= edit %>" enctype="multipart/form-data">
             <br />
-            <input type="file" name="uploadedFile" size="30" />
-            &nbsp;
-            <input type="submit" value='<%= bundle.getString("uploadFiles.upload")
%>' />
+            
+            <input type="file" name="uploadedFile0" id="uploadFile0" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" value="" /><br />
+              
+            <div id="fileControl1" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile1" id="uploadFile1" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>                     
+            
+            <div id="fileControl2" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile2" id="uploadFile2" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>                     
+            
+            <div id="fileControl3" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile3" id="uploadFile3" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>                     
+            
+            <div id="fileControl4" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile4" id="uploadFile4" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>      
+               
+            <div id="fileControl5" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile5" id="uploadFile5" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>      
+               
+            <div id="fileControl6" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile6" id="uploadFile6" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>      
+               
+            <div id="fileControl7" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile7" id="uploadFile7" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>      
+               
+            <div id="fileControl8" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile8" id="uploadFile8" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>      
+               
+            <div id="fileControl9" class="miscControl" style="display:none">
+                <input type="file" name="uploadedFile9" id="uploadFile9" size="30" onchange="fileChanged()"
onkeyup="fileChanged()" /><br />
+            </div>          
+               
+            <div id="lessToggle" style="display:none; float:left;">
+                <a onclick="javascript:toggleLess('fileControl')">
+                   <img src='<c:url value="/images/delete.png"/>' style="padding:4px"
title="Add file to upload list" />
+                </a>
+            </div>
+            <div id="moreToggle" style="display:inline; float:left">
+                <a onclick="javascript:toggleMore('fileControl')">
+                    <img src='<c:url value="/images/add.png"/>' style="padding:4px"
title="Remove last from upload list" />
+                </a>
+            </div>
+         
+            <br />
+            <br />
+            
+            <input name="submitButton" type="submit" value='<%= bundle.getString("uploadFiles.upload")
%>' disabled="true" />
             <input type="hidden" name="method" value="upload" />
             <input type="hidden" name="weblog" value='<%= model.getWebsite().getHandle()
%>'>
             <br />
-            <fmt:message key="uploadFiles.quotaNote">
-               <fmt:param value="${model.maxFileMB}" />
-               <fmt:param value="${model.maxDirMB}" />
-            </fmt:message>
+            <br />
+            
         </form>
     </c:otherwise>
 </c:choose>
@@ -66,7 +170,10 @@
         <c:forEach var="loopfile" items="${model.files}" >
            <roller:row oddStyleClass="rollertable_odd" evenStyleClass="rollertable_even">
                 <td class="rollertable">
-                    <a href='<c:out value="${model.resourcesBaseURL}" />/<c:out
value="${loopfile.name}" />'><c:out value="${loopfile.name}" /></a>
+                    <img src='<c:url value="/images/image.png"/>' style="padding:0px"
/>
+                    <a href='<c:out value="${model.resourcesBaseURL}" />/<c:out
value="${loopfile.name}" />'>
+                        <c:out value="${loopfile.name}" />
+                    </a>
                 </td>
                 <td class="rollertable" align="right">
                     <fmt:formatNumber value="${loopfile.length / 1024}" type="number"
maxFractionDigits="2" />&nbsp;KB



Mime
View raw message