public
Description: modified version of java jupload
Clone URL: git://github.com/bmo/jupload.git
Callbacks for progress working
bmo (author)
Mon Jun 23 09:32:53 -0700 2008
commit  d997259b39ea5ff15c5f312a84416d15cbcc5870
tree    db889a889db3620c26314df9751d057d63b3a422
parent  34af26efd2355dc8ca7d73fbba92e3ce3dd6ab06
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@
0
 # ANY CHANGES WILL BE OVERWRITTEN BY THE BUILD-PROCESS!
0
 
0
 # Date of the compilation
0
-buildDate = 06/13/2008 04:35 PM
0
+buildDate = 06/21/2008 08:02 AM
0
 
0
 #Last revision commited. This compilation may contain other uncommitted changes.
0
 revision = 477
...
263
264
265
 
 
 
266
267
268
...
263
264
265
266
267
268
269
270
271
0
@@ -263,6 +263,9 @@ public class JUploadApplet extends Applet {
0
     public String cancelUpload() {
0
         return this.jsHandler.doCommand(JavascriptHandler.COMMAND_CANCEL_UPLOAD);
0
     }
0
+ public String cancelUpload(String fileId) {
0
+ return this.jsHandler.doCommand(JavascriptHandler.COMMAND_CANCEL_UPLOAD,fileId);
0
+ }
0
     /**
0
      * example public method that can be called by Javascript to get overall status
0
      *
...
241
242
243
244
 
245
246
247
248
 
249
250
251
...
265
266
267
268
269
270
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
273
274
...
241
242
243
 
244
245
246
247
 
248
249
250
251
...
265
266
267
 
 
 
 
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
0
@@ -241,11 +241,11 @@ public class JavascriptHandler extends Thread {
0
                           if (args[0] instanceof String) {
0
                             uploadPolicy.displayDebug(
0
                                 "Argument is "+args[0], 50);
0
- //jUploadPanel.doStartUploadSingle((String) args[0]);
0
+ jUploadPanel.doStartUpload();
0
                           } else if (args[0] instanceof Integer){
0
                             uploadPolicy.displayDebug(
0
                                 "Argument is an int"+ args[0].toString(), 50);
0
- //jUploadPanel.doStartUploadSingle((Integer) args[0]);
0
+ jUploadPanel.doStartUpload(); //jUploadPanel.doStartUploadSingle((Integer) args[0]);
0
                           }
0
                         } else {
0
                           jUploadPanel.doStartUpload(); //
0
@@ -265,10 +265,22 @@ public class JavascriptHandler extends Thread {
0
                         notified=true;
0
                         doNotify(); // don't wait -
0
                         uploadPolicy.displayDebug(
0
- "run(): Calling doCancelUpload()", 50);
0
- jUploadPanel.doStopUpload();
0
- //jUploadPanel.doStopUpload();
0
- this.jsResponse = "ASYNC";
0
+ "run(): Calling doCancelUpload()", 50);
0
+ if (args.length>0 && (args[0]!=null)) {
0
+ // do single upload of a particular file
0
+ if (args[0] instanceof String) {
0
+ uploadPolicy.displayDebug(
0
+ "Argument is "+args[0], 50);
0
+ jUploadPanel.getFilePanel().removeFilebByExternalId(args[0].toString());
0
+ } else {
0
+ uploadPolicy.displayDebug(
0
+ "Bad Argument ", 50);
0
+ }
0
+
0
+ } else {
0
+ jUploadPanel.getFilePanel().removeFilebByExternalId(null); //
0
+ this.jsResponse=null;
0
+ }
0
                     }
0
                     if (curCommand.equals(COMMAND_GET_STATS)) {
0
                       String gsj = uploadPolicy.getStatsJSON();
...
303
304
305
306
 
 
307
308
309
...
356
357
358
 
 
359
360
361
362
363
364
365
 
366
367
368
...
303
304
305
 
306
307
308
309
310
...
357
358
359
360
361
362
363
364
365
366
367
 
368
369
370
371
0
@@ -303,7 +303,8 @@ public class DefaultFileData implements FileData {
0
                 this.uploadPolicy.displayWarn("uploadError callback - CMD - "
0
                     + cmd_string);
0
                 try {
0
- String[] args = { this.getJSON(), error_code.toString(), message };
0
+
0
+ String[] args = { this.getJSON(), error_code.toString(), '"'+message+'"' };
0
                   this.uploadPolicy.performCallback(cmd_string,args,true); // instance call
0
                 } catch (JUploadException e) {
0
                     this.uploadPolicy.displayErr(e);
0
@@ -356,13 +357,15 @@ public class DefaultFileData implements FileData {
0
    */
0
   public String getJSON() {
0
     String json_obj;
0
+ String reldir = this.getRelativeDir().replaceAll("\\\\", "/");
0
+ // normalize to forward slash...
0
     /* TODO creation_date, modification_date, filestatus */
0
     json_obj = "{ id : '" + this.ext_id + "', " +
0
             " index : " + this.ext_index + ", " +
0
             " name : '" + this.getFileName() + "'," +
0
             " size : " + this.fileSize + "," +
0
             " type : '" + this.getFileExtension() + "'," +
0
- " relative_path : '" + this.getRelativeDir()+ "'," +
0
+ " relative_path : '" + reldir + "'," +
0
             " filestatus : "+ this.status +
0
             " } ";
0
     return json_obj;
...
62
63
64
 
 
65
66
67
...
62
63
64
65
66
67
68
69
0
@@ -62,6 +62,8 @@ public interface FilePanel {
0
      */
0
     public void removeSelected();
0
 
0
+ public FileData removeFilebByExternalId(String fid);
0
+
0
     /**
0
      * Removes all file entries.
0
      */
...
307
308
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
311
312
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
0
@@ -307,6 +307,28 @@ class FilePanelDataModel2 extends AbstractTableModel {
0
             }
0
         }
0
     }
0
+ public synchronized FileData removeFilebByExternalId(String fid) {
0
+ FileData fd;
0
+ Iterator<FileData> i = this.rows.iterator();
0
+ FileData item;
0
+ if (null==fid && i.hasNext()) {
0
+ item = i.next();
0
+ this.rows.removeElement(item);
0
+ fireTableDataChanged();
0
+ return item;
0
+ }
0
+
0
+ while (i.hasNext()) {
0
+ item = i.next();
0
+ if (item.external_id()==fid) {
0
+ this.rows.removeElement(item);
0
+ fireTableDataChanged();
0
+ break;
0
+ }
0
+ }
0
+ return null;
0
+ }
0
+
0
 
0
     /** @see javax.swing.table.TableModel#getColumnCount() */
0
     public int getColumnCount() {
...
34
35
36
 
37
38
39
...
52
53
54
55
 
56
57
58
...
66
67
68
 
69
70
71
...
98
99
100
101
 
 
102
103
104
...
129
130
131
132
 
133
134
135
...
168
169
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
172
173
...
34
35
36
37
38
39
40
...
53
54
55
 
56
57
58
59
...
67
68
69
70
71
72
73
...
100
101
102
 
103
104
105
106
107
...
132
133
134
 
135
136
137
138
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
0
@@ -34,6 +34,7 @@ import wjhk.jupload2.exception.JUploadExceptionStopAddingFiles;
0
 import wjhk.jupload2.filedata.FileData;
0
 import wjhk.jupload2.policies.UploadPolicy;
0
 
0
+
0
 /**
0
  * Implementation of the FilePanel : it creates the
0
  * {@link wjhk.jupload2.gui.FilePanelJTable}, and handles the necessary
0
@@ -52,7 +53,7 @@ public class FilePanelTableImp extends Panel implements FilePanel {
0
     private FilePanelJTable jtable;
0
 
0
     private FilePanelDataModel2 model;
0
-
0
+ private UploadPolicy uploadPolicy;
0
     /**
0
      * Creates a new instance.
0
      *
0
@@ -66,6 +67,7 @@ public class FilePanelTableImp extends Panel implements FilePanel {
0
         this.jtable = new FilePanelJTable(jup, uploadPolicy);
0
 
0
         this.model = new FilePanelDataModel2(uploadPolicy);
0
+ this.uploadPolicy = uploadPolicy;
0
         this.jtable.setModel(this.model);
0
 
0
         TableColumnModel colModel = this.jtable.getColumnModel();
0
@@ -98,7 +100,8 @@ public class FilePanelTableImp extends Panel implements FilePanel {
0
         } else {
0
             File[] dirFiles = f.listFiles();
0
             for (int i = 0; i < dirFiles.length; i++) {
0
- if (dirFiles[i].isDirectory()) {
0
+ if (dirFiles[i].isDirectory() ) { //# TODO FILTER OUT directories to ignore here...
0
+ if (this.uploadPolicy.directoryFilterAccept(dirFiles[i])) // only add if the file directory is OK too...
0
                     addDirectoryFiles(dirFiles[i], root);
0
                 } else {
0
                     addFileOnly(dirFiles[i], root);
0
@@ -129,7 +132,7 @@ public class FilePanelTableImp extends Panel implements FilePanel {
0
     return this.model.getFilebByExternalId(fid);
0
   }
0
   
0
- public FileData getFileByExternalIndex(Integer index) {
0
+ public FileData getFileByExternalIndex(Integer index) {
0
     return this.model.getFileByExternalIndex(index);
0
   }
0
     /**
0
@@ -168,6 +171,36 @@ public class FilePanelTableImp extends Panel implements FilePanel {
0
     public final void remove(FileData fileData) {
0
         this.model.removeRow(fileData);
0
     }
0
+ /* removes the file with the given fid, *OR* the first one */
0
+ /* does nothing about the file being uploaded at the time. */
0
+
0
+ public FileData removeFilebByExternalId(String fid) {
0
+ FileData fd;
0
+ if (null==fid) {
0
+ fd=this.model.getFileDataAt(0);
0
+ this.model.removeRow(0);
0
+ return fd;
0
+ }
0
+ for (int i = getFilesLength() - 1; 0 <= i; i--) {
0
+ fd = this.model.getFileDataAt(i);
0
+ if (fid.equals(fd.external_id())) {
0
+ this.model.removeRow(i);
0
+ return fd;
0
+ }
0
+ }
0
+ return null;
0
+ }
0
+ public FileData removeFilebByExternalIndex(Integer index) {
0
+ for (int i = getFilesLength() - 1; 0 <= i; i--) {
0
+ FileData fd = this.model.getFileDataAt(i);
0
+ if (index == fd.external_index()) {
0
+ this.model.removeRow(i);
0
+ return fd;
0
+ }
0
+ }
0
+ return null;
0
+ }
0
+
0
 
0
     /**
0
      * Clear the current selection in the JTable.
...
143
144
145
 
 
 
 
 
146
147
148
...
275
276
277
278
279
 
 
280
281
282
...
462
463
464
 
 
465
466
467
...
699
700
701
702
703
704
 
 
 
705
706
707
708
709
710
711
 
712
713
714
...
1389
1390
1391
 
 
1392
1393
1394
...
1487
1488
1489
1490
1491
 
 
1492
1493
1494
1495
1496
1497
1498
1499
1500
...
1521
1522
1523
 
 
 
 
 
 
 
1524
1525
1526
...
2143
2144
2145
2146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2147
2148
2149
...
2154
2155
2156
2157
2158
 
 
 
2159
2160
2161
...
2176
2177
2178
2179
2180
2181
 
 
 
 
 
 
2182
2183
 
2184
2185
2186
...
143
144
145
146
147
148
149
150
151
152
153
...
280
281
282
 
 
283
284
285
286
287
...
467
468
469
470
471
472
473
474
...
706
707
708
 
 
 
709
710
711
712
713
714
715
716
717
 
718
719
720
721
...
1396
1397
1398
1399
1400
1401
1402
1403
...
1496
1497
1498
 
 
1499
1500
1501
1502
 
 
 
 
1503
1504
1505
...
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
...
2155
2156
2157
 
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
...
2184
2185
2186
 
 
2187
2188
2189
2190
2191
2192
...
2207
2208
2209
 
 
 
2210
2211
2212
2213
2214
2215
2216
 
2217
2218
2219
2220
0
@@ -143,6 +143,11 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
     private String allowedFileExtensions = UploadPolicy.DEFAULT_ALLOWED_FILE_EXTENSIONS;
0
 
0
     /**
0
+ * Contains the allowedFileExtensions applet parameter.
0
+ */
0
+ private String ignoredDirectoryRegex = UploadPolicy.DEFAULT_IGNORED_DIRECTORY_REGEX;
0
+
0
+ /**
0
      * Indicate whether the log window is shown or not to the user. In all cases
0
      * it remains in memory, and stores all debug information. This allows a log
0
      * information, in case of an error occurs.
0
@@ -275,8 +280,8 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
     private int upload_cancelled=0; // The number of files that have been cancelled
0
     private int queue_errors=0; // The number of files that caused fileQueueError to be fired
0
 
0
-
0
- private String javascriptInstanceName = "JUpload.instances['jupload_0']"; // TODO - change this to Null, and make it be set.
0
+ private String javascriptInstancePrefix = "JUpload.instances"; //
0
+
0
 
0
     // //////////////////////////////////////////////////////////////////////////////////////////////
0
     // /////////////////// INTERNAL ATTRIBUTE
0
@@ -462,6 +467,8 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
                 this));
0
         setFilenameFormvarName(UploadPolicyFactory.getParameter(theApplet,PROP_FORM_VAR_NAME, null,
0
                 this));
0
+ setIgnoreDirectoryRegex(UploadPolicyFactory.getParameter(theApplet, PROP_IGNORE_DIRECTORY_REGEX, null,
0
+ this));
0
 
0
         // get the filenameEncoding. If not null, it should be a valid argument
0
         // for the URLEncoder.encode method.
0
@@ -699,16 +706,16 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
                   }
0
                 }
0
                 
0
- //if ( args.length==0) {s_args = "null";} else {s_args = "["+s_args+"]";}
0
- if (use_instance && (null!=this.javascriptInstanceName)){ // Do instance call, JUpload.instances['jupload_0'].function.apply(JUpload.instances['jupload_0'],args)
0
- instanced_function = this.javascriptInstanceName+"."+function+"("+s_args+")";
0
+
0
+ if (use_instance && (null!=this.applet.getParameter("NAME"))){ // Do instance call, JUpload.instances['jupload_0'].function.apply(JUpload.instances['jupload_0'],args)
0
+ instanced_function = this.javascriptInstancePrefix+"[\""+this.applet.getParameter("NAME")+"\"]."+function+"("+s_args+")";
0
                   // turn into function.apply(JUpload['jupload_0'],(args))
0
                 } else { // do a class call, like JUpload.JUploadReady.apply(JUpload.instances['jupload_0'],null)
0
                   //instanced_function = function+".apply("+this.javascriptInstanceName+","+s_args+")";
0
                   instanced_function = function+"("+s_args+")";
0
                 }
0
                 // A JavaScript expression was specified. Execute it.
0
- displayWarn("performCallback with "+instanced_function);
0
+ displayDebug("performCallback with "+instanced_function,20);
0
                 return_val = JSObject.getWindow(getApplet()).eval(instanced_function);
0
                 return return_val;
0
             } catch (Exception ee) {
0
@@ -1389,6 +1396,8 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
                 + getAllowHttpPersistent(), 20);
0
         displayDebug(PROP_ALLOWED_FILE_EXTENSIONS + ": "
0
                 + getAllowedFileExtensions(), 20);
0
+ displayDebug(PROP_IGNORE_DIRECTORY_REGEX + ": "
0
+ + getIgnoreDirectoryRegex(), 20);
0
         displayDebug(PROP_DEBUG_LEVEL + ": " + this.debugLevel
0
                 + " (debugfile: " + debugFile.getAbsolutePath() + ")", 1);
0
         displayDebug(PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT + ": "
0
@@ -1487,14 +1496,10 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
     return (String) s_callbacks.get(property_name);
0
   }
0
 
0
- public String getJavascripInstanceName() {
0
- return this.javascriptInstanceName;
0
+ public String getJavascriptInstanceName() {
0
+ return this.applet.getParameter("NAME");
0
   }
0
   
0
- public void setJavascripInstanceName(String the_name) {
0
- this.javascriptInstanceName=the_name;
0
- }
0
-
0
   public void setFilenamePrefix(String prefix){
0
        this.filenamePrefix = prefix;
0
     }
0
@@ -1521,6 +1526,13 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
     public boolean getAllowHttpPersistent() {
0
         return this.allowHttpPersistent;
0
     }
0
+ protected void setIgnoreDirectoryRegex(String ignoreDirectoryRegex) {
0
+ this.ignoredDirectoryRegex=ignoreDirectoryRegex;
0
+ }
0
+
0
+ protected String getIgnoreDirectoryRegex() {
0
+ return this.ignoredDirectoryRegex;
0
+ }
0
 
0
     /** @see UploadPolicy#getAllowedFileExtensions() */
0
     public String getAllowedFileExtensions() {
0
@@ -2143,7 +2155,25 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
     public JUploadFileChooser createFileChooser() {
0
         return new JUploadFileChooser(this);
0
     }
0
-
0
+ /**
0
+ * This method returns the response for the
0
+ * {@link JUploadFileFilter#accept(File)} which just calls this method. This
0
+ * method checks that the file isn't excluded by the ignoreDirectoryRegex
0
+ * applet parameter.
0
+ *
0
+ * @see UploadPolicy#fileFilterAccept(File)
0
+ */
0
+ public boolean directoryFilterAccept(File file) {
0
+ if (file.isDirectory()) {
0
+ //
0
+ displayDebug("Directory filter directory: " + file.getName()+"\n regex: "+this.ignoredDirectoryRegex, 10);
0
+ if (this.ignoredDirectoryRegex.length()>0 && file.getName().matches(this.ignoredDirectoryRegex)){
0
+ displayDebug("Ignored", 10);
0
+ return false;
0
+ }
0
+ }
0
+ return true;
0
+ }
0
     /**
0
      * This method returns the response for the
0
      * {@link JUploadFileFilter#accept(File)} which just calls this method. This
0
@@ -2154,8 +2184,9 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
      */
0
     public boolean fileFilterAccept(File file) {
0
         if (file.isDirectory()) {
0
- return true;
0
- } else if (this.allowedFileExtensions == null
0
+ return directoryFilterAccept(file);
0
+ }
0
+ else if (this.allowedFileExtensions == null
0
                 || this.allowedFileExtensions.equals("")) {
0
             return true;
0
         } else {
0
@@ -2176,11 +2207,14 @@ public class DefaultUploadPolicy implements UploadPolicy {
0
 
0
     /** @see UploadPolicy#fileFilterGetDescription() */
0
     public String fileFilterGetDescription() {
0
- if (this.allowedFileExtensions == null
0
- || this.allowedFileExtensions.equals(""))
0
- return null;
0
+ String fileFilterDesc =
0
+ (this.allowedFileExtensions == null
0
+ || this.allowedFileExtensions.equals("") ? "" : "JUpload file filter (" + this.allowedFileExtensions + ")");
0
+
0
+ String directoryFilterDesc = (this.ignoredDirectoryRegex == null
0
+ || this.ignoredDirectoryRegex.equals("") ? "" : "JUpload directory filter ignore (" + this.ignoredDirectoryRegex + ")");
0
 
0
- return "JUpload file filter (" + this.allowedFileExtensions + ")";
0
+ return fileFilterDesc+" "+directoryFilterDesc;
0
     }
0
 
0
     /**
...
858
859
860
 
 
861
862
863
864
865
 
 
 
 
866
867
868
...
1013
1014
1015
 
 
 
 
 
1016
1017
1018
...
1329
1330
1331
1332
 
1333
1334
1335
...
1636
1637
1638
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1639
1640
1641
...
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
...
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
...
1340
1341
1342
 
1343
1344
1345
1346
...
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
0
@@ -858,11 +858,17 @@ public interface UploadPolicy {
0
      */
0
 
0
     public final static String PROP_FORM_VAR_NAME = "form_var_name";
0
+
0
+
0
     /**
0
      * Parameter/Property name for specifying high quality previews.
0
      */
0
     public final static String PROP_HIGH_QUALITY_PREVIEW = "highQualityPreview";
0
 
0
+ /**
0
+ * Parameter/Property name for specifying the regex for IGNORED directories, for example .svn
0
+ */
0
+ public final static String PROP_IGNORE_DIRECTORY_REGEX = "ignoreDirectoryRegex";
0
     /**
0
      * Parameter/Property name for specifying the UI language
0
      */
0
@@ -1013,6 +1019,11 @@ public interface UploadPolicy {
0
      */
0
     public final static String DEFAULT_ALLOWED_FILE_EXTENSIONS = "";
0
 
0
+ /**
0
+ * Default value for parameter "ignoredDirectoryRegex".
0
+ */
0
+ public final static String DEFAULT_IGNORED_DIRECTORY_REGEX = "";
0
+
0
     /**
0
      * Default value for parameter "albumId".
0
      */
0
@@ -1329,7 +1340,7 @@ public interface UploadPolicy {
0
      *
0
      * @return The current value for the specified callback.
0
      */
0
- public String getJavascripInstanceName();
0
+ public String getJavascriptInstanceName();
0
    
0
     /**
0
      * Retrieves the current value for allowHttpPersistent
0
@@ -1636,6 +1647,22 @@ public interface UploadPolicy {
0
      */
0
     public boolean fileFilterAccept(File file);
0
 
0
+ /**
0
+ * This methods is called by the {@link JUploadFileFilter#accept(File)}. It
0
+ * allows the current upload policy to filter directories, according to any
0
+ * choosen applet behaviour. This filter applied WHEN USING THE FILE CHOOSER *AND*
0
+ * when directories are being swept for files. Files dropped onto the applet won't trigger this function.<br>
0
+ * In the {@link DefaultUploadPolicy} upload policy, this filter is based on
0
+ * the applet parameter: <i>ignoreDirectoryRegex</i>.
0
+ *
0
+ * @param file file (directory) to test
0
+ * @return true or false, whether the file (directory) is accepted or not.
0
+ *
0
+ * @see JUploadPanel#JUploadPanel(java.awt.Container,
0
+ * wjhk.jupload2.gui.JUploadTextArea, UploadPolicy)
0
+ */
0
+ public boolean directoryFilterAccept(File file);
0
+
0
     /**
0
      * Return a description for the FileFilter, according to the current upload
0
      * policy.

Comments

    No one has commented yet.