Changeset 12826 in josm for trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java
- Timestamp:
- 2017-09-12T00:58:32+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java
r12634 r12826 66 66 public final class CustomConfigurator { 67 67 68 private static StringBuilder summary = new StringBuilder();69 70 68 private CustomConfigurator() { 71 69 // Hide default constructor for utils classes … … 77 75 * @param vars arguments 78 76 * @see String#format 79 */ 77 * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#log(String, Object...)} instead 78 */ 79 @Deprecated 80 80 public static void log(String fmt, Object... vars) { 81 summary.append(String.format(fmt, vars));81 PreferencesUtils.log(fmt, vars); 82 82 } 83 83 … … 85 85 * Log a message. 86 86 * @param s message to log 87 */ 87 * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#log(String)} instead 88 */ 89 @Deprecated 88 90 public static void log(String s) { 89 summary.append(s).append('\n');91 PreferencesUtils.log(s); 90 92 } 91 93 … … 95 97 * @param s message prefix 96 98 * @since 10469 97 */ 99 * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#log(Exception, String)} instead 100 */ 101 @Deprecated 98 102 public static void log(Exception e, String s) { 99 summary.append(s).append(' ').append(Logging.getErrorMessage(e)).append('\n');103 PreferencesUtils.log(e, s); 100 104 } 101 105 … … 103 107 * Returns the log. 104 108 * @return the log 105 */ 109 * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#getLog()} instead 110 */ 111 @Deprecated 106 112 public static String getLog() { 107 return summary.toString();113 return PreferencesUtils.getLog(); 108 114 } 109 115 110 116 /** 111 117 * Resets the log. 112 */ 118 * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#resetLog()} instead 119 */ 120 @Deprecated 113 121 public static void resetLog() { 114 summary = new StringBuilder();122 PreferencesUtils.resetLog(); 115 123 } 116 124 … … 185 193 186 194 MainApplication.worker.submit(downloadFileTask); 187 log("Info: downloading file from %s to %s in background ", parentDir, fOut.getAbsolutePath());188 if (unzip) log("and unpacking it"); elselog("");195 PreferencesUtils.log("Info: downloading file from %s to %s in background ", parentDir, fOut.getAbsolutePath()); 196 if (unzip) PreferencesUtils.log("and unpacking it"); else PreferencesUtils.log(""); 189 197 190 198 } … … 315 323 String dir = getDirectoryByAbbr(base); 316 324 if (dir == null) { 317 log("Error: Can not find base, use base=cache, base=prefs or base=plugins attribute.");325 PreferencesUtils.log("Error: Can not find base, use base=cache, base=prefs or base=plugins attribute."); 318 326 return; 319 327 } 320 log("Delete file: %s\n", path);328 PreferencesUtils.log("Delete file: %s\n", path); 321 329 if (path.contains("..") || path.startsWith("/") || path.contains(":")) { 322 330 return; // some basic protection … … 338 346 } 339 347 if (!Utils.deleteFile(f)) { 340 log("Warning: Can not delete file "+f.getPath());348 PreferencesUtils.log("Warning: Can not delete file "+f.getPath()); 341 349 } 342 350 } … … 356 364 357 365 if (!installList.isEmpty()) { 358 log("Plugins install: "+installList);366 PreferencesUtils.log("Plugins install: "+installList); 359 367 } 360 368 if (!removeList.isEmpty()) { 361 log("Plugins turn off: "+removeList);369 PreferencesUtils.log("Plugins turn off: "+removeList); 362 370 } 363 371 if (!deleteList.isEmpty()) { 364 log("Plugins delete: "+deleteList);372 PreferencesUtils.log("Plugins delete: "+deleteList); 365 373 } 366 374 … … 437 445 438 446 public void openAndReadXML(File file) { 439 log("-- Reading custom preferences from " + file.getAbsolutePath() + " --");447 PreferencesUtils.log("-- Reading custom preferences from " + file.getAbsolutePath() + " --"); 440 448 try { 441 449 String fileDir = file.getParentFile().getAbsolutePath(); … … 445 453 } 446 454 } catch (ScriptException | IOException | SecurityException ex) { 447 log(ex, "Error reading custom preferences:");455 PreferencesUtils.log(ex, "Error reading custom preferences:"); 448 456 } 449 457 } … … 456 464 } 457 465 } catch (SAXException | IOException | ParserConfigurationException ex) { 458 log(ex, "Error reading custom preferences:");459 } 460 log("-- Reading complete --");466 PreferencesUtils.log(ex, "Error reading custom preferences:"); 467 } 468 PreferencesUtils.log("-- Reading complete --"); 461 469 } 462 470 … … 464 472 try { 465 473 this.mainPrefs = mainPrefs; 466 resetLog();474 PreferencesUtils.resetLog(); 467 475 engine = new ScriptEngineManager().getEngineByName("JavaScript"); 468 476 engine.eval("API={}; API.pref={}; API.fragments={};"); … … 482 490 engine.eval("API.pluginDelete = function(names) { "+className+".pluginOperation('','',names);}"); 483 491 } catch (ScriptException ex) { 484 log("Error: initializing script engine: "+ex.getMessage());492 PreferencesUtils.log("Error: initializing script engine: "+ex.getMessage()); 485 493 Logging.error(ex); 486 494 } … … 540 548 break; 541 549 default: 542 log("Error: Unknown element " + elementName);550 PreferencesUtils.log("Error: Unknown element " + elementName); 543 551 } 544 552 } … … 567 575 // we store this fragment as API.fragments['id'] 568 576 } catch (ScriptException ex) { 569 log(ex, "Error: can not load preferences fragment:");577 PreferencesUtils.log(ex, "Error: can not load preferences fragment:"); 570 578 } 571 579 } 572 580 573 581 if ("replace".equals(oper)) { 574 log("Preferences replace: %d keys: %s\n",582 PreferencesUtils.log("Preferences replace: %d keys: %s\n", 575 583 tmpPref.getAllSettings().size(), tmpPref.getAllSettings().keySet().toString()); 576 584 PreferencesUtils.replacePreferences(tmpPref, mainPrefs); 577 585 } else if ("append".equals(oper)) { 578 log("Preferences append: %d keys: %s\n",586 PreferencesUtils.log("Preferences append: %d keys: %s\n", 579 587 tmpPref.getAllSettings().size(), tmpPref.getAllSettings().keySet().toString()); 580 588 PreferencesUtils.appendPreferences(tmpPref, mainPrefs); … … 594 602 String dir = getDirectoryByAbbr(base); 595 603 if (dir == null) { 596 log("Error: Can not find directory to place file, use base=cache, base=prefs or base=plugins attribute.");604 PreferencesUtils.log("Error: Can not find directory to place file, use base=cache, base=prefs or base=plugins attribute."); 597 605 return; 598 606 } … … 605 613 String address = evalVars(item.getAttribute("url")); 606 614 if (address.isEmpty() || path.isEmpty()) { 607 log("Error: Please specify url=\"where to get file\" and path=\"where to place it\"");615 PreferencesUtils.log("Error: Please specify url=\"where to get file\" and path=\"where to place it\""); 608 616 return; 609 617 } … … 652 660 engine.eval(name+"='"+value+"';"); 653 661 } catch (ScriptException ex) { 654 log(ex, String.format("Error: Can not assign variable: %s=%s :", name, value));662 PreferencesUtils.log(ex, String.format("Error: Can not assign variable: %s=%s :", name, value)); 655 663 } 656 664 } … … 663 671 v = true; 664 672 } else { 665 log("Error: Illegal test expression in if: %s=%s\n", elem.getAttribute("test"), realValue);673 PreferencesUtils.log("Error: Illegal test expression in if: %s=%s\n", elem.getAttribute("test"), realValue); 666 674 } 667 675 … … 679 687 Element task = tasksMap.get(taskName); 680 688 if (task != null) { 681 log("EXECUTING TASK "+taskName);689 PreferencesUtils.log("EXECUTING TASK "+taskName); 682 690 processXmlFragment(task); // process task recursively 683 691 } else { 684 log("Error: Can not execute task "+taskName);692 PreferencesUtils.log("Error: Can not execute task "+taskName); 685 693 return true; 686 694 } … … 690 698 private void processScriptElement(Element elem) { 691 699 String js = elem.getChildNodes().item(0).getTextContent(); 692 log("Processing script...");700 PreferencesUtils.log("Processing script..."); 693 701 try { 694 702 PreferencesUtils.modifyPreferencesByScript(engine, mainPrefs, js); 695 703 } catch (ScriptException ex) { 696 704 messageBox("e", ex.getMessage()); 697 log(ex, "JS error:");698 } 699 log("Script finished");705 PreferencesUtils.log(ex, "JS error:"); 706 } 707 PreferencesUtils.log("Script finished"); 700 708 } 701 709 … … 713 721 mr.appendReplacement(sb, result); 714 722 } catch (ScriptException ex) { 715 log(ex, String.format("Error: Can not evaluate expression %s :", mr.group(1)));723 PreferencesUtils.log(ex, String.format("Error: Can not evaluate expression %s :", mr.group(1))); 716 724 } 717 725 } … … 734 742 tmpPref.fromXML(reader); 735 743 } catch (TransformerException | XMLStreamException | IOException ex) { 736 log(ex, "Error: can not read XML fragment:");744 PreferencesUtils.log(ex, "Error: can not read XML fragment:"); 737 745 } 738 746
Note:
See TracChangeset
for help on using the changeset viewer.