Changeset 3008
- Timestamp:
- Dec 7, 2006, 2:52:12 PM (16 years ago)
- Location:
- branches/2.1.2
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.1.2/src/clients/web/net/sf/basedb/clients/web/fileupload/FileUpload.java
r3003 r3008 65 65 arrive. 66 66 */ 67 public static final long DEFAULT_TIMEOUT = 20000;67 public static final long DEFAULT_TIMEOUT = 60000; 68 68 69 69 private static final String EMPTY_STRING = ""; … … 108 108 /** 109 109 The timeout in milliseconds that we wait for more data to arrive. 110 Default value is 20000 = 20 seconds.110 Default value is 60000 = 60 seconds. 111 111 */ 112 112 private long timeout = DEFAULT_TIMEOUT; … … 636 636 try 637 637 { 638 if (debugEnabled) log.debug("Calling in.readLine() for more data");639 638 bytes = in.readLine(b, off, len); 640 if (debugEnabled) log.debug("Got " + bytes + " bytes");641 639 gotData = true; 642 640 } … … 648 646 { 649 647 SocketTimeoutException ex2 = 650 new SocketTimeoutException("No data for " + waitTime + " milliseconds");648 new SocketTimeoutException("No data for " + (waitTime / 1000) + " seconds"); 651 649 ex2.initCause(ex); 652 log.debug("Total timeout exceeded after " + waitTime + "ms", ex2);650 log.debug("Total timeout exceeded after " + waitTime + "ms", ex2); 653 651 throw ex2; 654 652 } -
branches/2.1.2/src/clients/web/net/sf/basedb/clients/web/fileupload/FileUploadProgress.java
r2691 r3008 24 24 package net.sf.basedb.clients.web.fileupload; 25 25 26 import java.util.Date;27 28 import net.sf.basedb.core.ProgressReporter;29 30 26 /** 31 27 Objects of this class holds information about the progress … … 43 39 */ 44 40 public class FileUploadProgress 45 implements ProgressReporter46 41 { 47 42 private final long totalBytes; 48 43 private final long startTime; 49 private final Date lastTransfer;50 44 private long transferredBytes; 51 45 private String currentFilename; 52 46 private Throwable exception; 53 47 private boolean abort = false; 54 private boolean unpacking = false;55 private int percent = 0;56 private String message = null;57 48 58 49 /** … … 68 59 this.totalBytes = totalBytes; 69 60 this.startTime = System.currentTimeMillis(); 70 this.lastTransfer = new Date();71 61 this.transferredBytes = 0; 72 62 } 73 74 /*75 From the ProgressReporter interface76 -------------------------------------------77 */78 public void display(int percent, String message)79 {80 this.unpacking = percent < 100;81 this.message = message;82 this.percent = percent;83 }84 85 public void append(String message)86 {87 this.message += message;88 }89 // -------------------------------------------90 63 91 64 /** … … 113 86 { 114 87 transferredBytes = bytes; 115 lastTransfer.setTime(System.currentTimeMillis());116 88 } 117 89 /** … … 122 94 { 123 95 transferredBytes += bytes; 124 lastTransfer.setTime(System.currentTimeMillis());125 96 } 126 97 127 98 /** 128 99 Checks if the transfer is complete or not. A transfer is complete 129 when the transferred bytes equals the total bytes and when optional 130 unpacking of a zip file has been completed. 100 when the transferred bytes equals the total bytes. 131 101 @return TRUE if the transfer has been completed, FALSE otherwise 132 102 */ 133 103 public boolean transferIsComplete() 134 104 { 135 return (getTotalBytes() == getTransferredBytes() && !unpacking);105 return (getTotalBytes() == getTransferredBytes()); 136 106 } 137 107 … … 179 149 180 150 /** 181 Get the data and time for the last update to this object.182 This value is used by the a {@link FileUpload} object183 to decide when to remove old progress information from the cache.184 @return The data and time of the last update to this object.185 */186 Date getLastTransfer()187 {188 return lastTransfer;189 }190 191 /**192 151 Request that the upload should be aborted. The associated {@link 193 152 FileUpload} object will check this property at regular intervals and if set -
branches/2.1.2/src/core/net/sf/basedb/util/zip/ZipUnpacker.java
r2691 r3008 40 40 import net.sf.basedb.core.Path; 41 41 import net.sf.basedb.util.FileUtil; 42 import net.sf.basedb.util.Values; 42 43 43 44 /** … … 101 102 { 102 103 progress.displayAbsolute(totalUnpacked, 103 "Unpacking " + (isDirectory ? "directory: " : "file: ") + completePath); 104 "Unpacking " + (isDirectory ? "directory: " : "file: ") + completePath + 105 " (" +Values.formatBytes(entry.getSize()) + ")"); 104 106 } 105 107 if (!isDirectory) -
branches/2.1.2/www/filemanager/upload/index.jsp
r2753 r3008 34 34 @version 2.0 35 35 --%> 36 <%@ page 36 <%@ page session="false" 37 37 import="net.sf.basedb.core.SessionControl" 38 38 import="net.sf.basedb.core.DbControl" … … 52 52 int directoryId = Values.getInt(request.getParameter("directory_id")); 53 53 int fileId = Values.getInt(request.getParameter("file_id")); 54 String thePage = "select.jsp"; 55 FileUploadProgress progress = (FileUploadProgress)sc.getSessionSetting("FileUploadProgress"); 56 if (progress != null && !progress.transferIsComplete() && progress.getException() == null) 57 { 58 thePage = "progress.jsp"; 59 } 60 else 61 { 62 sc.setSessionSetting("FileUploadProgress", null); 63 } 54 sc.setSessionSetting("FileUploadProgress", null); 55 sc.setSessionSetting("UnpackProgress", null); 64 56 %> 65 57 66 58 <base:page type="frameset" title="Upload file"> 67 59 <base:head /> 68 <frameset rows="*,0 " frameborder="no" border="0">69 <frame name=" progress" src="<%=thePage%>?ID=<%=ID%>&directory_id=<%=directoryId%>&file_id=<%=fileId%>"60 <frameset rows="*,0,0" frameborder="yes" border="1"> 61 <frame name="select" src="select.jsp?ID=<%=ID%>&directory_id=<%=directoryId%>&file_id=<%=fileId%>" 70 62 scrolling="no" frameborder="0"> 63 <frame name="progress" scrolling="no" frameborder="0"> 71 64 <frame name="upload" scrolling="no" frameborder="0"> 72 65 </frameset> -
branches/2.1.2/www/filemanager/upload/progress.jsp
r2753 r3008 35 35 @version 2.0 36 36 --%> 37 <%@ page 37 <%@ page session="false" 38 38 import="net.sf.basedb.core.SessionControl" 39 import="net.sf.basedb.core.Simple ProgressReporter"39 import="net.sf.basedb.core.SimpleAbsoluteProgressReporter" 40 40 import="net.sf.basedb.clients.web.Base" 41 41 import="net.sf.basedb.util.Values" … … 51 51 final boolean abort = Values.getBoolean(request.getParameter("abort")); 52 52 final FileUploadProgress progress = (FileUploadProgress)sc.getSessionSetting("FileUploadProgress"); 53 final SimpleProgressReporter unpackProgress = (SimpleProgressReporter)sc.getSessionSetting("UnpackProgress"); 53 final SimpleAbsoluteProgressReporter unpackProgress = (SimpleAbsoluteProgressReporter)sc.getSessionSetting("UnpackProgress"); 54 54 55 boolean aborted = false; 55 if (progress != null) 56 { 57 if (abort) progress.setAbort(); 58 Throwable t = progress.getException(); 59 if (t != null) 60 { 61 if (t instanceof UploadAbortedException) 62 { 63 aborted = true; 64 } 65 else 66 { 67 throw progress.getException(); 68 } 69 } 70 } 56 boolean transferIsComplete = false; 71 57 long total = 0; 72 58 long transferred = 0; 73 boolean transferIsComplete = false;74 59 long seconds = 0; 75 60 long transferRate = 0; … … 77 62 String currentFileName = ""; 78 63 long percent = 0; 64 String unpackMessage = ""; 79 65 if (progress != null) 80 66 { 81 currentFileName = "Uploading " + progress.getCurrentFilename(); 67 if (abort) progress.setAbort(); 68 currentFileName = progress.getCurrentFilename(); 82 69 total = progress.getTotalBytes(); 83 70 transferred = progress.getTransferredBytes(); … … 87 74 remain = transferRate != 0 ? (total-transferred)/transferRate : 0; 88 75 percent = (total==0 ? 0 : 100 * transferred / total); 76 aborted = progress.getException() != null || abort; 89 77 } 90 final String onload = transferIsComplete ? "xdone();" : aborted ? null : "setTimeout('location.reload()', 1500);"; 78 if (unpackProgress != null) 79 { 80 unpackMessage = unpackProgress.getMessage(); 81 } 82 83 String onload = ""; 91 84 if (transferIsComplete) 92 85 { 86 onload = "displayProgress(true)"; 93 87 sc.setSessionSetting("FileUploadProgress", null); 88 sc.setSessionSetting("UnpackProgress", null); 89 } 90 else if (aborted) 91 { 92 onload = "uploadAborted()"; 93 } 94 else if (progress != null) 95 { 96 onload = "displayProgress(false)"; 97 } 98 else 99 { 100 onload = "setTimeout('location.reload()', 1500)"; 94 101 } 95 102 %> 96 <base:page type="popup" title="Uploading file..."> 97 <base:head styles="progressbar.css"> 98 <script language="JavaScript"> 99 function done() 103 <html> 104 <head> 105 </head> 106 <body onload="<%=onload%>"> 107 <script language="javascript"> 108 function displayProgress(isComplete) 100 109 { 101 var message = '<%=HTML.urlEncode(aborted ? "Upload aborted" : "File uploaded successfully")%>'; 102 location.href = getRoot()+'common/close_popup.jsp?refresh_opener=1&message='+(message); 103 } 104 function abortUpload() 105 { 106 if (confirm('Are you sure you want to abort the upload? It cannot be resumed.')) 110 var fileName = '<%=HTML.javaScriptEncode(currentFileName)%>'; 111 var percentDone = '<%=percent%>'; 112 var transferredBytes = '<%=Values.formatBytes(transferred)%>'; 113 var totalBytes = '<%=Values.formatBytes(total)%>'; 114 var transferTime = '<%=Values.formatTime(seconds)%>'; 115 var transferRate = '<%=Values.formatBytes(transferRate)%>/s'; 116 var remainTime = '<%=Values.formatTime(remain)%>'; 117 var unpackMessage = '<%=HTML.javaScriptEncode(unpackMessage)%>'; 118 window.top.frames['select'].displayProgress(fileName, percentDone, transferredBytes, totalBytes, transferTime, transferRate, remainTime, unpackMessage); 119 if (!isComplete) 107 120 { 108 location.href = 'progress.jsp?ID=<%=ID%>&abort=1';121 setTimeout('location.reload()', 1500); 109 122 } 110 123 } 111 <% 112 if (abort && progress == null) 124 function displayException() 113 125 { 114 %> 115 top.window.close(); 116 <% 126 window.top.frames['select'].location = 'show_exception.jsp?ID=<%=ID%>'; 117 127 } 118 %> 128 function uploadAborted() 129 { 130 window.top.location = '../../common/close_popup.jsp?refresh_opener=1&message=<%=HTML.urlEncode("The upload was aborted before it was completed.")%>'; 131 } 119 132 </script> 120 </base:head> 121 <base:body onload="<%=onload%>" > 122 123 <% 124 if (aborted) 125 { 126 %> 127 <base:note type="info" title="Upload aborted"> 128 The upload was aborted before it was completed. 129 </base:note> 130 <table align="center"> 131 <tr> 132 <td><base:button onclick="window.top.close()" title="Close" /></td> 133 </tr> 134 </table> 135 <% 136 } 137 else 138 { 139 %> 140 <h3 class="docked"><%=currentFileName%>...</h3> 141 <div class="boxed" style="background: #E0E0E0"> 142 <br> 143 <table width="90%" border=0 cellspacing=0 cellpadding=0 align="center"> 144 <tr> 145 <td width="90%" > 146 <table width="100%" class="progressbar" border=0 cellspacing=0 cellpadding=0> 147 <tr> 148 <% 149 if (percent > 0) 150 { 151 %> 152 <td width="<%=percent%>%" class="done"> </td> 153 <% 154 } 155 if (percent < 100) 156 { 157 %> 158 <td width="<%=100-percent%>%" class="remain"> </td> 159 <% 160 } 161 %> 162 </tr> 163 </table> 164 </td> 165 <td width="10%"> <%=percent%>%</td> 166 </tr> 167 <tr> 168 <td colspan="2"> 169 <% 170 if (progress == null) 171 { 172 %> 173 Waiting for transfer to begin... 174 <% 175 } 176 else 177 { 178 %> 179 <b>Transferred:</b> <%=Values.formatBytes(transferred)%> of <%=Values.formatBytes(total)%><br> 180 <b>Time:</b> <%=Values.formatTime(seconds)%> (<%=Values.formatBytes(transferRate)%>/s)<br> 181 <b>Remain:</b> <%=Values.formatTime(remain)%> (estimated)<br> 182 <% 183 if (unpackProgress != null) 184 { 185 %> 186 <b><%=unpackProgress.getMessage()%></b> 187 <% 188 } 189 } 190 %> 191 </td> 192 </tr> 193 </table> 194 <br> 195 </div> 196 <br> 197 <table align="center"> 198 <tr> 199 <td><base:button image="cancel.gif" onclick="abortUpload()" title="Abort..." /></td> 200 </tr> 201 </table> 202 <% 203 } 204 %> 205 </base:body> 206 </base:page> 133 </body> 134 </html> -
branches/2.1.2/www/filemanager/upload/select.jsp
r2753 r3008 26 26 @version 2.0 27 27 --%> 28 <%@ page 28 <%@ page session="false" 29 29 import="net.sf.basedb.core.SessionControl" 30 30 import="net.sf.basedb.core.DbControl" … … 118 118 119 119 <base:page type="popup" title="<%=title%>"> 120 <base:head scripts="tabcontrol.js" styles="tabcontrol.css ">120 <base:head scripts="tabcontrol.js" styles="tabcontrol.css,progressbar.css"> 121 121 <script language="JavaScript"> 122 122 // Validate the "File" tab … … 149 149 150 150 frm.submit(); 151 this.location.href = "progress.jsp?ID=<%=ID%>"; 152 } 153 } 151 window.top.frames['progress'].location.href = 'progress.jsp?ID=<%=ID%>'; 152 Main.hide('selectForm'); 153 Main.show('progressForm'); 154 } 155 } 156 157 function abortUpload() 158 { 159 if (confirm('Are you sure you want to abort the upload? It cannot be resumed.')) 160 { 161 window.top.frames['progress'].location.href = 'progress.jsp?ID=<%=ID%>&abort=1'; 162 } 163 } 164 154 165 function fileOnChange() 155 166 { … … 199 210 } 200 211 %> 212 } 213 214 function displayProgress(fileName, percentDone, transferredBytes, totalBytes, transferTime, transferRate, remainTime, unpackMessage) 215 { 216 document.getElementById('fileName').innerHTML = 'Uploading ' + fileName + '...'; 217 document.getElementById('percent').innerHTML = ' ' + percentDone+'%'; 218 var doneElement = document.getElementById('percentDone'); 219 doneElement.style.width = percentDone+'%'; 220 var remainElement = document.getElementById('percentRemain'); 221 remainElement.style.width = (100-percentDone)+'%'; 222 if (percentDone == 100) Main.hide('percentRemain'); 223 document.getElementById('transferredBytes').innerHTML = transferredBytes; 224 document.getElementById('totalBytes').innerHTML = totalBytes; 225 document.getElementById('transferTime').innerHTML = transferTime; 226 document.getElementById('transferRate').innerHTML = '(' + transferRate + ')'; 227 document.getElementById('remainTime').innerHTML = remainTime + ' (estimated)'; 228 document.getElementById('unpackMessage').innerHTML = unpackMessage.replace(/(.*):(.*)/, '<b>$1:</b> $2'); 201 229 } 202 230 … … 246 274 return s; 247 275 } 248 249 } 250 251 276 } 252 277 253 278 </script> 254 279 </base:head> 255 280 <base:body onload="initZipFormats()"> 256 257 281 <p> 282 <div id="selectForm"> 258 283 <form action="upload.jsp?ID=<%=ID%>&directory_id=<%=directory.getId()%>" 259 284 method="post" name="file" enctype="multipart/form-data" onsubmit="return false;" target="upload"> … … 387 412 </table> 388 413 </form> 414 </div> 415 416 <div id="progressForm" style="display:none;"> 417 <h3 class="docked" id="fileName">Preparing file upload...</h3> 418 <div class="boxed" style="background: #E0E0E0"> 419 <br> 420 <table width="90%" border=0 cellspacing=0 cellpadding=0 align="center"> 421 <tr> 422 <td width="90%" > 423 <table width="100%" class="progressbar" border=0 cellspacing=0 cellpadding=0> 424 <tr> 425 <td width="0%" class="done" id="percentDone"> </td> 426 <td width="100%" class="remain" id="percentRemain"> </td> 427 </tr> 428 </table> 429 </td> 430 <td width="10%" id="percent"> 0%</td> 431 </tr> 432 <tr> 433 <td colspan="2"> 434 <b>Transferred:</b> <span id="transferredBytes">0 bytes</span> of <span id="totalBytes">unknown</span><br> 435 <b>Time:</b> <span id="transferTime">0s</span> <span id="transferRate"></span><br> 436 <b>Remain:</b> <span id="remainTime">unknown</span><br> 437 <span id="unpackMessage"></span> 438 </td> 439 </tr> 440 </table> 441 <br> 442 </div> 443 <br> 444 <table align="center"> 445 <tr> 446 <td><base:button image="cancel.gif" onclick="abortUpload()" title="Abort..." /></td> 447 </tr> 448 </table> 449 450 </div> 389 451 </base:body> 390 452 </base:page> -
branches/2.1.2/www/filemanager/upload/upload.jsp
r3003 r3008 31 31 @version 2.0 32 32 --%> 33 <%@ page 33 <%@ page session="false" 34 34 import="net.sf.basedb.core.SessionControl" 35 35 import="net.sf.basedb.core.DbControl" … … 68 68 final int directoryId = Values.getInt(request.getParameter("directory_id"), SystemItems.getId(Directory.ROOT)); 69 69 final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); 70 71 70 String message = null; 71 String onload = ""; 72 72 DbControl dc = null; 73 73 FileUpload upload = null; … … 193 193 } 194 194 dc.commit(); 195 dc.close();196 195 message = unpackZip ? numUnpackedFiles + " file(s) unpacked successfully" : "File uploaded successfully"; 196 onload="done()"; 197 197 } 198 198 catch (Throwable t) 199 199 { 200 200 if (upload != null) upload.setException(t); 201 throw t; 201 if (t instanceof UploadAbortedException) 202 { 203 message = "The upload was aborted before it was completed."; 204 onload="done()"; 205 } 206 else 207 { 208 onload = "exception()"; 209 } 202 210 } 203 211 finally … … 205 213 if (dc != null) dc.close(); 206 214 } 207 208 215 %> 209 < base:page type="popup">210 < base:head>216 <html> 217 <head> 211 218 <script language="JavaScript"> 212 219 function done() 213 220 { 214 window.top.location = getRoot() + 'common/close_popup.jsp?refresh_opener=1&message=<%=HTML.urlEncode(message)%>'; 221 window.top.location = '../../common/close_popup.jsp?refresh_opener=1&message=<%=HTML.urlEncode(message)%>'; 222 } 223 function exception() 224 { 225 window.top.frames['select'].location = 'show_exception.jsp?ID=<%=ID%>'; 215 226 } 216 227 </script> 217 </base:head> 218 <base:body onload="done()"> 219 </base:body> 220 </base:page> 221 222 228 </head> 229 <body onload="<%=onload%>"> 230 </body> 231 </html> 232 233 234
Note: See TracChangeset
for help on using the changeset viewer.