Ignore:
Timestamp:
2017-09-12T00:58:32+02:00 (20 months ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - remove GUI references from PreferencesUtils

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java

    r12634 r12826  
    6666public final class CustomConfigurator {
    6767
    68     private static StringBuilder summary = new StringBuilder();
    69 
    7068    private CustomConfigurator() {
    7169        // Hide default constructor for utils classes
     
    7775     * @param vars arguments
    7876     * @see String#format
    79      */
     77     * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#log(String, Object...)} instead
     78     */
     79    @Deprecated
    8080    public static void log(String fmt, Object... vars) {
    81         summary.append(String.format(fmt, vars));
     81        PreferencesUtils.log(fmt, vars);
    8282    }
    8383
     
    8585     * Log a message.
    8686     * @param s message to log
    87      */
     87     * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#log(String)} instead
     88     */
     89    @Deprecated
    8890    public static void log(String s) {
    89         summary.append(s).append('\n');
     91        PreferencesUtils.log(s);
    9092    }
    9193
     
    9597     * @param s message prefix
    9698     * @since 10469
    97      */
     99     * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#log(Exception, String)} instead
     100     */
     101    @Deprecated
    98102    public static void log(Exception e, String s) {
    99         summary.append(s).append(' ').append(Logging.getErrorMessage(e)).append('\n');
     103        PreferencesUtils.log(e, s);
    100104    }
    101105
     
    103107     * Returns the log.
    104108     * @return the log
    105      */
     109     * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#getLog()} instead
     110     */
     111    @Deprecated
    106112    public static String getLog() {
    107         return summary.toString();
     113        return PreferencesUtils.getLog();
    108114    }
    109115
    110116    /**
    111117     * Resets the log.
    112      */
     118     * @deprecated to be removed end of 2017. Use {@link PreferencesUtils#resetLog()} instead
     119     */
     120    @Deprecated
    113121    public static void resetLog() {
    114         summary = new StringBuilder();
     122        PreferencesUtils.resetLog();
    115123    }
    116124
     
    185193
    186194        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"); else log("");
     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("");
    189197
    190198    }
     
    315323        String dir = getDirectoryByAbbr(base);
    316324        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.");
    318326            return;
    319327        }
    320         log("Delete file: %s\n", path);
     328        PreferencesUtils.log("Delete file: %s\n", path);
    321329        if (path.contains("..") || path.startsWith("/") || path.contains(":")) {
    322330            return; // some basic protection
     
    338346        }
    339347        if (!Utils.deleteFile(f)) {
    340             log("Warning: Can not delete file "+f.getPath());
     348            PreferencesUtils.log("Warning: Can not delete file "+f.getPath());
    341349        }
    342350    }
     
    356364
    357365        if (!installList.isEmpty()) {
    358             log("Plugins install: "+installList);
     366            PreferencesUtils.log("Plugins install: "+installList);
    359367        }
    360368        if (!removeList.isEmpty()) {
    361             log("Plugins turn off: "+removeList);
     369            PreferencesUtils.log("Plugins turn off: "+removeList);
    362370        }
    363371        if (!deleteList.isEmpty()) {
    364             log("Plugins delete: "+deleteList);
     372            PreferencesUtils.log("Plugins delete: "+deleteList);
    365373        }
    366374
     
    437445
    438446        public void openAndReadXML(File file) {
    439             log("-- Reading custom preferences from " + file.getAbsolutePath() + " --");
     447            PreferencesUtils.log("-- Reading custom preferences from " + file.getAbsolutePath() + " --");
    440448            try {
    441449                String fileDir = file.getParentFile().getAbsolutePath();
     
    445453                }
    446454            } catch (ScriptException | IOException | SecurityException ex) {
    447                 log(ex, "Error reading custom preferences:");
     455                PreferencesUtils.log(ex, "Error reading custom preferences:");
    448456            }
    449457        }
     
    456464                }
    457465            } 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 --");
    461469        }
    462470
     
    464472            try {
    465473                this.mainPrefs = mainPrefs;
    466                 resetLog();
     474                PreferencesUtils.resetLog();
    467475                engine = new ScriptEngineManager().getEngineByName("JavaScript");
    468476                engine.eval("API={}; API.pref={}; API.fragments={};");
     
    482490                engine.eval("API.pluginDelete = function(names) { "+className+".pluginOperation('','',names);}");
    483491            } catch (ScriptException ex) {
    484                 log("Error: initializing script engine: "+ex.getMessage());
     492                PreferencesUtils.log("Error: initializing script engine: "+ex.getMessage());
    485493                Logging.error(ex);
    486494            }
     
    540548                    break;
    541549                default:
    542                     log("Error: Unknown element " + elementName);
     550                    PreferencesUtils.log("Error: Unknown element " + elementName);
    543551                }
    544552            }
     
    567575                    // we store this fragment as API.fragments['id']
    568576                } catch (ScriptException ex) {
    569                     log(ex, "Error: can not load preferences fragment:");
     577                    PreferencesUtils.log(ex, "Error: can not load preferences fragment:");
    570578                }
    571579            }
    572580
    573581            if ("replace".equals(oper)) {
    574                 log("Preferences replace: %d keys: %s\n",
     582                PreferencesUtils.log("Preferences replace: %d keys: %s\n",
    575583                   tmpPref.getAllSettings().size(), tmpPref.getAllSettings().keySet().toString());
    576584                PreferencesUtils.replacePreferences(tmpPref, mainPrefs);
    577585            } else if ("append".equals(oper)) {
    578                 log("Preferences append: %d keys: %s\n",
     586                PreferencesUtils.log("Preferences append: %d keys: %s\n",
    579587                   tmpPref.getAllSettings().size(), tmpPref.getAllSettings().keySet().toString());
    580588                PreferencesUtils.appendPreferences(tmpPref, mainPrefs);
     
    594602            String dir = getDirectoryByAbbr(base);
    595603            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.");
    597605                return;
    598606            }
     
    605613            String address = evalVars(item.getAttribute("url"));
    606614            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\"");
    608616                return;
    609617            }
     
    652660                engine.eval(name+"='"+value+"';");
    653661            } 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));
    655663            }
    656664        }
     
    663671                v = true;
    664672            } 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);
    666674            }
    667675
     
    679687            Element task = tasksMap.get(taskName);
    680688            if (task != null) {
    681                 log("EXECUTING TASK "+taskName);
     689                PreferencesUtils.log("EXECUTING TASK "+taskName);
    682690                processXmlFragment(task); // process task recursively
    683691            } else {
    684                 log("Error: Can not execute task "+taskName);
     692                PreferencesUtils.log("Error: Can not execute task "+taskName);
    685693                return true;
    686694            }
     
    690698        private void processScriptElement(Element elem) {
    691699            String js = elem.getChildNodes().item(0).getTextContent();
    692             log("Processing script...");
     700            PreferencesUtils.log("Processing script...");
    693701            try {
    694702                PreferencesUtils.modifyPreferencesByScript(engine, mainPrefs, js);
    695703            } catch (ScriptException ex) {
    696704                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");
    700708        }
    701709
     
    713721                    mr.appendReplacement(sb, result);
    714722                } 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)));
    716724                }
    717725            }
     
    734742                tmpPref.fromXML(reader);
    735743            } catch (TransformerException | XMLStreamException | IOException ex) {
    736                 log(ex, "Error: can not read XML fragment:");
     744                PreferencesUtils.log(ex, "Error: can not read XML fragment:");
    737745            }
    738746
Note: See TracChangeset for help on using the changeset viewer.