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