Changeset 12826 in josm for trunk/src/org
- Timestamp:
- 2017-09-12T00:58:32+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/PreferencesUtils.java
r12634 r12826 23 23 import org.openstreetmap.josm.data.preferences.Setting; 24 24 import org.openstreetmap.josm.data.preferences.StringSetting; 25 import org.openstreetmap.josm.gui.io.CustomConfigurator;26 25 import org.openstreetmap.josm.tools.Logging; 27 26 import org.openstreetmap.josm.tools.Utils; … … 34 33 public final class PreferencesUtils { 35 34 35 private static StringBuilder summary = new StringBuilder(); 36 36 37 private PreferencesUtils() { 37 38 // Hide implicit public constructor for utility class 39 } 40 41 /** 42 * Log a formatted message. 43 * @param fmt format 44 * @param vars arguments 45 * @see String#format 46 * @since 12826 47 */ 48 public static void log(String fmt, Object... vars) { 49 summary.append(String.format(fmt, vars)); 50 } 51 52 /** 53 * Log a message. 54 * @param s message to log 55 * @since 12826 56 */ 57 public static void log(String s) { 58 summary.append(s).append('\n'); 59 } 60 61 /** 62 * Log an exception. 63 * @param e exception to log 64 * @param s message prefix 65 * @since 12826 66 */ 67 public static void log(Exception e, String s) { 68 summary.append(s).append(' ').append(Logging.getErrorMessage(e)).append('\n'); 69 } 70 71 /** 72 * Returns the log. 73 * @return the log 74 * @since 12826 75 */ 76 public static String getLog() { 77 return summary.toString(); 78 } 79 80 /** 81 * Resets the log. 82 * @since 12826 83 */ 84 public static void resetLog() { 85 summary = new StringBuilder(); 38 86 } 39 87 … … 112 160 // remove mentioned items from collection 113 161 for (String item : lSetting.getValue()) { 114 CustomConfigurator.log("Deleting preferences: from list %s: %s\n", key, item);162 log("Deleting preferences: from list %s: %s\n", key, item); 115 163 newItems.remove(item); 116 164 } … … 128 176 if (list.containsAll(removeList)) { 129 177 // remove current list, because it matches search criteria 130 CustomConfigurator.log("Deleting preferences: list from lists %s: %s\n", key, list);178 log("Deleting preferences: list from lists %s: %s\n", key, list); 131 179 listIterator.remove(); 132 180 } … … 146 194 if (map.entrySet().containsAll(removeMap.entrySet())) { 147 195 // the map contain all mentioned key-value pair, so it should be deleted from "maps" 148 CustomConfigurator.log("Deleting preferences: deleting map from maps %s: %s\n", key, map);196 log("Deleting preferences: deleting map from maps %s: %s\n", key, map); 149 197 mapIterator.remove(); 150 198 } … … 161 209 String key = entry.getKey(); 162 210 if (key.matches(pattern)) { 163 CustomConfigurator.log("Deleting preferences: deleting key from preferences: " + key);211 log("Deleting preferences: deleting key from preferences: " + key); 164 212 pref.putSetting(key, null); 165 213 } … … 170 218 Map<String, Setting<?>> allSettings = pref.getAllSettings(); 171 219 if (allSettings.containsKey(key)) { 172 CustomConfigurator.log("Deleting preferences: deleting key from preferences: " + key);220 log("Deleting preferences: deleting key from preferences: " + key); 173 221 pref.putSetting(key, null); 174 222 } … … 218 266 219 267 private static void defaultUnknownWarning(String key) { 220 CustomConfigurator.log("Warning: Unknown default value of %s , skipped\n", key);268 log("Warning: Unknown default value of %s , skipped\n", key); 221 269 JOptionPane.showMessageDialog( 222 270 Main.parent, … … 285 333 " listmapMap.put(key, l);"+ 286 334 " } else {" + 287 " " + CustomConfigurator.class.getName() + ".log('Unknown type:'+val.type+ '- use list, listlist or listmap'); }"+335 " " + PreferencesUtils.class.getName() + ".log('Unknown type:'+val.type+ '- use list, listlist or listmap'); }"+ 288 336 " }"; 289 337 engine.eval(finish); -
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 -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r12634 r12826 39 39 import org.openstreetmap.josm.actions.DiskAccessAction; 40 40 import org.openstreetmap.josm.data.Preferences; 41 import org.openstreetmap.josm.data.PreferencesUtils; 41 42 import org.openstreetmap.josm.data.preferences.Setting; 42 43 import org.openstreetmap.josm.data.preferences.StringSetting; … … 264 265 for (File f : files) { 265 266 CustomConfigurator.readXML(f, tmpPrefs); 266 log.append( CustomConfigurator.getLog());267 log.append(PreferencesUtils.getLog()); 267 268 } 268 269 log.append("</html>");
Note:
See TracChangeset
for help on using the changeset viewer.