1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package wjhk.jupload2.policies;
23
24 import java.awt.BorderLayout;
25 import java.awt.Cursor;
26 import java.awt.GridLayout;
27 import java.awt.SystemColor;
28 import java.awt.dnd.DropTargetDropEvent;
29 import java.io.BufferedReader;
30 import java.io.ByteArrayOutputStream;
31 import java.io.File;
32 import java.io.FileOutputStream;
33 import java.io.FileReader;
34 import java.io.IOException;
35 import java.io.InputStream;
36 import java.io.PrintStream;
37 import java.io.UnsupportedEncodingException;
38 import java.net.MalformedURLException;
39 import java.net.URL;
40 import java.net.URLEncoder;
41 import java.nio.charset.Charset;
42 import java.nio.charset.UnsupportedCharsetException;
43 import java.util.IllegalFormatException;
44 import java.util.Iterator;
45 import java.util.Locale;
46 import java.util.ResourceBundle;
47 import java.util.Vector;
48 import java.util.regex.Matcher;
49 import java.util.regex.Pattern;
50 import java.util.regex.PatternSyntaxException;
51
52 import javax.swing.BorderFactory;
53 import javax.swing.BoxLayout;
54 import javax.swing.Icon;
55 import javax.swing.JButton;
56 import javax.swing.JLabel;
57 import javax.swing.JOptionPane;
58 import javax.swing.JPanel;
59 import javax.swing.JProgressBar;
60 import javax.swing.UIManager;
61 import javax.swing.UnsupportedLookAndFeelException;
62 import javax.swing.border.BevelBorder;
63
64 import wjhk.jupload2.context.JUploadContext;
65 import wjhk.jupload2.exception.JUploadException;
66 import wjhk.jupload2.exception.JUploadExceptionStopAddingFiles;
67 import wjhk.jupload2.exception.JUploadExceptionUploadFailed;
68 import wjhk.jupload2.exception.JUploadExceptionUploadFailedSuccessNotFound;
69 import wjhk.jupload2.exception.JUploadIOException;
70 import wjhk.jupload2.filedata.DefaultFileData;
71 import wjhk.jupload2.filedata.FileData;
72 import wjhk.jupload2.gui.JUploadFileChooser;
73 import wjhk.jupload2.gui.JUploadFileFilter;
74 import wjhk.jupload2.gui.JUploadPanel;
75 import wjhk.jupload2.gui.filepanel.FilePanel.FileListViewMode;
76 import wjhk.jupload2.upload.helper.ByteArrayEncoder;
77 import wjhk.jupload2.upload.helper.ByteArrayEncoderHTTP;
78 import wjhk.jupload2.upload.helper.HTTPConnectionHelper;
79 import wjhk.jupload2.upload.helper.HttpProtocolFinderThread;
80 import wjhk.jupload2.upload.helper.InteractiveTrustManager;
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 public class DefaultUploadPolicy implements UploadPolicy {
107
108
109
110
111 public final static int DIALOG_MESSAGE_MAX_LINE_LENGTH = 80;
112
113
114
115
116
117
118
119
120
121
122
123
124
125 JUploadContext juploadContext = null;
126
127
128
129
130
131 private String afterUploadURL = UploadPolicy.DEFAULT_AFTER_UPLOAD_URL;
132
133
134
135
136 private boolean allowHttpPersistent = UploadPolicy.DEFAULT_ALLOW_HTTP_PERSISTENT;
137
138
139
140
141 private String allowedFileExtensions = UploadPolicy.DEFAULT_ALLOWED_FILE_EXTENSIONS;
142
143
144
145
146
147
148
149 private String showLogWindow = UploadPolicy.DEFAULT_SHOW_LOGWINDOW;
150
151 private boolean showStatusbar = UploadPolicy.DEFAULT_SHOW_STATUSBAR;
152
153 private String specificHeaders = null;
154
155
156 private File currentBrowsingDirectory = null;
157
158
159
160
161
162 private boolean debugGenerateFile = true;
163
164
165
166
167 private int debugLevel = UploadPolicy.DEFAULT_DEBUG_LEVEL;
168
169
170
171
172
173
174 private int fileChooserIconFromFileContent = UploadPolicy.DEFAULT_FILE_CHOOSER_ICON_FROM_FILE_CONTENT;
175
176
177
178
179
180
181 private int fileChooserIconSize = UploadPolicy.DEFAULT_FILE_CHOOSER_ICON_SIZE;
182
183
184 private String fileFilterName = UploadPolicy.DEFAULT_FILE_FILTER_NAME;
185
186
187 private FileListViewMode fileListViewMode = UploadPolicy.DEFAULT_FILE_LIST_VIEW_MODE;
188
189
190
191
192
193 private String filenameEncoding = UploadPolicy.DEFAULT_FILENAME_ENCODING;
194
195
196
197
198 private boolean ftpCreateDirectoryStructure = UploadPolicy.DEFAULT_FTP_CREATE_DIRECTORY_STRUCTURE;
199
200
201
202
203 private boolean ftpTransfertBinary = UploadPolicy.DEFAULT_FTP_TRANSFERT_BINARY;
204
205
206
207
208 private boolean ftpTransfertPassive = UploadPolicy.DEFAULT_FTP_TRANSFERT_PASSIVE;
209
210
211 protected String httpUploadParameterName = UploadPolicy.DEFAULT_HTTP_UPLOAD_PARAMETER_NAME;
212
213
214 protected String httpUploadParameterType = UploadPolicy.DEFAULT_HTTP_UPLOAD_PARAMETER_TYPE;
215
216
217
218
219 private String lang = UploadPolicy.DEFAULT_LANG;
220
221
222
223
224 private Locale locale = Locale.getDefault();
225
226
227
228
229
230
231 private JUploadException lastException = null;
232
233
234
235
236
237 private String lookAndFeel = UploadPolicy.DEFAULT_LOOK_AND_FEEL;
238
239
240
241
242
243
244 private int nbFilesPerRequest = UploadPolicy.DEFAULT_NB_FILES_PER_REQUEST;
245
246
247
248
249
250 private long maxChunkSize = UploadPolicy.DEFAULT_MAX_CHUNK_SIZE;
251
252
253
254
255
256 private long maxFileSize = UploadPolicy.DEFAULT_MAX_FILE_SIZE;
257
258
259
260
261
262 private String postURL = UploadPolicy.DEFAULT_POST_URL;
263
264
265 private boolean readCookieFromNavigator = UploadPolicy.DEFAULT_READ_COOKIE_FROM_NAVIGATOR;
266
267
268 private boolean readUserAgentFromNavigator = UploadPolicy.DEFAULT_READ_USER_AGENT_FROM_NAVIGATOR;
269
270
271 private int retryMaxNumberOf = UploadPolicy.DEFAULT_RETRY_MAX_NUMBER_OF;
272
273
274 private int retryNbSecondsBetween = UploadPolicy.DEFAULT_RETRY_NB_SECONDS_BETWEEN;
275
276
277 private boolean sendMD5Sum = UploadPolicy.DEFAULT_SEND_MD5_SUM;
278
279
280 private String serverProtocol = UploadPolicy.DEFAULT_SERVER_PROTOCOL;
281
282
283
284
285 private String stringUploadError = UploadPolicy.DEFAULT_STRING_UPLOAD_ERROR;
286
287
288
289
290 private String stringUploadSuccess = UploadPolicy.DEFAULT_STRING_UPLOAD_SUCCESS;
291
292
293
294
295 private String stringUploadWarning = UploadPolicy.DEFAULT_STRING_UPLOAD_WARNING;
296
297
298
299
300
301
302
303
304 private String urlToSendErrorTo = UploadPolicy.DEFAULT_URL_TO_SEND_ERROR_TO;
305
306
307
308
309 private String formData = UploadPolicy.DEFAULT_FORMDATA;
310
311 private String afterUploadTarget = UploadPolicy.DEFAULT_AFTER_UPLOAD_TARGET;
312
313 private String lastResponseBody = null;
314
315 protected String lastResponseMessage = null;
316
317 private int sslVerifyCert = InteractiveTrustManager.NONE;
318
319 private final String CRLF = System.getProperty("line.separator");
320
321
322
323
324
325
326
327
328
329
330
331 private Vector<String> headers = new Vector<String>();
332
333
334
335
336 private ResourceBundle resourceBundle = null;
337
338
339
340
341
342 protected PrintStream debugOut = null;
343
344
345
346
347
348
349 protected File debugFile = null;
350
351
352
353
354 protected boolean debugOk = true;
355
356
357
358
359
360
361 protected Pattern patternError = Pattern.compile(UploadPolicy.DEFAULT_STRING_UPLOAD_ERROR);
362
363
364
365
366
367 protected Pattern patternSuccess = Pattern.compile(UploadPolicy.DEFAULT_STRING_UPLOAD_SUCCESS);
368
369
370
371
372
373 protected Pattern patternWarning = Pattern.compile(UploadPolicy.DEFAULT_STRING_UPLOAD_WARNING);
374
375
376
377
378
379
380
381
382
383
384
385
386
387 public DefaultUploadPolicy(JUploadContext juploadContext) throws JUploadException {
388
389 this.juploadContext = juploadContext;
390 displayInfo("JUpload juploadContext started, with " + this.getClass().getName() + " upload policy");
391
392
393
394
395
396 setDebugLevel(juploadContext.getParameter(PROP_DEBUG_LEVEL, DEFAULT_DEBUG_LEVEL), false);
397
398
399
400 setLang(juploadContext.getParameter(PROP_LANG, DEFAULT_LANG));
401
402
403
404
405
406 setLookAndFeel(juploadContext.getParameter(PROP_LOOK_AND_FEEL, DEFAULT_LOOK_AND_FEEL));
407
408
409
410 setSslVerifyCert(juploadContext.getParameter(PROP_SSL_VERIFY_CERT, DEFAULT_SSL_VERIFY_CERT));
411
412
413 setAfterUploadURL(juploadContext.getParameter(PROP_AFTER_UPLOAD_URL, DEFAULT_AFTER_UPLOAD_URL));
414
415
416 setFtpCreateDirectoryStructure(juploadContext.getParameter(PROP_FTP_CREATE_DIRECTORY_STRUCTURE,
417 DEFAULT_FTP_CREATE_DIRECTORY_STRUCTURE));
418
419 setFtpTransfertBinary(juploadContext.getParameter(PROP_FTP_TRANSFERT_BINARY, DEFAULT_FTP_TRANSFERT_BINARY));
420
421 setFtpTransfertPassive(juploadContext.getParameter(PROP_FTP_TRANSFERT_PASSIVE, DEFAULT_FTP_TRANSFERT_PASSIVE));
422
423
424 setAllowedFileExtensions(juploadContext.getParameter(PROP_ALLOWED_FILE_EXTENSIONS,
425 DEFAULT_ALLOWED_FILE_EXTENSIONS));
426 setFileFilterName(juploadContext.getParameter(PROP_FILE_FILTER_NAME, DEFAULT_FILE_FILTER_NAME));
427 setFileListViewMode(juploadContext.getParameter(PROP_FILE_LIST_VIEW_MODE, DEFAULT_FILE_LIST_VIEW_MODE));
428
429 setAllowHttpPersistent(juploadContext.getParameter(PROP_ALLOW_HTTP_PERSISTENT, DEFAULT_ALLOW_HTTP_PERSISTENT));
430
431 setShowStatusbar(juploadContext.getParameter(PROP_SHOW_STATUSBAR, DEFAULT_SHOW_STATUSBAR));
432
433 setShowLogWindow(juploadContext.getParameter(PROP_SHOW_LOGWINDOW, DEFAULT_SHOW_LOGWINDOW));
434
435
436 setFileChooserIconFromFileContent(juploadContext.getParameter(PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT,
437 DEFAULT_FILE_CHOOSER_ICON_FROM_FILE_CONTENT));
438 setFileChooserIconSize(juploadContext.getParameter(PROP_FILE_CHOOSER_ICON_SIZE, DEFAULT_FILE_CHOOSER_ICON_SIZE));
439 setCurrentBrowsingDirectory(juploadContext.getParameter(PROP_BROWSING_DIRECTORY, DEFAULT_BROWSING_DIRECTORY));
440
441
442 setFilenameEncoding(juploadContext.getParameter(PROP_FILENAME_ENCODING, DEFAULT_FILENAME_ENCODING));
443
444
445 setNbFilesPerRequest(juploadContext.getParameter(PROP_NB_FILES_PER_REQUEST, DEFAULT_NB_FILES_PER_REQUEST));
446 setHttpUploadParameterName(juploadContext.getParameter(PROP_HTTP_UPLOAD_PARAMETER_NAME,
447 DEFAULT_HTTP_UPLOAD_PARAMETER_NAME));
448 setHttpUploadParameterType(juploadContext.getParameter(PROP_HTTP_UPLOAD_PARAMETER_TYPE,
449 DEFAULT_HTTP_UPLOAD_PARAMETER_TYPE));
450
451
452 setMaxChunkSize(juploadContext.getParameter(PROP_MAX_CHUNK_SIZE, DEFAULT_MAX_CHUNK_SIZE));
453
454 setMaxFileSize(juploadContext.getParameter(PROP_MAX_FILE_SIZE, DEFAULT_MAX_FILE_SIZE));
455
456 setRetryMaxNumberOf(juploadContext.getParameter(PROP_RETRY_MAX_NUMBER_OF, DEFAULT_RETRY_MAX_NUMBER_OF));
457 setRetryNbSecondsBetween(juploadContext.getParameter(PROP_RETRY_NB_SECONDS_BETWEEN,
458 DEFAULT_RETRY_NB_SECONDS_BETWEEN));
459
460
461 setPostURL(juploadContext.getParameter(PROP_POST_URL, DEFAULT_POST_URL));
462
463
464 setReadCookieFromNavigator(juploadContext.getParameter(PROP_READ_COOKIE_FROM_NAVIGATOR,
465 DEFAULT_READ_COOKIE_FROM_NAVIGATOR));
466 setReadUserAgentFromNavigator(juploadContext.getParameter(PROP_READ_USER_AGENT_FROM_NAVIGATOR,
467 DEFAULT_READ_USER_AGENT_FROM_NAVIGATOR));
468 setSendMD5Sum(juploadContext.getParameter(PROP_SEND_MD5_SUM, DEFAULT_SEND_MD5_SUM));
469 setSpecificHeaders(juploadContext.getParameter(PROP_SPECIFIC_HEADERS, DEFAULT_SPECIFIC_HEADERS));
470 setStringUploadError(juploadContext.getParameter(PROP_STRING_UPLOAD_ERROR, DEFAULT_STRING_UPLOAD_ERROR));
471 setStringUploadSuccess(juploadContext.getParameter(PROP_STRING_UPLOAD_SUCCESS, DEFAULT_STRING_UPLOAD_SUCCESS));
472 setStringUploadWarning(juploadContext.getParameter(PROP_STRING_UPLOAD_WARNING, DEFAULT_STRING_UPLOAD_WARNING));
473
474
475
476 setUrlToSendErrorTo(juploadContext.getParameter(PROP_URL_TO_SEND_ERROR_TO, DEFAULT_URL_TO_SEND_ERROR_TO));
477 this.formData = juploadContext.getParameter(PROP_FORMDATA, DEFAULT_FORMDATA);
478 this.afterUploadTarget = juploadContext.getParameter(PROP_AFTER_UPLOAD_TARGET, DEFAULT_AFTER_UPLOAD_TARGET);
479
480
481
482
483 displayDebug("[DefaultUploadPolicy] end of constructor (serverProtocol has not been set)", 30);
484 }
485
486
487
488
489
490
491 public void start() {
492
493 if (getReadCookieFromNavigator()) {
494 this.juploadContext.readCookieFromNavigator(this.headers);
495 }
496 if (getReadUserAgentFromNavigator()) {
497 this.juploadContext.readUserAgentFromNavigator(this.headers);
498 }
499
500
501
502
503
504
505
506
507
508 HttpProtocolFinderThread.computeServerProtocol(this,
509 juploadContext.getParameter(PROP_SERVER_PROTOCOL, (String) null));
510 }
511
512
513
514
515
516
517 public void addHeader(String header) {
518 this.headers.add(header);
519 }
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538 public boolean checkUploadSuccess(int status, String msg, String body) throws JUploadException {
539 boolean bReturn = false;
540
541 if (getDebugLevel() > 100) {
542
543
544 try {
545 Thread.sleep(300);
546 } catch (InterruptedException e) {
547 }
548 }
549
550 this.lastResponseBody = body;
551 this.lastResponseMessage = msg;
552 displayDebug("HTTP status: " + msg, 30);
553
554 if ((status != 200) && (status != 100))
555 throw new JUploadExceptionUploadFailed("Received HTTP status " + msg);
556
557
558
559
560 if (status == 100)
561 return true;
562
563
564
565
566 Matcher matcherError, matcherWarning;
567 String line;
568 Pattern p = Pattern.compile("[\\r\\n]", Pattern.MULTILINE);
569 String[] lines = p.split(body);
570 StringBuffer sbBodyWithUniformCRLF = new StringBuffer(body.length());
571 for (int i = 0; i < lines.length; i += 1) {
572 line = lines[i];
573 sbBodyWithUniformCRLF.append(line).append("\r\n");
574
575
576
577
578 if (line == null || line.equals("")) {
579
580 continue;
581 }
582
583
584
585 if (getStringUploadSuccess() != null && !getStringUploadSuccess().equals("")) {
586 if (this.patternSuccess.matcher(line).matches()) {
587
588 bReturn = true;
589 }
590 }
591
592
593 if (getStringUploadError() != null && !getStringUploadError().equals("")) {
594 matcherError = this.patternError.matcher(line);
595 if (matcherError.matches()) {
596 String errmsg = "An error occurs during upload (but the applet couldn't find the error message)";
597 if (matcherError.groupCount() > 0) {
598 if (!matcherError.group(1).equals("")) {
599
600
601 errmsg = formatMessage(matcherError.group(1));
602 }
603 }
604 this.lastResponseMessage = errmsg;
605 throw new JUploadExceptionUploadFailed(errmsg);
606 }
607 }
608
609
610 if (getStringUploadWarning() != null && !getStringUploadWarning().equals("")) {
611 matcherWarning = this.patternWarning.matcher(line);
612 if (matcherWarning.matches()) {
613 String warnmsg = "A warning occurs during upload (but the applet couldn't find the warning message)";
614 if (matcherWarning.groupCount() > 0) {
615 if (!matcherWarning.group(1).equals("")) {
616 warnmsg = formatMessage(matcherWarning.group(1));
617 }
618 }
619 this.lastResponseMessage = warnmsg;
620 displayWarn(warnmsg);
621 alertStr(warnmsg);
622 }
623 }
624
625 }
626
627 if (bReturn) {
628 return true;
629 }
630
631
632 if (getStringUploadSuccess() == null || getStringUploadSuccess().equals("")) {
633
634 return true;
635 }
636
637
638
639
640
641 throw new JUploadExceptionUploadFailedSuccessNotFound(getClass().getName()
642 + ".checkUploadSuccess(): The regexp string \"" + getStringUploadSuccess()
643 + "\" was not found in the response body");
644 }
645
646
647
648
649
650
651
652
653 protected String formatMessage(String msg) {
654 StringBuffer sbMsg = new StringBuffer();
655 String[] lines = msg.split("\\\\n");
656 for (int i = 0; i < lines.length; i += 1) {
657
658 String line = lines[i];
659 for (int j = 0, remaining = line.length(); remaining > 0; remaining -= DIALOG_MESSAGE_MAX_LINE_LENGTH, j += 1) {
660 if (remaining <= DIALOG_MESSAGE_MAX_LINE_LENGTH) {
661
662 sbMsg.append(line.substring(j * DIALOG_MESSAGE_MAX_LINE_LENGTH));
663 } else {
664 sbMsg.append(line.substring(j * DIALOG_MESSAGE_MAX_LINE_LENGTH, (j + 1)
665 * DIALOG_MESSAGE_MAX_LINE_LENGTH));
666 sbMsg.append("\n");
667 }
668 }
669
670 if (i < lines.length - 1) {
671 sbMsg.append("\n");
672 }
673 }
674
675 return sbMsg.toString();
676 }
677
678
679
680
681 public void afterUpload(Exception e, String serverOutput) throws JUploadException {
682
683
684 String url = getAfterUploadURL();
685 if (url != null) {
686 this.juploadContext.displayURL(url, e == null);
687 }
688 }
689
690
691 public void alertStr(String str) {
692 String str2 = str.replaceAll("\\\\n", "\n");
693 JOptionPane.showMessageDialog(null, str2, "Alert", JOptionPane.WARNING_MESSAGE);
694 }
695
696
697 public int confirmDialogStr(String str, int optionTypes) {
698 String str2 = str.replaceAll("\\\\n", "\n");
699 return JOptionPane.showConfirmDialog(getContext().getUploadPanel().getJComponent().getParent(), str2, "Alert",
700 optionTypes);
701 }
702
703
704 public void alert(String key) {
705 alertStr(getLocalizedString(key));
706 }
707
708
709
710
711
712
713
714
715
716 public FileData createFileData(File file) throws JUploadExceptionStopAddingFiles {
717 if (!fileFilterAccept(file)) {
718 String msg = file.getName() + " : " + getLocalizedString("errForbiddenExtension");
719 displayWarn(msg);
720 if (confirmDialogStr(msg, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
721
722
723
724 throw new JUploadExceptionStopAddingFiles("Stopped by the user");
725 }
726 return null;
727 } else if (!file.canRead()) {
728 displayInfo("Can't read file " + file.getName() + ". No DefaultFileData creation.");
729 return null;
730 } else {
731 return new DefaultFileData(file, this);
732 }
733 }
734
735
736
737
738
739
740
741
742 public JPanel createTopPanel(JButton browse, JButton remove, JButton removeAll, JUploadPanel jUploadPanel) {
743 JPanel jPanel = new JPanel();
744
745 jPanel.setLayout(new GridLayout(1, 3, 10, 5));
746 jPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
747 jPanel.add(browse);
748 jPanel.add(removeAll);
749 jPanel.add(remove);
750
751 jUploadPanel.getJComponent().setBorder(BorderFactory.createLineBorder(SystemColor.controlDkShadow));
752
753 return jPanel;
754 }
755
756
757
758
759
760 public JPanel createProgressPanel(JProgressBar preparationProgressBar, JProgressBar uploadProgressBar,
761 JButton uploadButton, JButton stopButton, JUploadPanel mainPanel) {
762
763
764
765 JPanel jProgressBarPanel = new JPanel();
766 jProgressBarPanel.setLayout(new BorderLayout(10, 1));
767 jProgressBarPanel.add(preparationProgressBar, BorderLayout.NORTH);
768 jProgressBarPanel.add(uploadProgressBar, BorderLayout.SOUTH);
769
770 JPanel jProgressPanel = new JPanel();
771 jProgressPanel.setLayout(new BorderLayout(10, 0));
772 jProgressPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
773 jProgressPanel.add(uploadButton, BorderLayout.LINE_START);
774 jProgressPanel.add(jProgressBarPanel, BorderLayout.CENTER);
775 jProgressPanel.add(stopButton, BorderLayout.LINE_END);
776 return jProgressPanel;
777 }
778
779
780
781
782 public JPanel createStatusBar(JLabel content, JUploadPanel mainPanel) {
783 if (this.showStatusbar) {
784 JPanel pstatus = new JPanel();
785 pstatus.setLayout(new BorderLayout());
786 pstatus.add(content, BorderLayout.CENTER);
787 pstatus.setBorder(new BevelBorder(BevelBorder.LOWERED));
788 return pstatus;
789 }
790 return null;
791 }
792
793
794
795
796
797
798 public void addComponentsToJUploadPanel(JUploadPanel jUploadPanel) {
799
800 jUploadPanel.getJComponent().setLayout(new BoxLayout(jUploadPanel.getJComponent(), BoxLayout.Y_AXIS));
801
802
803
804
805 JPanel topPanel = createTopPanel(jUploadPanel.getBrowseButton(), jUploadPanel.getRemoveButton(),
806 jUploadPanel.getRemoveAllButton(), jUploadPanel);
807 if (topPanel != null) {
808 jUploadPanel.getJComponent().add(topPanel);
809 topPanel.addMouseListener(jUploadPanel.getMouseListener());
810 }
811
812
813 jUploadPanel.getJComponent().add(jUploadPanel.getFilePanel().getDropComponent());
814
815
816
817 JPanel progressPanel = createProgressPanel(jUploadPanel.getPreparationProgressBar(),
818 jUploadPanel.getUploadProgressBar(), jUploadPanel.getUploadButton(), jUploadPanel.getStopButton(),
819 jUploadPanel);
820 jUploadPanel.getJComponent().add(progressPanel);
821 jUploadPanel.getJComponent().addMouseListener(jUploadPanel.getMouseListener());
822
823
824 jUploadPanel.showOrHideLogWindow();
825 jUploadPanel.getJComponent().add(jUploadPanel.getJLogWindowPane());
826
827
828 JPanel p = createStatusBar(jUploadPanel.getStatusLabel(), jUploadPanel);
829 if (null != p) {
830 jUploadPanel.getJComponent().add(p);
831 p.addMouseListener(jUploadPanel.getMouseListener());
832 }
833 }
834
835
836 public void updateButtonState(int executionStatus) {
837
838 if (executionStatus != UploadPolicy.EXEC_STATUS_READY && executionStatus != UploadPolicy.EXEC_STATUS_UPLOADING) {
839 throw new java.lang.IllegalArgumentException("Unknow value for executionStatus: " + executionStatus);
840 }
841
842
843 }
844
845
846 public void displayErr(Exception e) {
847 displayErr(e.getMessage(), e);
848 }
849
850
851 public void displayErr(String err) {
852 displayErr(err, null);
853 }
854
855
856
857
858
859
860 private void displayStackTrace(Throwable throwable) {
861 if (throwable != null) {
862 ByteArrayOutputStream bs = new ByteArrayOutputStream();
863 PrintStream ps = new PrintStream(bs);
864 throwable.printStackTrace(ps);
865 ps.close();
866 displayMsg("", bs.toString());
867
868
869 if (throwable.getCause() != null) {
870 displayMsg("", "Caused by:");
871 displayStackTrace(throwable.getCause());
872 }
873 }
874 }
875
876
877
878
879
880
881
882 private void logErr(String errorText, Exception exception) {
883 if (exception == null) {
884 setLastException(new JUploadException("errorText"));
885 } else if (exception instanceof JUploadException) {
886 setLastException((JUploadException) exception);
887 } else {
888 setLastException(new JUploadException(exception));
889 }
890
891
892
893
894 if (getDebugLevel() == 0)
895 setDebugLevel(1);
896
897 String exceptionMsg = null;
898 String exceptionClassName = null;
899 String logMsg = errorText;
900
901
902 if (exception == null) {
903 exceptionClassName = "";
904 } else if (exception instanceof JUploadException) {
905 exceptionClassName = "[" + ((JUploadException) exception).getClassNameAndClause() + "] ";
906 } else {
907 exceptionClassName = "[" + exception.getClass().getName() + "] ";
908 }
909
910
911 if (exception != null) {
912
913 if (exception.getCause() != null) {
914 exceptionMsg = exception.getCause().getMessage();
915 } else {
916 exceptionMsg = exception.getMessage();
917 }
918 logMsg = exceptionMsg + " (" + errorText + ")";
919 }
920
921
922 displayMsg("[ERROR]", exceptionClassName + logMsg);
923
924 displayStackTrace(exception);
925
926
927
928 if (this.juploadContext.getUploadPanel() != null && getDebugLevel() >= 99) {
929
930 this.juploadContext.getUploadPanel().copyLogWindow();
931 alert("messageLogWindowCopiedToClipboard");
932 }
933
934 }
935
936
937
938
939
940
941
942
943 public int displayErr(String errorText, Exception exception, int optionTypes) {
944
945 String alertMsg = errorText;
946
947 if (exception != null && (errorText == null || errorText.equals(""))) {
948
949 if (exception.getCause() != null) {
950 alertMsg = exception.getCause().getMessage();
951 } else {
952 alertMsg = exception.getMessage();
953 }
954 }
955
956
957 if (getDebugLevel() >= 30 && exception != null) {
958 alertMsg = exception.getClass().getName() + ": " + alertMsg;
959 }
960
961
962
963 int buttonClicked = 0;
964 switch (optionTypes) {
965 case -1:
966
967 alertStr(alertMsg);
968 buttonClicked = JOptionPane.OK_OPTION;
969 break;
970 case JOptionPane.OK_CANCEL_OPTION:
971 case JOptionPane.YES_NO_CANCEL_OPTION:
972 case JOptionPane.YES_NO_OPTION:
973 buttonClicked = confirmDialogStr(alertMsg, optionTypes);
974 break;
975 default:
976
977
978 alertStr(alertMsg);
979 buttonClicked = JOptionPane.OK_OPTION;
980
981 String msg = "Unknown optionType in displayErr(String, Exception, int)";
982 alertStr(msg);
983 logErr(msg, null);
984 }
985
986
987 logErr(errorText, exception);
988
989 return buttonClicked;
990 }
991
992
993
994
995
996
997
998
999 public void displayErr(String errorText, Exception exception) {
1000 displayErr(errorText, exception, -1);
1001 }
1002
1003
1004
1005
1006 public void displayInfo(String info) {
1007 displayMsg("[INFO]", info);
1008 }
1009
1010
1011
1012
1013 public void displayWarn(String warn) {
1014 displayMsg("[WARN]", warn);
1015 }
1016
1017
1018
1019
1020 public void displayDebug(String debug, int minDebugLevel) {
1021 final String tag = "[DEBUG]";
1022 if (this.debugLevel >= minDebugLevel) {
1023
1024 displayMsg(tag, debug);
1025 } else if (this.debugGenerateFile) {
1026
1027
1028 addMsgToDebugLog(tag + debug);
1029 }
1030 }
1031
1032
1033 public String getLocalizedString(String key, Object... args) {
1034 String ret = this.resourceBundle.getString(key);
1035 try {
1036
1037 switch (args.length) {
1038 case 0:
1039 return String.format(ret);
1040 case 1:
1041 return String.format(ret, args[0]);
1042 case 2:
1043 return String.format(ret, args[0], args[1]);
1044 case 3:
1045 return String.format(ret, args[0], args[1], args[2]);
1046 case 4:
1047 return String.format(ret, args[0], args[1], args[2], args[3]);
1048 case 5:
1049 return String.format(ret, args[0], args[1], args[2], args[3], args[4]);
1050 case 6:
1051 return String.format(ret, args[0], args[1], args[2], args[3], args[4], args[5]);
1052 case 7:
1053 return String.format(ret, args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
1054 default:
1055 throw new IllegalArgumentException(
1056 "DefaultUploadPolicy.getLocalizedString accepts up to 7 variable parameters ("
1057 + args.length + " values were given for the 'args' argument");
1058 }
1059 } catch (IllegalFormatException ife) {
1060 displayErr(ife.getClass().getName() + " (" + ife.getMessage() + ")when managing this string: " + ret);
1061 throw ife;
1062 }
1063 }
1064
1065
1066
1067
1068 public String getUploadFilename(FileData fileData, int index) throws JUploadException {
1069 return getEncodedFilename(fileData.getFileName());
1070 }
1071
1072
1073
1074
1075
1076
1077
1078
1079 protected final String getEncodedFilename(String filename) throws JUploadException {
1080 if (this.filenameEncoding == null || this.filenameEncoding.equals("")) {
1081 return filename;
1082 }
1083 try {
1084 return URLEncoder.encode(filename, this.filenameEncoding);
1085 } catch (UnsupportedEncodingException e) {
1086 throw new JUploadException(e);
1087 }
1088 }
1089
1090
1091 public String getUploadName(FileData fileData, int index) throws JUploadException {
1092 if (this.httpUploadParameterType.equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ARRAY)) {
1093 return this.httpUploadParameterName + "[]";
1094 } else if (this.httpUploadParameterType.equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ITERATION)) {
1095 return this.httpUploadParameterName + index;
1096 } else if (this.httpUploadParameterType.equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ONE_FILE)) {
1097
1098 if (getNbFilesPerRequest() == 1) {
1099 return this.httpUploadParameterName;
1100 } else {
1101 throw new JUploadException(UploadPolicy.PROP_HTTP_UPLOAD_PARAMETER_TYPE + " value '"
1102 + this.httpUploadParameterType + "' is only valid when '"
1103 + UploadPolicy.PROP_NB_FILES_PER_REQUEST + " is 1.");
1104 }
1105 } else {
1106 throw new JUploadException(UploadPolicy.PROP_HTTP_UPLOAD_PARAMETER_TYPE + " '"
1107 + this.httpUploadParameterType + "' is not implemented.");
1108 }
1109 }
1110
1111
1112 public String getHttpUploadParameterName() {
1113 return this.httpUploadParameterName;
1114 }
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124 protected void setHttpUploadParameterName(String httpUploadParameterName) throws JUploadException {
1125
1126 if (httpUploadParameterName == null || httpUploadParameterName.equals("")) {
1127 throw new JUploadException("httpUploadParameterName may not be null");
1128 }
1129
1130 if (!httpUploadParameterName.matches("^[a-zA-Z0-9][a-zA-Z0-9_]*$")) {
1131 throw new JUploadException(
1132 "httpUploadParameterName may only contain letters (lowercase or uppercase) and numbers.");
1133 }
1134
1135
1136 this.httpUploadParameterName = httpUploadParameterName;
1137 }
1138
1139
1140 public String getHttpUploadParameterType() {
1141 return this.httpUploadParameterType;
1142 }
1143
1144
1145
1146
1147
1148
1149
1150
1151 protected void setHttpUploadParameterType(String httpUploadParameterType) throws JUploadException {
1152
1153 if (httpUploadParameterType == null) {
1154 throw new JUploadException("httpUploadParameterType may not be null");
1155 }
1156
1157
1158 if (!httpUploadParameterType.equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ARRAY)
1159 && !httpUploadParameterType.equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ITERATION)
1160 && !httpUploadParameterType.equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ONE_FILE)) {
1161 throw new JUploadException("'" + httpUploadParameterType
1162 + "' is not an allowed value for httpUploadParameterType.");
1163 }
1164
1165
1166 if (httpUploadParameterType.equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ONE_FILE)) {
1167 if (getNbFilesPerRequest() != 1) {
1168 throw new JUploadException("'" + httpUploadParameterType
1169 + "' is only valid when nbFilesPerRequest is 1.");
1170 }
1171 }
1172
1173
1174 this.httpUploadParameterType = httpUploadParameterType;
1175 }
1176
1177
1178 public boolean beforeUpload() {
1179
1180 return true;
1181 }
1182
1183
1184 public ByteArrayEncoder onAppendHeader(ByteArrayEncoder bae) throws JUploadIOException {
1185 Iterator<String> it = this.headers.iterator();
1186 String header;
1187 displayDebug("[onAppendHeader] Start", 80);
1188 while (it.hasNext()) {
1189 header = it.next();
1190 if (header == null || header.equals("")) {
1191 displayWarn("[onAppendHeader] Found one empty header. Ignoring it.");
1192 } else {
1193 bae.append(header).append("\r\n");
1194 displayDebug("[onAppendHeader] Header appended; " + header, 80);
1195 }
1196 }
1197 displayDebug("[onAppendHeader] End", 80);
1198 return bae;
1199 }
1200
1201
1202
1203
1204
1205 public void onFileSelected(FileData fileData) {
1206
1207 }
1208
1209
1210
1211
1212
1213 public void onFileDoubleClicked(FileData fileData) {
1214
1215 }
1216
1217
1218 public void sendDebugInformation(String description, Exception exception) {
1219 try {
1220 if (null == getUrlToSendErrorTo()) {
1221 displayInfo("getUrlToSendErrorTo is null. No debug information is sent.");
1222 if (exception == null) {
1223 displayInfo(" No exception was stored!");
1224 } else {
1225 displayInfo(" The exception was: " + exception.getClass().getName() + exception.getMessage());
1226 }
1227 } else {
1228 displayInfo("Sending debug information to " + getUrlToSendErrorTo());
1229 if (JOptionPane.showConfirmDialog(null, getLocalizedString("questionSendMailOnError"),
1230 getLocalizedString("Confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
1231 displayDebug("[sendDebugInformation] Within response == true", 30);
1232
1233 String action = null;
1234 String line;
1235 HTTPConnectionHelper connectionHelper = null;
1236 boolean localDebugOk = this.debugOk;
1237
1238 try {
1239 URL url = new URL(this.urlToSendErrorTo);
1240 connectionHelper = new HTTPConnectionHelper(this);
1241 connectionHelper.initRequest(url, "POST", false, true);
1242
1243 ByteArrayEncoder baeContent = new ByteArrayEncoderHTTP(this, connectionHelper
1244 .getByteArrayEncoder().getBoundary(), connectionHelper.getByteArrayEncoder()
1245 .getEncoding());
1246
1247
1248
1249
1250 baeContent.appendTextProperty("description", "An error occured during upload, in JUpload.", -1);
1251 String exceptionClass = null;
1252 String exceptionCause = null;
1253 String exceptionStackTrace = null;
1254 if (exception != null) {
1255 exceptionClass = exception.getClass().getName();
1256 if (exception.getCause() != null) {
1257 exceptionCause = exception.getCause().getClass().getName();
1258 }
1259 StackTraceElement[] elements = exception.getStackTrace();
1260 ByteArrayEncoderHTTP baeStackTrace = new ByteArrayEncoderHTTP(this, connectionHelper
1261 .getByteArrayEncoder().getBoundary(), connectionHelper.getByteArrayEncoder()
1262 .getEncoding());
1263 for (int i = 0; i < elements.length; i += 1) {
1264 baeStackTrace.append(" at ");
1265 baeStackTrace.append(elements[i].getClassName());
1266 baeStackTrace.append(".");
1267 baeStackTrace.append(elements[i].getMethodName());
1268 baeStackTrace.append("() [line ");
1269 baeStackTrace.append(Integer.toString(elements[i].getLineNumber()));
1270 baeStackTrace.append("]\r\n");
1271 }
1272 baeStackTrace.close();
1273 exceptionStackTrace = baeStackTrace.getString();
1274 }
1275 baeContent.appendTextProperty("exceptionClass", exceptionClass, -1);
1276 baeContent.appendTextProperty("exceptionCause", exceptionCause, -1);
1277 baeContent.appendTextProperty("exceptionStackTrace", exceptionStackTrace, -1);
1278
1279 String baeBound = connectionHelper.getByteArrayEncoder().getBoundary();
1280 String baeEncoding = connectionHelper.getByteArrayEncoder().getEncoding();
1281 ByteArrayEncoder baeDebug = new ByteArrayEncoderHTTP(this, baeBound, baeEncoding);
1282 if (this.debugGenerateFile) {
1283
1284
1285
1286
1287 action = "flush (debugGenerateFile=true)";
1288 synchronized (this) {
1289 this.debugOut.flush();
1290 this.debugOk = false;
1291
1292
1293
1294 action = "read debug file (debugGenerateFile=true)";
1295 BufferedReader debugIn = new BufferedReader(new FileReader(this.debugFile));
1296 while ((line = debugIn.readLine()) != null) {
1297 baeDebug.append(line).append("\r\n");
1298 }
1299 debugIn.close();
1300
1301
1302
1303 this.debugOk = localDebugOk;
1304 }
1305 }
1306 else {
1307 action = "read debug file (debugGenerateFile=false)";
1308 baeDebug.append(this.juploadContext.getLogWindow().getText());
1309 }
1310 action = "baeDebug.close()";
1311 baeDebug.close();
1312
1313 baeContent.appendTextProperty("debugOutput", baeDebug.getString(), -1);
1314 baeContent.appendEndPropertyList();
1315
1316 baeContent.close();
1317
1318
1319
1320
1321 action = "send request";
1322 connectionHelper.append("Content-Type: multipart/form-data; boundary=")
1323 .append(connectionHelper.getBoundary().substring(2)).append("\r\n");
1324 connectionHelper.append("Content-length: ")
1325 .append(String.valueOf(baeContent.getEncodedLength())).append("\r\n");
1326
1327
1328 connectionHelper.sendRequest();
1329
1330 connectionHelper.append("\r\n");
1331 connectionHelper.append(baeContent);
1332
1333 action = "connectionHelper.readHttpResponse()";
1334 int status = connectionHelper.readHttpResponse();
1335
1336 displayDebug(
1337 "========================================================================================",
1338 90);
1339 displayDebug(
1340 "================== sendDebugInformation [start] =================================",
1341 90);
1342 displayDebug(
1343 "========================================================================================",
1344 90);
1345 displayDebug("[sendDebugInformation] Sent to server: \r\n"
1346 + connectionHelper.getByteArrayEncoder().getString(), 90);
1347 displayDebug(
1348 "========================================================================================",
1349 90);
1350 displayDebug("[sendDebugInformation] Body received: \r\n" + connectionHelper.getResponseBody(),
1351 90);
1352 displayDebug(
1353 "========================================================================================",
1354 90);
1355 displayDebug(
1356 "================== sendDebugInformation [end] =================================",
1357 90);
1358 displayDebug(
1359 "========================================================================================",
1360 90);
1361
1362
1363 if (!checkUploadSuccess(status, connectionHelper.getResponseMsg(),
1364 connectionHelper.getResponseBody())) {
1365 throw new JUploadExceptionUploadFailed(getLocalizedString("errHttpResponse"));
1366 }
1367
1368 displayInfo("debug information sent correctly");
1369 } catch (MalformedURLException e) {
1370 throw new JUploadIOException("Malformed URL Exception for " + this.urlToSendErrorTo, e);
1371 } catch (Exception e) {
1372 this.debugOk = localDebugOk;
1373 displayErr(getLocalizedString("errDuringLogManagement") + " (" + action + ")", e);
1374 } finally {
1375 this.debugOk = localDebugOk;
1376 }
1377 }
1378 }
1379 } catch (JUploadIOException e) {
1380 displayErr("Could not send debug information", e);
1381 }
1382 }
1383
1384
1385
1386
1387
1388
1389
1390
1391 public void setProperty(String prop, String value) throws JUploadException {
1392
1393 displayDebug("[DefaultUploadPolicy] Call of setProperty: " + prop + " => " + value, 30);
1394
1395 if (prop.equals(PROP_AFTER_UPLOAD_URL)) {
1396 setAfterUploadURL(value);
1397 } else if (prop.equals(PROP_ALLOW_HTTP_PERSISTENT)) {
1398 setAllowHttpPersistent(Boolean.parseBoolean(value));
1399 } else if (prop.equals(PROP_ALLOWED_FILE_EXTENSIONS)) {
1400 setAllowedFileExtensions(value);
1401 } else if (prop.equals(PROP_DEBUG_LEVEL)) {
1402 setDebugLevel(this.juploadContext.parseInt(value, this.debugLevel));
1403 } else if (prop.equals(PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT)) {
1404 setFileChooserIconFromFileContent(this.juploadContext.parseInt(value, getFileChooserIconFromFileContent()));
1405 } else if (prop.equals(PROP_FILE_CHOOSER_ICON_SIZE)) {
1406 setFileChooserIconSize(this.juploadContext.parseInt(value, getFileChooserIconSize()));
1407 } else if (prop.equals(PROP_FILE_FILTER_NAME)) {
1408 setFileFilterName(value);
1409 } else if (prop.equals(PROP_FILENAME_ENCODING)) {
1410 setFilenameEncoding(value);
1411 } else if (prop.equals(PROP_LANG)) {
1412 setLang(value);
1413 } else if (prop.equals(PROP_LOOK_AND_FEEL)) {
1414 setLookAndFeel(value);
1415 } else if (prop.equals(PROP_MAX_CHUNK_SIZE)) {
1416 setMaxChunkSize(this.juploadContext.parseLong(value, this.maxChunkSize));
1417 } else if (prop.equals(PROP_MAX_FILE_SIZE)) {
1418 setMaxFileSize(this.juploadContext.parseLong(value, this.maxFileSize));
1419 } else if (prop.equals(PROP_NB_FILES_PER_REQUEST)) {
1420 setNbFilesPerRequest(this.juploadContext.parseInt(value, this.nbFilesPerRequest));
1421 } else if (prop.equals(PROP_POST_URL)) {
1422 setPostURL(value);
1423 } else if (prop.equals(PROP_SERVER_PROTOCOL)) {
1424
1425
1426
1427 } else if (prop.equals(PROP_STRING_UPLOAD_SUCCESS)) {
1428 setStringUploadSuccess(value);
1429 } else if (prop.equals(PROP_SSL_VERIFY_CERT)) {
1430 setSslVerifyCert(value);
1431 } else if (prop.equals(PROP_URL_TO_SEND_ERROR_TO)) {
1432 setUrlToSendErrorTo(value);
1433 } else {
1434 displayWarn("Unknown applet parameter: " + prop + " (in DefaultUploadPolicy.setProperty)");
1435 }
1436 }
1437
1438
1439
1440
1441
1442
1443
1444
1445 public void displayParameterStatus() {
1446 displayDebug("=======================================================================", 30);
1447 displayDebug("======= Parameters managed by DefaultUploadPolicy", 30);
1448
1449
1450
1451 displayInfo("JUpload applet, version " + this.juploadContext.getDetailedVersionMessage() + " (compiled: "
1452 + this.juploadContext.getBuildDate() + "), available at http://jupload.sourceforge.net/");
1453 displayDebug("Java version: " + System.getProperty("java.version"), 30);
1454
1455 displayDebug("List of all applet parameters:", 30);
1456 displayDebug(" language: " + this.resourceBundle.getLocale().getLanguage(), 30);
1457 displayDebug(" country: " + this.resourceBundle.getLocale().getCountry(), 30);
1458
1459 displayDebug(PROP_AFTER_UPLOAD_URL + ": " + getAfterUploadURL(), 30);
1460 displayDebug(PROP_ALLOW_HTTP_PERSISTENT + ": " + getAllowHttpPersistent(), 30);
1461 displayDebug(PROP_ALLOWED_FILE_EXTENSIONS + ": " + getAllowedFileExtensions(), 30);
1462 displayDebug(PROP_BROWSING_DIRECTORY + " (current value): " + getCurrentBrowsingDirectory(), 30);
1463 displayDebug(PROP_DEBUG_LEVEL + ": " + this.debugLevel, 1);
1464 synchronized (this) {
1465 if (this.debugGenerateFile) {
1466 displayDebug(" (debugfile: " + this.debugFile.getAbsolutePath() + ")", 1);
1467 }
1468 }
1469 displayDebug(PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT + ": " + getFileChooserIconFromFileContent(), 30);
1470 displayDebug(PROP_FILE_CHOOSER_ICON_SIZE + ": " + getFileChooserIconSize(), 30);
1471 displayDebug(PROP_FILE_FILTER_NAME + ": " + getFileFilterName(), 30);
1472 displayDebug(PROP_FILE_LIST_VIEW_MODE + ": " + getFileListViewMode(), 30);
1473 displayDebug(PROP_FILENAME_ENCODING + ": " + getFilenameEncoding(), 30);
1474 displayDebug(PROP_FORMDATA + ": " + getFormdata(), 30);
1475 displayDebug(PROP_FTP_CREATE_DIRECTORY_STRUCTURE + ": " + getFtpCreateDirectoryStructure(), 30);
1476 displayDebug(PROP_FTP_TRANSFERT_BINARY + ": " + getFtpTransfertBinary(), 30);
1477 displayDebug(PROP_FTP_TRANSFERT_PASSIVE + ": " + getFtpTransfertPassive(), 30);
1478 displayDebug(PROP_HTTP_UPLOAD_PARAMETER_NAME + ": " + getHttpUploadParameterName(), 30);
1479 displayDebug(PROP_HTTP_UPLOAD_PARAMETER_TYPE + ": " + getHttpUploadParameterType(), 30);
1480 displayDebug("lang: " + this.lang, 30);
1481 displayDebug(PROP_MAX_CHUNK_SIZE + ": " + getMaxChunkSize(), 30);
1482 if (this.maxFileSize == Long.MAX_VALUE) {
1483
1484
1485 displayDebug(PROP_MAX_FILE_SIZE + ": " + getMaxFileSize(), 30);
1486 } else {
1487
1488 displayInfo(PROP_MAX_FILE_SIZE + ": " + getMaxFileSize());
1489 }
1490 displayDebug(PROP_NB_FILES_PER_REQUEST + ": " + getNbFilesPerRequest(), 30);
1491 displayDebug(PROP_POST_URL + ": " + this.postURL, 30);
1492 displayDebug(PROP_READ_COOKIE_FROM_NAVIGATOR + ": " + this.readCookieFromNavigator, 30);
1493 displayDebug(PROP_READ_USER_AGENT_FROM_NAVIGATOR + ": " + this.readUserAgentFromNavigator, 30);
1494 displayDebug(PROP_RETRY_MAX_NUMBER_OF + ": " + this.retryMaxNumberOf, 30);
1495 displayDebug(PROP_RETRY_NB_SECONDS_BETWEEN + ": " + this.retryNbSecondsBetween, 30);
1496 displayDebug(PROP_SEND_MD5_SUM + ": " + getSendMD5Sum(), 30);
1497 displayDebug(PROP_SERVER_PROTOCOL + ": " + getServerProtocol(), 30);
1498 displayDebug(PROP_SHOW_LOGWINDOW + ": " + getShowLogWindow(), 30);
1499 displayDebug(PROP_SHOW_STATUSBAR + ": " + this.showStatusbar, 30);
1500 displayDebug(PROP_SPECIFIC_HEADERS + ": " + getSpecificHeaders(), 30);
1501
1502 displayDebug("Headers that will be added to the POST request: ", 30);
1503 for (Iterator<String> it = this.headers.iterator(); it.hasNext();) {
1504 displayDebug(it.next() + "\n", 30);
1505 }
1506 displayDebug(PROP_STRING_UPLOAD_ERROR + ": " + getStringUploadError(), 30);
1507 displayDebug(PROP_STRING_UPLOAD_SUCCESS + ": " + getStringUploadSuccess(), 30);
1508 displayDebug(PROP_STRING_UPLOAD_WARNING + ": " + getStringUploadWarning(), 30);
1509 displayDebug(PROP_URL_TO_SEND_ERROR_TO + ": " + getUrlToSendErrorTo(), 30);
1510 displayDebug("", 30);
1511 }
1512
1513
1514
1515
1516
1517
1518
1519 public String getAfterUploadURL() {
1520 return this.afterUploadURL;
1521 }
1522
1523
1524
1525
1526
1527
1528
1529 protected void setAfterUploadURL(String afterUploadURL) throws JUploadException {
1530 if (null == afterUploadURL)
1531 return;
1532 if (afterUploadURL.toLowerCase().startsWith("javascript:")) {
1533 this.afterUploadURL = afterUploadURL;
1534 } else
1535 this.afterUploadURL = this.juploadContext.normalizeURL(afterUploadURL);
1536 }
1537
1538
1539
1540
1541 public boolean getAllowHttpPersistent() {
1542 return this.allowHttpPersistent;
1543 }
1544
1545
1546 public String getAllowedFileExtensions() {
1547 return this.allowedFileExtensions;
1548 }
1549
1550
1551
1552
1553 protected void setAllowedFileExtensions(String allowedFileExtensions) {
1554 if (allowedFileExtensions == null || allowedFileExtensions.equals("")) {
1555 this.allowedFileExtensions = null;
1556 } else {
1557 this.allowedFileExtensions = (allowedFileExtensions.startsWith("/") ? "" : "/")
1558 + allowedFileExtensions.toLowerCase() + (allowedFileExtensions.endsWith("/") ? "" : "/");
1559 }
1560 }
1561
1562 protected void setAllowHttpPersistent(boolean value) {
1563 this.allowHttpPersistent = value;
1564 }
1565
1566
1567 public JUploadContext getContext() {
1568 return this.juploadContext;
1569 }
1570
1571
1572 public void setCurrentBrowsingDirectory(File currentBrowsingDirectoryParam) {
1573 try {
1574 if (currentBrowsingDirectoryParam.isDirectory()) {
1575 this.currentBrowsingDirectory = currentBrowsingDirectoryParam;
1576 } else {
1577 displayWarn("DefaultUploadPolicy.setCurrentBrowsingDirectory(): " + currentBrowsingDirectoryParam
1578 + " doesn't exist.");
1579 }
1580 } catch (SecurityException se) {
1581 displayWarn(se.getClass().getName() + " in DefaultUploadPolicy.setCurrentBrowsingDirectory(): "
1582 + currentBrowsingDirectoryParam + " is ignored.");
1583 }
1584 }
1585
1586
1587
1588
1589
1590 public void setCurrentBrowsingDirectory(String currentBrowsingDirectoryParam) {
1591 try {
1592 if (currentBrowsingDirectoryParam == null) {
1593 this.currentBrowsingDirectory = null;
1594 } else {
1595
1596
1597
1598 if (currentBrowsingDirectoryParam.startsWith("~")) {
1599
1600 currentBrowsingDirectoryParam = System.getProperty("user.home")
1601 + currentBrowsingDirectoryParam.substring(1);
1602 }
1603
1604 this.currentBrowsingDirectory = new File(currentBrowsingDirectoryParam);
1605
1606
1607 if (this.currentBrowsingDirectory != null && !this.currentBrowsingDirectory.isDirectory()) {
1608 displayWarn("DefaultUploadPolicy.setCurrentBrowsingDirectory(): <" + currentBrowsingDirectoryParam
1609 + "> doesn't exist or is not a directory.");
1610 this.currentBrowsingDirectory = null;
1611 }
1612 }
1613 } catch (SecurityException se) {
1614 displayWarn(se.getClass().getName() + " in DefaultUploadPolicy.setCurrentBrowsingDirectory(): "
1615 + currentBrowsingDirectoryParam + " is ignored.");
1616 }
1617 }
1618
1619
1620 public File getCurrentBrowsingDirectory() {
1621 return this.currentBrowsingDirectory;
1622 }
1623
1624
1625 public String getDateFormat() {
1626 return UploadPolicy.DEFAULT_DATE_FORMAT;
1627 }
1628
1629
1630 public int getDebugLevel() {
1631 return this.debugLevel;
1632 }
1633
1634
1635 public void setDebugLevel(int debugLevel) {
1636 setDebugLevel(debugLevel, true);
1637 }
1638
1639
1640
1641
1642
1643
1644
1645 public synchronized void setDebugLevel(int debugLevel, boolean displayAppletParameterList) {
1646
1647
1648 if (this.debugLevel >= 0) {
1649 displayInfo("Debug level set to " + debugLevel);
1650 if (this.debugGenerateFile) {
1651 displayInfo("Current debug output file: " + this.debugFile.getAbsolutePath());
1652 }
1653 }
1654 this.debugLevel = debugLevel;
1655
1656
1657 if (displayAppletParameterList) {
1658 displayParameterStatus();
1659 }
1660 }
1661
1662
1663
1664
1665
1666
1667
1668 public int getFileChooserIconFromFileContent() {
1669 return this.fileChooserIconFromFileContent;
1670 }
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680 public void setFileChooserIconFromFileContent(int fileChooserIconFromFileContent) {
1681 if (fileChooserIconFromFileContent != -1 && fileChooserIconFromFileContent != 0
1682 && fileChooserIconFromFileContent != 1) {
1683 throw new java.lang.IllegalArgumentException("fileChooserIconFromFileContent must be one of -1, 0, 1");
1684 }
1685 this.fileChooserIconFromFileContent = fileChooserIconFromFileContent;
1686 }
1687
1688
1689
1690
1691
1692
1693
1694 public int getFileChooserIconSize() {
1695 return this.fileChooserIconSize;
1696 }
1697
1698
1699
1700
1701
1702
1703
1704
1705 public void setFileChooserIconSize(int fileChooserIconSize) {
1706 if (fileChooserIconSize <= 0) {
1707 throw new java.lang.IllegalArgumentException("fileChooserIconSize must be more than 0");
1708 }
1709 this.fileChooserIconSize = fileChooserIconSize;
1710 }
1711
1712
1713 public void setLang(String lang) {
1714 this.lang = lang;
1715 if (lang == null) {
1716 displayInfo("lang = null, taking default language");
1717 locale = Locale.getDefault();
1718 } else {
1719
1720
1721
1722 if (lang.length() == 5 && (lang.substring(2, 3).equals("_") || lang.substring(2, 3).equals("-"))) {
1723 String language = lang.substring(0, 2);
1724 String country = lang.substring(3, 5);
1725 displayDebug("setLang - language read: " + language, 50);
1726 displayDebug("setLang - country read: " + country, 50);
1727 locale = new Locale(language, country.toUpperCase());
1728 } else {
1729 locale = new Locale(lang);
1730 displayDebug("setLang - language read (no country): " + lang, 50);
1731 }
1732 }
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742 this.resourceBundle = ResourceBundle.getBundle("lang.lang", locale,
1743
1744 new ClassLoader(this.getClass().getClassLoader()) {
1745
1746 @Override
1747 public Class<?> loadClass(String name) throws ClassNotFoundException {
1748 throw new ClassNotFoundException();
1749 }
1750
1751
1752 @Override
1753 public InputStream getResourceAsStream(String name) {
1754 return this.getClass().getClassLoader().getResourceAsStream(name);
1755 }
1756 });
1757 }
1758
1759
1760 public Locale getLocale() {
1761 return this.locale;
1762 }
1763
1764
1765
1766 protected String getLookAndFeel() {
1767 return this.lookAndFeel;
1768 }
1769
1770
1771
1772
1773 protected void setLookAndFeel(String lookAndFeel) {
1774 try {
1775 this.lookAndFeel = lookAndFeel;
1776 if (lookAndFeel != null && !lookAndFeel.equals("") && !lookAndFeel.equals("java")) {
1777
1778
1779
1780
1781 if (!lookAndFeel.equals("system")) {
1782
1783 UIManager.setLookAndFeel(lookAndFeel);
1784 } else {
1785 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1786 }
1787 } else {
1788 this.lookAndFeel = "java";
1789 UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
1790 }
1791 } catch (Exception e) {
1792 displayErr(e);
1793 try {
1794 this.lookAndFeel = "java";
1795 UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
1796 } catch (UnsupportedLookAndFeelException e1) {
1797 displayErr(e1);
1798
1799 this.lookAndFeel = null;
1800 }
1801 }
1802 }
1803
1804
1805 public long getMaxChunkSize() {
1806 return this.maxChunkSize;
1807 }
1808
1809
1810
1811
1812
1813
1814 protected void setMaxChunkSize(long maxChunkSize) {
1815 if (maxChunkSize <= 0) {
1816 displayDebug("maxChunkSize<=0 which is invalid. Switched to the default value (Long.MAX_VALUE)", 1);
1817 maxChunkSize = Long.MAX_VALUE;
1818 }
1819 this.maxChunkSize = maxChunkSize;
1820 }
1821
1822
1823 public long getMaxFileSize() {
1824 return this.maxFileSize;
1825 }
1826
1827
1828
1829
1830 protected void setMaxFileSize(long maxFileSize) {
1831 if (maxFileSize <= 0) {
1832 displayDebug("maxFileSize<=0 which is invalid. Switched to the default value (Long.MAX_VALUE)", 1);
1833 maxFileSize = Long.MAX_VALUE;
1834 }
1835 this.maxFileSize = maxFileSize;
1836 }
1837
1838
1839 public int getNbFilesPerRequest() {
1840 return this.nbFilesPerRequest;
1841 }
1842
1843
1844
1845
1846
1847 protected void setNbFilesPerRequest(int nbFilesPerRequest) throws JUploadException {
1848
1849 if (getHttpUploadParameterType().equals(UploadPolicy.HTTPUPLOADPARAMETERTYPE_ONE_FILE)
1850 && nbFilesPerRequest != 1) {
1851 throw new JUploadException("nbFilesPerRequest must be 1, when httpUploadParameterType is oneFile");
1852 }
1853
1854 if (nbFilesPerRequest < 1) {
1855 displayDebug("nbFilesPerRequest <1 : switched to the 'unlimited' value (Integer.MAX_VALUE)", 1);
1856 this.nbFilesPerRequest = Integer.MAX_VALUE;
1857 } else {
1858 this.nbFilesPerRequest = nbFilesPerRequest;
1859 }
1860 }
1861
1862
1863 public FileListViewMode getFileListViewMode() {
1864 return fileListViewMode;
1865 }
1866
1867
1868 public void setFileListViewMode(FileListViewMode fileListViewMode) {
1869 this.fileListViewMode = fileListViewMode;
1870 }
1871
1872
1873 @Deprecated
1874 public String getFilenameEncoding() {
1875 return this.filenameEncoding;
1876 }
1877
1878
1879 public String getFileFilterName() {
1880 return this.fileFilterName;
1881 }
1882
1883
1884
1885
1886
1887 protected void setFileFilterName(String fileFilterName) {
1888 this.fileFilterName = fileFilterName;
1889 }
1890
1891
1892
1893
1894 protected void setFilenameEncoding(String filenameEncoding) {
1895 if (filenameEncoding != null && filenameEncoding.equals("")) {
1896 filenameEncoding = null;
1897 }
1898 if (filenameEncoding != null && !Charset.isSupported(filenameEncoding)) {
1899 throw new UnsupportedCharsetException("non supported charset (" + filenameEncoding + ")");
1900 }
1901 this.filenameEncoding = filenameEncoding;
1902 }
1903
1904
1905 public boolean getFtpCreateDirectoryStructure() {
1906 return this.ftpCreateDirectoryStructure;
1907 }
1908
1909
1910
1911
1912 protected void setFtpCreateDirectoryStructure(boolean ftpCreateDirectoryStructure) {
1913 this.ftpCreateDirectoryStructure = ftpCreateDirectoryStructure;
1914 }
1915
1916
1917 public boolean getFtpTransfertBinary() {
1918 return this.ftpTransfertBinary;
1919 }
1920
1921
1922
1923
1924 protected void setFtpTransfertBinary(boolean ftpTransfertBinary) {
1925 this.ftpTransfertBinary = ftpTransfertBinary;
1926 }
1927
1928
1929 public boolean getFtpTransfertPassive() {
1930 return this.ftpTransfertPassive;
1931 }
1932
1933
1934
1935
1936 protected void setFtpTransfertPassive(boolean ftpTransfertPassive) {
1937 this.ftpTransfertPassive = ftpTransfertPassive;
1938 }
1939
1940
1941 public String getPostURL() {
1942 return this.postURL;
1943 }
1944
1945
1946
1947
1948
1949 public void setPostURL(String postURL) throws JUploadException {
1950
1951
1952
1953
1954
1955
1956
1957
1958 this.postURL = this.juploadContext.normalizeURL(postURL);
1959 }
1960
1961
1962 public boolean getReadCookieFromNavigator() {
1963 return this.readCookieFromNavigator;
1964 }
1965
1966
1967 protected void setReadCookieFromNavigator(boolean readCookieFromNavigator) {
1968 this.readCookieFromNavigator = readCookieFromNavigator;
1969 }
1970
1971
1972 public boolean getReadUserAgentFromNavigator() {
1973 return this.readUserAgentFromNavigator;
1974 }
1975
1976
1977 protected void setReadUserAgentFromNavigator(boolean readUserAgentFromNavigator) {
1978 this.readUserAgentFromNavigator = readUserAgentFromNavigator;
1979 }
1980
1981
1982 public int getRetryMaxNumberOf() {
1983 return this.retryMaxNumberOf;
1984 }
1985
1986
1987
1988
1989
1990
1991 public void setRetryMaxNumberOf(int retryMaxNumberOf) {
1992 if (retryMaxNumberOf < 0) {
1993 throw new IllegalArgumentException("retryMaxNumberOf must be 0 or more");
1994 }
1995 this.retryMaxNumberOf = retryMaxNumberOf;
1996 }
1997
1998
1999 public int getRetryNbSecondsBetween() {
2000 return this.retryNbSecondsBetween;
2001 }
2002
2003
2004
2005
2006
2007
2008 public void setRetryNbSecondsBetween(int retryNbSecondsBetween) {
2009 if (retryNbSecondsBetween < 0) {
2010 throw new IllegalArgumentException("retryNbSecondsBetween must be 0 or more");
2011 }
2012 this.retryNbSecondsBetween = retryNbSecondsBetween;
2013 }
2014
2015
2016 public String getServerProtocol() {
2017 if (this.serverProtocol == null) {
2018 return DEFAULT_SERVER_PROTOCOL;
2019 } else {
2020 return this.serverProtocol;
2021 }
2022 }
2023
2024
2025 public void setServerProtocol(String serverProtocol) {
2026 this.serverProtocol = serverProtocol;
2027 }
2028
2029
2030 public boolean getSendMD5Sum() {
2031 return this.sendMD5Sum;
2032 }
2033
2034
2035 public void setSendMD5Sum(boolean sendMD5Sum) {
2036 this.sendMD5Sum = sendMD5Sum;
2037 }
2038
2039
2040 public String getShowLogWindow() {
2041 return this.showLogWindow;
2042 }
2043
2044
2045 public void setShowLogWindow(String showLogWindow) {
2046 if (showLogWindow.equals(SHOWLOGWINDOW_TRUE) || showLogWindow.equals(SHOWLOGWINDOW_FALSE)
2047 || showLogWindow.equals(SHOWLOGWINDOW_ONERROR)) {
2048 this.showLogWindow = showLogWindow;
2049
2050
2051 if (this.juploadContext.getUploadPanel() != null) {
2052 this.juploadContext.getUploadPanel().showOrHideLogWindow();
2053 }
2054 } else {
2055 displayWarn("[setShowLogWindow] Unallowed value: " + showLogWindow + " (showLogWindow is left unchanged)");
2056 }
2057 }
2058
2059
2060 public String getSpecificHeaders() {
2061 return this.specificHeaders;
2062 }
2063
2064
2065
2066
2067
2068
2069
2070
2071 protected void setSpecificHeaders(String specificHeaders) {
2072 this.specificHeaders = specificHeaders;
2073 if (specificHeaders != null) {
2074
2075
2076
2077
2078
2079 String[] headerArray = specificHeaders.split("\\\\n");
2080 for (int x = 0; x < headerArray.length; x++) {
2081 addHeader(headerArray[x]);
2082 }
2083 }
2084 }
2085
2086
2087
2088
2089 public int getSslVerifyCert() {
2090 return this.sslVerifyCert;
2091 }
2092
2093 protected void setSslVerifyCert(String mode) throws JUploadException {
2094 int val = -1;
2095 if (mode.toLowerCase().equals("none"))
2096 val = InteractiveTrustManager.NONE;
2097 if (mode.toLowerCase().equals("server"))
2098 val = InteractiveTrustManager.SERVER;
2099 if (mode.toLowerCase().equals("client"))
2100 val = InteractiveTrustManager.CLIENT;
2101 if (mode.toLowerCase().equals("strict"))
2102 val = InteractiveTrustManager.STRICT;
2103 if (val == -1)
2104 throw new JUploadException("Invalid parameter sslVerifyCert (" + mode + ")");
2105 this.sslVerifyCert = val;
2106 }
2107
2108
2109
2110
2111 protected void setShowStatusbar(boolean show) {
2112 this.showStatusbar = show;
2113 }
2114
2115
2116 public String getStringUploadError() {
2117 return this.stringUploadError;
2118 }
2119
2120
2121 public String getStringUploadSuccess() {
2122 return this.stringUploadSuccess;
2123 }
2124
2125
2126 public String getStringUploadWarning() {
2127 return this.stringUploadWarning;
2128 }
2129
2130
2131
2132
2133
2134 protected void setStringUploadError(String stringUploadError) throws JUploadException {
2135 this.stringUploadError = stringUploadError;
2136 if (stringUploadError != null) {
2137 try {
2138 this.patternError = Pattern.compile(stringUploadError);
2139 } catch (PatternSyntaxException e) {
2140 throw new JUploadException("Invalid regex in parameter stringUploadError");
2141 }
2142 }
2143 }
2144
2145
2146
2147
2148
2149 protected void setStringUploadSuccess(String stringUploadSuccess) throws JUploadException {
2150 this.stringUploadSuccess = stringUploadSuccess;
2151 if (stringUploadSuccess != null) {
2152 try {
2153 this.patternSuccess = Pattern.compile(stringUploadSuccess);
2154 } catch (PatternSyntaxException e) {
2155 throw new JUploadException("Invalid regex in parameter stringUploadSuccess");
2156 }
2157 }
2158 }
2159
2160
2161
2162
2163
2164 protected void setStringUploadWarning(String stringUploadWarning) throws JUploadException {
2165 this.stringUploadWarning = stringUploadWarning;
2166 if (stringUploadWarning != null) {
2167 try {
2168 this.patternWarning = Pattern.compile(stringUploadWarning);
2169 } catch (PatternSyntaxException e) {
2170 throw new JUploadException("Invalid regex in parameter stringUploadWarning");
2171 }
2172 }
2173 }
2174
2175
2176 public String getUrlToSendErrorTo() {
2177 return this.urlToSendErrorTo;
2178 }
2179
2180
2181 public void setUrlToSendErrorTo(String urlToSendErrorTo) throws JUploadException {
2182 if (null == urlToSendErrorTo)
2183 return;
2184 String tmp = this.juploadContext.normalizeURL(urlToSendErrorTo);
2185 if (tmp.startsWith("ftp://")) {
2186 throw new JUploadException("urlToSendErrorTo: ftp scheme not supported.");
2187 }
2188 this.urlToSendErrorTo = tmp;
2189 }
2190
2191
2192 public String getFormdata() {
2193 return this.formData;
2194 }
2195
2196
2197 public String getAfterUploadTarget() {
2198 return this.afterUploadTarget;
2199 }
2200
2201
2202
2203
2204
2205
2206
2207
2208 public synchronized void deleteLog() {
2209 if (this.debugGenerateFile) {
2210 try {
2211 if (null != this.debugOut) {
2212 this.debugOut.close();
2213 this.debugOut = null;
2214 }
2215 if (null != this.debugFile) {
2216 if (!this.debugFile.delete()) {
2217 displayWarn(this.debugFile.getName() + " was not correctly removed!");
2218 }
2219 this.debugFile = null;
2220 }
2221 } catch (Exception e) {
2222
2223 displayWarn(e.getClass().getName() + " occured in deleteLog(). Exception ignored.");
2224 }
2225 }
2226 }
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236 protected synchronized void addMsgToDebugLog(String msg) {
2237
2238
2239
2240 if (this.debugGenerateFile && this.debugOk) {
2241 try {
2242 if (null == this.debugOut) {
2243 this.juploadContext.registerUnload(this, "deleteLog");
2244 this.debugFile = File.createTempFile("jupload_", "_log.txt");
2245 this.debugOut = new PrintStream(new FileOutputStream(this.debugFile));
2246 }
2247 boolean endsLF = msg.endsWith("\n");
2248 msg = msg.replaceAll("\n", this.CRLF);
2249 if (endsLF) {
2250 this.debugOut.print(msg);
2251 } else {
2252 this.debugOut.println(msg);
2253 }
2254 } catch (IOException e) {
2255 this.debugOk = false;
2256 System.err.println("IO error on debuglog " + this.debugFile.getPath()
2257 + "\nFallback to standard output.");
2258 System.out.println(msg);
2259 }
2260 } else {
2261 System.out.println(msg);
2262 }
2263 }
2264
2265
2266
2267
2268
2269
2270
2271 private void displayMsg(String tag, String msg) {
2272 String message;
2273
2274 if (this.juploadContext.getLogWindow() == null) {
2275 message = tag + " - " + msg;
2276 System.out.println(message);
2277 } else {
2278 message = this.juploadContext.getLogWindow().displayMsg(tag, msg);
2279 }
2280
2281 if (this.debugGenerateFile) {
2282 addMsgToDebugLog(message);
2283 }
2284 }
2285
2286
2287
2288
2289
2290
2291 public void afterFileDropped(DropTargetDropEvent dropEvent) {
2292
2293 }
2294
2295
2296
2297
2298
2299
2300
2301 public JUploadFileChooser createFileChooser() {
2302 return new JUploadFileChooser(this);
2303 }
2304
2305
2306
2307
2308
2309
2310
2311 public boolean fileFilterAccept(File file) {
2312 if (file.isDirectory()) {
2313 return true;
2314 } else if (this.allowedFileExtensions == null || this.allowedFileExtensions.equals("")) {
2315 return true;
2316 } else {
2317
2318 String extension = DefaultFileData.getExtension(file.getName()).toLowerCase();
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328 return (this.allowedFileExtensions.indexOf("/" + extension + "/")) >= 0;
2329 }
2330 }
2331
2332
2333 public String fileFilterGetDescription() {
2334 if (this.allowedFileExtensions == null || this.allowedFileExtensions.equals("")) {
2335 return null;
2336 } else if (getFileFilterName() != null) {
2337 return getFileFilterName();
2338 } else {
2339 return "JUpload file filter (" + this.allowedFileExtensions + ")";
2340 }
2341 }
2342
2343
2344
2345
2346
2347
2348 public Icon fileViewGetIcon(File file) {
2349 return null;
2350 }
2351
2352
2353 public JUploadException getLastException() {
2354 return this.lastException;
2355 }
2356
2357
2358
2359
2360
2361
2362 public void setLastException(JUploadException exception) {
2363 this.lastException = exception;
2364
2365
2366 if (this.juploadContext.getUploadPanel() != null) {
2367 this.juploadContext.getUploadPanel().showOrHideLogWindow();
2368 }
2369
2370 }
2371
2372
2373 public String getLastResponseBody() {
2374 return this.lastResponseBody;
2375 }
2376
2377
2378 public String getLastResponseMessage() {
2379 return (null != this.lastResponseMessage) ? this.lastResponseMessage : "";
2380 }
2381
2382
2383
2384
2385
2386 public Cursor setCursor(Cursor cursor) {
2387 return this.juploadContext.setCursor(cursor);
2388 }
2389
2390
2391
2392
2393
2394 public Cursor setWaitCursor() {
2395 return this.juploadContext.setWaitCursor();
2396 }
2397
2398 }