| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
package wjhk.jupload2.context; |
| 21 | |
|
| 22 | |
import java.awt.Cursor; |
| 23 | |
import java.awt.Frame; |
| 24 | |
import java.io.InputStream; |
| 25 | |
import java.lang.reflect.InvocationTargetException; |
| 26 | |
import java.lang.reflect.Method; |
| 27 | |
import java.text.MessageFormat; |
| 28 | |
import java.util.ArrayList; |
| 29 | |
import java.util.Date; |
| 30 | |
import java.util.List; |
| 31 | |
import java.util.Locale; |
| 32 | |
import java.util.Properties; |
| 33 | |
import java.util.Vector; |
| 34 | |
|
| 35 | |
import javax.swing.JApplet; |
| 36 | |
import javax.swing.JOptionPane; |
| 37 | |
import javax.swing.RootPaneContainer; |
| 38 | |
import javax.swing.SwingUtilities; |
| 39 | |
|
| 40 | |
import wjhk.jupload2.exception.JUploadException; |
| 41 | |
import wjhk.jupload2.gui.JUploadPanel; |
| 42 | |
import wjhk.jupload2.gui.JUploadPanelImpl; |
| 43 | |
import wjhk.jupload2.gui.JUploadTextArea; |
| 44 | |
import wjhk.jupload2.gui.filepanel.FilePanel.FileListViewMode; |
| 45 | |
import wjhk.jupload2.policies.UploadPolicy; |
| 46 | |
import wjhk.jupload2.policies.UploadPolicyFactory; |
| 47 | |
import wjhk.jupload2.upload.FileUploadManagerThread; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 33 | public class DefaultJUploadContext implements JUploadContext { |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
private final static String SVN_PROPERTIES_FILENAME = "/conf/svn.properties"; |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
private final static String DEFAULT_PROP_UNKNOWN = "Unknown"; |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | 33 | Properties svnProperties = getSvnProperties(); |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | 33 | Frame frame = null; |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | 33 | JavascriptHandler jsHandler = null; |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | 33 | Properties mimeTypesProperties = null; |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | 33 | UploadPolicy uploadPolicy = null; |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | 33 | JUploadPanel jUploadPanel = null; |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | 33 | JUploadTextArea logWindow = null; |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
static class Callback { |
| 120 | |
private String method; |
| 121 | |
|
| 122 | |
private Object object; |
| 123 | |
|
| 124 | 35 | Callback(Object object, String method) { |
| 125 | 35 | this.object = object; |
| 126 | 35 | this.method = method; |
| 127 | 35 | } |
| 128 | |
|
| 129 | |
void invoke() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, |
| 130 | |
SecurityException { |
| 131 | 2 | Object args[] = {}; |
| 132 | 2 | Method methods[] = this.object.getClass().getMethods(); |
| 133 | 102 | for (int i = 0; i < methods.length; i++) { |
| 134 | 100 | if (methods[i].getName().equals(this.method)) { |
| 135 | 2 | methods[i].invoke(this.object, args); |
| 136 | |
} |
| 137 | |
} |
| 138 | 2 | } |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
public String getMethod() { |
| 144 | 1 | return method; |
| 145 | |
} |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
public Object getObject() { |
| 151 | 2 | return object; |
| 152 | |
} |
| 153 | |
|
| 154 | |
} |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | 33 | List<Callback> unloadCallbacks = new ArrayList<Callback>(20); |
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public void init(Frame frame, RootPaneContainer rootPaneContainer) { |
| 174 | |
try { |
| 175 | 33 | this.frame = frame; |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | 33 | Thread.currentThread().setName(rootPaneContainer.getClass().getName()); |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | 33 | this.logWindow = new JUploadTextArea(20, 20, this.uploadPolicy); |
| 186 | |
|
| 187 | |
|
| 188 | 33 | this.uploadPolicy = UploadPolicyFactory.getUploadPolicy(this); |
| 189 | 33 | this.uploadPolicy.displayDebug("After UploadPolicyFactory.getUploadPolicy(this)", 80); |
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | 33 | this.uploadPolicy.displayDebug("Before this.logWindow.setUploadPolicy(this.uploadPolicy)", 80); |
| 195 | 33 | this.logWindow.setUploadPolicy(this.uploadPolicy); |
| 196 | |
|
| 197 | |
|
| 198 | 33 | this.uploadPolicy.displayDebug("Before new JUploadPanelImpl(this.logWindow,this.uploadPolicy)", 80); |
| 199 | 33 | this.jUploadPanel = new JUploadPanelImpl(this.logWindow, this.uploadPolicy); |
| 200 | |
|
| 201 | |
|
| 202 | 33 | this.uploadPolicy.displayDebug("Before rootPaneContainer.setContentPane(this.jUploadPanel);", 80); |
| 203 | 33 | rootPaneContainer.setContentPane(this.jUploadPanel.getJComponent()); |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | 33 | this.uploadPolicy.displayDebug("Before new JavascriptHandler(this.uploadPolicy, this.jUploadPanel)", 80); |
| 208 | 33 | this.jsHandler = new JavascriptHandler(this.uploadPolicy, this.jUploadPanel); |
| 209 | 33 | this.jsHandler.start(); |
| 210 | |
|
| 211 | |
|
| 212 | 33 | registerUnload(this, "unload"); |
| 213 | 0 | } catch (final Exception e) { |
| 214 | 0 | System.out.println(e.getMessage()); |
| 215 | 0 | e.printStackTrace(); |
| 216 | |
|
| 217 | 0 | JOptionPane.showMessageDialog(null, |
| 218 | 0 | "Error during applet initialization!\nHave a look in your Java console (" + e.getClass().getName() |
| 219 | |
+ ")", "Error", JOptionPane.ERROR_MESSAGE); |
| 220 | 33 | } |
| 221 | |
|
| 222 | 33 | this.uploadPolicy.displayDebug("Before new Properties();", 80); |
| 223 | 33 | this.mimeTypesProperties = new Properties(); |
| 224 | 33 | final String mimetypePropertiesFilename = "/conf/mimetypes.properties"; |
| 225 | |
try { |
| 226 | 33 | InputStream isProperties = this.getClass().getResourceAsStream(mimetypePropertiesFilename); |
| 227 | 33 | this.mimeTypesProperties.load(isProperties); |
| 228 | 33 | isProperties.close(); |
| 229 | 33 | this.uploadPolicy.displayDebug("Mime types list loaded Ok (" + mimetypePropertiesFilename + ")", 50); |
| 230 | 0 | } catch (Exception e) { |
| 231 | 0 | this.uploadPolicy.displayWarn("Unable to load the mime types list (" + mimetypePropertiesFilename + "): " |
| 232 | 0 | + e.getClass().getName() + " (" + e.getMessage() + ")"); |
| 233 | 33 | } |
| 234 | |
|
| 235 | 33 | this.uploadPolicy.displayDebug("End of DefaultJUploadContext.init()", 80); |
| 236 | 33 | } |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
public void unload() { |
| 243 | 2 | if (this.jsHandler != null && this.jsHandler.isAlive()) { |
| 244 | 2 | this.jsHandler.interrupt(); |
| 245 | 2 | this.jsHandler = null; |
| 246 | |
} |
| 247 | 2 | } |
| 248 | |
|
| 249 | |
|
| 250 | |
public String getDetailedVersionMessage() { |
| 251 | 0 | String version = getVersion(); |
| 252 | 0 | String svnRevision = getSvnRevision(); |
| 253 | 0 | boolean gotSvnRevision = !svnRevision.equals(DEFAULT_PROP_UNKNOWN); |
| 254 | 0 | int buildNumber = getBuildNumber(); |
| 255 | 0 | boolean gotBuildNumber = buildNumber > 0; |
| 256 | 0 | String buildDate = getBuildDate(); |
| 257 | 0 | boolean gotBuildDate = !buildDate.equals(DEFAULT_PROP_UNKNOWN); |
| 258 | |
|
| 259 | 0 | StringBuffer sb = new StringBuffer(); |
| 260 | 0 | sb.append(version); |
| 261 | |
|
| 262 | 0 | if (gotSvnRevision || gotBuildNumber) { |
| 263 | 0 | sb.append(" ["); |
| 264 | 0 | String space = ""; |
| 265 | 0 | if (gotSvnRevision) { |
| 266 | 0 | sb.append("SVN-Rev: "); |
| 267 | 0 | sb.append(svnRevision); |
| 268 | 0 | space = " "; |
| 269 | |
} |
| 270 | 0 | if (gotBuildNumber) { |
| 271 | 0 | sb.append(space); |
| 272 | 0 | sb.append("build "); |
| 273 | 0 | sb.append(buildNumber); |
| 274 | |
} |
| 275 | 0 | sb.append("]"); |
| 276 | |
} |
| 277 | |
|
| 278 | 0 | if (gotBuildDate) { |
| 279 | 0 | sb.append(" - "); |
| 280 | 0 | sb.append(buildDate); |
| 281 | |
} |
| 282 | 0 | return sb.toString(); |
| 283 | |
} |
| 284 | |
|
| 285 | |
|
| 286 | |
public String getVersion() { |
| 287 | 0 | return getProperty("jupload.version", DEFAULT_PROP_UNKNOWN); |
| 288 | |
} |
| 289 | |
|
| 290 | |
|
| 291 | |
public String getSvnRevision() { |
| 292 | 0 | String svnRevision = getProperty("jupload.svn.revision", DEFAULT_PROP_UNKNOWN); |
| 293 | 0 | if (svnRevision.startsWith("{") || svnRevision.startsWith("${")) { |
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | 0 | return DEFAULT_PROP_UNKNOWN; |
| 299 | |
} else { |
| 300 | 0 | return svnRevision; |
| 301 | |
} |
| 302 | |
} |
| 303 | |
|
| 304 | |
|
| 305 | |
public String getLastModified() { |
| 306 | 1 | return getProperty("jupload.lastSrcDirModificationDate", DEFAULT_PROP_UNKNOWN); |
| 307 | |
} |
| 308 | |
|
| 309 | |
|
| 310 | |
public String getBuildDate() { |
| 311 | 1 | String timestamp = getProperty("jupload.buildTimestamp", DEFAULT_PROP_UNKNOWN); |
| 312 | 1 | if (timestamp.equals(DEFAULT_PROP_UNKNOWN)) { |
| 313 | 0 | return DEFAULT_PROP_UNKNOWN; |
| 314 | |
} else { |
| 315 | 1 | Locale locale = Locale.getDefault(); |
| 316 | 1 | if (this.uploadPolicy != null) { |
| 317 | 1 | locale = this.uploadPolicy.getLocale(); |
| 318 | |
} |
| 319 | 1 | MessageFormat msgFormat = new MessageFormat("{0,date,medium}", locale); |
| 320 | |
try { |
| 321 | 1 | Object[] args = { |
| 322 | 1 | new Date(Long.parseLong(timestamp)) |
| 323 | |
}; |
| 324 | 1 | return msgFormat.format(args); |
| 325 | 0 | } catch (NumberFormatException e) { |
| 326 | |
|
| 327 | |
|
| 328 | 0 | System.out.println("[WARN] The timestamp can not be read (" + timestamp + "). Will return '" |
| 329 | |
+ DEFAULT_PROP_UNKNOWN + "'."); |
| 330 | 0 | return DEFAULT_PROP_UNKNOWN; |
| 331 | |
} |
| 332 | |
} |
| 333 | |
} |
| 334 | |
|
| 335 | |
|
| 336 | |
public int getBuildNumber() { |
| 337 | 1 | String valuePropBuildNumber = getProperty("jupload.buildNumber", "-1"); |
| 338 | |
try { |
| 339 | 1 | return Integer.parseInt(valuePropBuildNumber); |
| 340 | 0 | } catch (java.lang.NumberFormatException e) { |
| 341 | 0 | System.out.println("[WARN] " + e.getClass().getName() + " when getting the buildNumber, while parsing '" |
| 342 | |
+ valuePropBuildNumber + "'). Will return -1"); |
| 343 | 0 | return -1; |
| 344 | |
} |
| 345 | |
} |
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
private String getProperty(String propertyName, String defaultValue) { |
| 356 | 3 | String value = null; |
| 357 | |
try { |
| 358 | 3 | value = this.svnProperties.getProperty(propertyName); |
| 359 | 0 | } catch (Exception e) { |
| 360 | 0 | System.out.println("[WARN] " + e.getClass().getName() + " when getting the " + propertyName + " property (" |
| 361 | 0 | + e.getMessage() + "). Will return '" + value + "'"); |
| 362 | 3 | } |
| 363 | 3 | return (value == null) ? defaultValue : value; |
| 364 | |
} |
| 365 | |
|
| 366 | |
|
| 367 | |
public JUploadTextArea getLogWindow() { |
| 368 | 1 | return this.logWindow; |
| 369 | |
} |
| 370 | |
|
| 371 | |
|
| 372 | |
public String getMimeType(String fileExtension) { |
| 373 | 4 | String mimeType = this.mimeTypesProperties.getProperty(fileExtension.toLowerCase()); |
| 374 | 4 | return (mimeType == null) ? "application/octet-stream" : mimeType; |
| 375 | |
} |
| 376 | |
|
| 377 | |
|
| 378 | |
public JUploadPanel getUploadPanel() { |
| 379 | 2 | return this.jUploadPanel; |
| 380 | |
} |
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
public UploadPolicy getUploadPolicy() throws JUploadException { |
| 390 | 27 | return this.uploadPolicy; |
| 391 | |
} |
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
public void setProperty(String prop, String value) { |
| 407 | |
|
| 408 | |
class PropertySetter implements Runnable { |
| 409 | |
String prop; |
| 410 | |
|
| 411 | |
String value; |
| 412 | |
|
| 413 | 2 | PropertySetter(String prop, String value) { |
| 414 | 2 | this.prop = prop; |
| 415 | 2 | this.value = value; |
| 416 | 2 | } |
| 417 | |
|
| 418 | |
public void run() { |
| 419 | |
try { |
| 420 | |
|
| 421 | |
|
| 422 | 2 | for (int i = 0; i < 20 && uploadPolicy == null; i += 1) { |
| 423 | 0 | this.wait(100); |
| 424 | |
} |
| 425 | 2 | if (uploadPolicy == null) { |
| 426 | 0 | System.out.println("uploadPolicy is null. Impossible to set " + prop + " to " + value); |
| 427 | |
} else { |
| 428 | |
|
| 429 | 2 | uploadPolicy.setProperty(prop, value); |
| 430 | |
} |
| 431 | 0 | } catch (Exception e) { |
| 432 | 0 | uploadPolicy.displayErr(e); |
| 433 | 2 | } |
| 434 | 2 | } |
| 435 | |
} |
| 436 | |
try { |
| 437 | 2 | SwingUtilities.invokeLater(new PropertySetter(prop, value)); |
| 438 | 0 | } catch (Exception e) { |
| 439 | 0 | if (this.uploadPolicy != null) { |
| 440 | 0 | this.uploadPolicy.displayErr(e); |
| 441 | |
} else { |
| 442 | 0 | System.out.println(e.getClass().getName() + ": " + e.getMessage()); |
| 443 | |
} |
| 444 | 2 | } |
| 445 | 2 | } |
| 446 | |
|
| 447 | |
|
| 448 | |
public String startUpload() { |
| 449 | 1 | return this.jsHandler.doCommand(JavascriptHandler.COMMAND_START_UPLOAD); |
| 450 | |
} |
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
public void displayErr(String err) { |
| 458 | 1 | this.uploadPolicy.displayErr(err); |
| 459 | 1 | } |
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
|
| 466 | |
public void displayInfo(String info) { |
| 467 | 1 | this.uploadPolicy.displayInfo(info); |
| 468 | 1 | } |
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
public void displayWarn(String warn) { |
| 476 | 1 | this.uploadPolicy.displayWarn(warn); |
| 477 | 1 | } |
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
public void displayDebug(String debug, int minDebugLevel) { |
| 487 | 1 | this.uploadPolicy.displayDebug(debug, minDebugLevel); |
| 488 | 1 | } |
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
|
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
public static Properties getSvnProperties() { |
| 500 | 34 | Properties properties = new Properties(); |
| 501 | 34 | Boolean bPropertiesLoaded = false; |
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
try { |
| 507 | 34 | InputStream isProperties = Class.forName("wjhk.jupload2.JUploadApplet").getResourceAsStream( |
| 508 | |
SVN_PROPERTIES_FILENAME); |
| 509 | 34 | properties.load(isProperties); |
| 510 | 34 | isProperties.close(); |
| 511 | 34 | bPropertiesLoaded = true; |
| 512 | 0 | } catch (Exception e) { |
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | 0 | System.out.println(e.getClass().getName() + " in DefaultJUploadContext.getSvnProperties() (" |
| 523 | 0 | + e.getMessage() + ")"); |
| 524 | 34 | } |
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | 34 | if (!bPropertiesLoaded) { |
| 529 | 0 | properties.setProperty("buildDate", "Unknown build date (please use the build.xml ant script)"); |
| 530 | 0 | properties.setProperty("lastSrcDirModificationDate", |
| 531 | |
"Unknown last modification date (please use the build.xml ant script)"); |
| 532 | 0 | properties.setProperty("revision", "Unknown revision (please use the build.xml ant script)"); |
| 533 | |
} |
| 534 | 34 | return properties; |
| 535 | |
} |
| 536 | |
|
| 537 | |
|
| 538 | |
public void registerUnload(Object object, String method) { |
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | 35 | this.unloadCallbacks.add(0, new Callback(object, method)); |
| 545 | 35 | } |
| 546 | |
|
| 547 | |
|
| 548 | |
public synchronized void runUnload() { |
| 549 | |
|
| 550 | 1 | FileUploadManagerThread fileUploadManagerThread = this.getUploadPanel().getFileUploadManagerThread(); |
| 551 | 1 | if (fileUploadManagerThread != null) { |
| 552 | 0 | fileUploadManagerThread.stopUpload(); |
| 553 | |
} |
| 554 | |
|
| 555 | |
|
| 556 | 1 | for (Callback callback : this.unloadCallbacks) { |
| 557 | |
try { |
| 558 | 2 | callback.invoke(); |
| 559 | 0 | } catch (Exception e) { |
| 560 | 0 | System.out.println(e.getClass().getName() + " while calling the callback: " |
| 561 | 0 | + callback.getObject().getClass().getName() + "." + callback.getMethod()); |
| 562 | 0 | e.printStackTrace(); |
| 563 | 2 | } |
| 564 | 2 | } |
| 565 | 1 | this.unloadCallbacks.clear(); |
| 566 | 1 | } |
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
void displayDebugParameterValue(String key, String value) { |
| 572 | 13 | if (this.uploadPolicy != null && this.uploadPolicy.getDebugLevel() >= 80) { |
| 573 | 12 | this.uploadPolicy.displayDebug("Parameter '" + key + "' loaded. Value: " + value, 80); |
| 574 | |
} |
| 575 | 13 | } |
| 576 | |
|
| 577 | |
|
| 578 | |
public int parseInt(String value, int def) { |
| 579 | 4 | int ret = def; |
| 580 | |
|
| 581 | |
try { |
| 582 | 4 | ret = Integer.parseInt(value); |
| 583 | 1 | } catch (NumberFormatException e) { |
| 584 | 1 | ret = def; |
| 585 | 1 | if (this.uploadPolicy != null) { |
| 586 | 1 | this.uploadPolicy.displayWarn("Invalid int value: " + value + ", using default value: " + def); |
| 587 | |
} |
| 588 | 3 | } |
| 589 | |
|
| 590 | 4 | return ret; |
| 591 | |
} |
| 592 | |
|
| 593 | |
|
| 594 | |
public float parseFloat(String value, float def) { |
| 595 | 4 | float ret = def; |
| 596 | |
|
| 597 | |
try { |
| 598 | 4 | ret = Float.parseFloat(value); |
| 599 | 1 | } catch (NumberFormatException e) { |
| 600 | 1 | ret = def; |
| 601 | 1 | if (this.uploadPolicy != null) { |
| 602 | 1 | this.uploadPolicy.displayWarn("Invalid float value: " + value + ", using default value: " + def); |
| 603 | |
} |
| 604 | 3 | } |
| 605 | |
|
| 606 | 4 | return ret; |
| 607 | |
} |
| 608 | |
|
| 609 | |
|
| 610 | |
public long parseLong(String value, long def) { |
| 611 | 4 | long ret = def; |
| 612 | |
|
| 613 | |
try { |
| 614 | 4 | ret = Long.parseLong(value); |
| 615 | 1 | } catch (NumberFormatException e) { |
| 616 | 1 | ret = def; |
| 617 | 1 | if (this.uploadPolicy != null) { |
| 618 | 1 | this.uploadPolicy.displayWarn("Invalid long value: " + value + ", using default value: " + def); |
| 619 | |
} |
| 620 | 3 | } |
| 621 | |
|
| 622 | 4 | return ret; |
| 623 | |
} |
| 624 | |
|
| 625 | |
|
| 626 | |
public boolean parseBoolean(String value, boolean def) { |
| 627 | |
|
| 628 | 8 | if (value.toUpperCase().equals("FALSE")) { |
| 629 | 3 | return false; |
| 630 | 5 | } else if (value.toUpperCase().equals("TRUE")) { |
| 631 | 3 | return true; |
| 632 | |
} else { |
| 633 | 2 | if (this.uploadPolicy != null) { |
| 634 | 2 | this.uploadPolicy.displayWarn("Invalid boolean value: " + value + ", using default value: " + def); |
| 635 | |
} |
| 636 | 2 | return def; |
| 637 | |
} |
| 638 | |
} |
| 639 | |
|
| 640 | |
|
| 641 | |
public FileListViewMode parseFileListViewMode(String value, FileListViewMode def) { |
| 642 | 0 | FileListViewMode ret = null; |
| 643 | |
try { |
| 644 | 0 | ret = FileListViewMode.valueOf(value.toUpperCase()); |
| 645 | 0 | } catch (IllegalArgumentException e) { |
| 646 | 0 | ret = def; |
| 647 | 0 | String msg = "Unknown FileListViewMode value '" + value + "'. Using default value: '" + def.toString() |
| 648 | |
+ "'"; |
| 649 | 0 | if (this.uploadPolicy != null) { |
| 650 | 0 | this.uploadPolicy.displayWarn(msg); |
| 651 | |
} else { |
| 652 | 0 | System.out.println(msg); |
| 653 | |
} |
| 654 | 0 | } |
| 655 | 0 | return ret; |
| 656 | |
} |
| 657 | |
|
| 658 | |
|
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
public Cursor setWaitCursor() { |
| 663 | 1 | return setCursor(new Cursor(Cursor.WAIT_CURSOR)); |
| 664 | |
} |
| 665 | |
|
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
public void displayURL(String url, boolean success) { |
| 673 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.displayURL()"); |
| 674 | |
} |
| 675 | |
|
| 676 | |
|
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
public JApplet getApplet() { |
| 682 | 0 | throw new UnsupportedOperationException("DefaultJUploadContext.getApplet()"); |
| 683 | |
} |
| 684 | |
|
| 685 | |
|
| 686 | |
public Frame getFrame() { |
| 687 | 1 | return this.frame; |
| 688 | |
} |
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
|
| 695 | |
public Cursor getCursor() { |
| 696 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.getCursor()"); |
| 697 | |
} |
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
|
| 706 | |
public String getParameter(String key, String def) { |
| 707 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.getParameter(String, String)"); |
| 708 | |
} |
| 709 | |
|
| 710 | |
|
| 711 | |
|
| 712 | |
|
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
public int getParameter(String key, int def) { |
| 718 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.getParameter(String, int))"); |
| 719 | |
} |
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
|
| 727 | |
|
| 728 | |
public float getParameter(String key, float def) { |
| 729 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.getParameter(String, float)"); |
| 730 | |
} |
| 731 | |
|
| 732 | |
|
| 733 | |
|
| 734 | |
|
| 735 | |
|
| 736 | |
|
| 737 | |
|
| 738 | |
|
| 739 | |
public long getParameter(String key, long def) { |
| 740 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.getParameter(String, long)"); |
| 741 | |
} |
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
public boolean getParameter(String key, boolean def) { |
| 751 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.getParameter(String, boolean)"); |
| 752 | |
} |
| 753 | |
|
| 754 | |
|
| 755 | |
|
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
public FileListViewMode getParameter(String key, FileListViewMode def) { |
| 762 | 0 | throw new UnsupportedOperationException("DefaultJUploadContext.getParameter(String, FileListViewMode)"); |
| 763 | |
} |
| 764 | |
|
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
public String normalizeURL(String url) throws JUploadException { |
| 773 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.normalizeURL()"); |
| 774 | |
} |
| 775 | |
|
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
|
| 780 | |
|
| 781 | |
public void readCookieFromNavigator(Vector<String> headers) { |
| 782 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.readCookieFromNavigator()"); |
| 783 | |
} |
| 784 | |
|
| 785 | |
|
| 786 | |
|
| 787 | |
|
| 788 | |
|
| 789 | |
|
| 790 | |
public void readUserAgentFromNavigator(Vector<String> headers) { |
| 791 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.readUserAgentFromNavigator()"); |
| 792 | |
} |
| 793 | |
|
| 794 | |
|
| 795 | |
|
| 796 | |
|
| 797 | |
|
| 798 | |
|
| 799 | |
|
| 800 | |
public Cursor setCursor(Cursor cursor) { |
| 801 | 2 | throw new UnsupportedOperationException("DefaultJUploadContext.setCursor(Cursor)"); |
| 802 | |
} |
| 803 | |
|
| 804 | |
|
| 805 | |
|
| 806 | |
|
| 807 | |
|
| 808 | |
|
| 809 | |
public void showStatus(String status) { |
| 810 | 1 | throw new UnsupportedOperationException("DefaultJUploadContext.showStatus()"); |
| 811 | |
} |
| 812 | |
|
| 813 | |
} |