Index: trunk/src/org/openstreetmap/josm/data/PreferencesUtils.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/PreferencesUtils.java	(revision 16328)
+++ trunk/src/org/openstreetmap/josm/data/PreferencesUtils.java	(revision 16329)
@@ -7,13 +7,9 @@
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.TreeMap;
-
-import javax.script.ScriptEngine;
-import javax.script.ScriptException;
+
 import javax.swing.JOptionPane;
 
@@ -30,5 +26,4 @@
 /**
  * Helper class to do specific Preferences operation - appending, replacing, deletion by key and by value
- * Also contains functions that convert preferences object to JavaScript object and back
  * @since 12634 (extracted from {@code CustomConfigurator})
  */
@@ -282,201 +277,4 @@
     }
 
-    public static void modifyPreferencesByScript(ScriptEngine engine, Preferences tmpPref, String js) throws ScriptException {
-        loadPrefsToJS(engine, tmpPref, "API.pref", true);
-        engine.eval(js);
-        readPrefsFromJS(engine, tmpPref, "API.pref");
-    }
-
-    /**
-     * Convert JavaScript preferences object to preferences data structures
-     * @param engine - JS engine to put object
-     * @param tmpPref - preferences to fill from JS
-     * @param varInJS - JS variable name, where preferences are stored
-     * @throws ScriptException if the evaluation fails
-     */
-    public static void readPrefsFromJS(ScriptEngine engine, Preferences tmpPref, String varInJS) throws ScriptException {
-        String finish =
-            "stringMap = new java.util.TreeMap ;"+
-            "listMap =  new java.util.TreeMap ;"+
-            "listlistMap = new java.util.TreeMap ;"+
-            "listmapMap =  new java.util.TreeMap ;"+
-            "for (key in "+varInJS+") {"+
-            "  val = "+varInJS+"[key];"+
-            "  type = typeof val == 'string' ? 'string' : val.type;"+
-            "  if (type == 'string') {"+
-            "    stringMap.put(key, val);"+
-            "  } else if (type == 'list') {"+
-            "    l = new java.util.ArrayList;"+
-            "    for (i=0; i<val.length; i++) {"+
-            "      l.add(java.lang.String.valueOf(val[i]));"+
-            "    }"+
-            "    listMap.put(key, l);"+
-            "  } else if (type == 'listlist') {"+
-            "    l = new java.util.ArrayList;"+
-            "    for (i=0; i<val.length; i++) {"+
-            "      list=val[i];"+
-            "      jlist=new java.util.ArrayList;"+
-            "      for (j=0; j<list.length; j++) {"+
-            "         jlist.add(java.lang.String.valueOf(list[j]));"+
-            "      }"+
-            "      l.add(jlist);"+
-            "    }"+
-            "    listlistMap.put(key, l);"+
-            "  } else if (type == 'listmap') {"+
-            "    l = new java.util.ArrayList;"+
-            "    for (i=0; i<val.length; i++) {"+
-            "      map=val[i];"+
-            "      jmap=new java.util.TreeMap;"+
-            "      for (var key2 in map) {"+
-            "         jmap.put(key2,java.lang.String.valueOf(map[key2]));"+
-            "      }"+
-            "      l.add(jmap);"+
-            "    }"+
-            "    listmapMap.put(key, l);"+
-            "  }  else {" +
-            "   " + PreferencesUtils.class.getName() + ".log('Unknown type:'+val.type+ '- use list, listlist or listmap'); }"+
-            "  }";
-        engine.eval(finish);
-
-        @SuppressWarnings("unchecked")
-        Map<String, String> stringMap = (Map<String, String>) engine.get("stringMap");
-        @SuppressWarnings("unchecked")
-        Map<String, List<String>> listMap = (Map<String, List<String>>) engine.get("listMap");
-        @SuppressWarnings("unchecked")
-        Map<String, List<Collection<String>>> listlistMap = (Map<String, List<Collection<String>>>) engine.get("listlistMap");
-        @SuppressWarnings("unchecked")
-        Map<String, List<Map<String, String>>> listmapMap = (Map<String, List<Map<String, String>>>) engine.get("listmapMap");
-
-        tmpPref.settingsMap.clear();
-
-        Map<String, Setting<?>> tmp = new HashMap<>();
-        for (Entry<String, String> e : stringMap.entrySet()) {
-            tmp.put(e.getKey(), new StringSetting(e.getValue()));
-        }
-        for (Entry<String, List<String>> e : listMap.entrySet()) {
-            tmp.put(e.getKey(), new ListSetting(e.getValue()));
-        }
-
-        for (Entry<String, List<Collection<String>>> e : listlistMap.entrySet()) {
-            @SuppressWarnings({ "unchecked", "rawtypes" })
-            List<List<String>> value = (List) e.getValue();
-            tmp.put(e.getKey(), new ListListSetting(value));
-        }
-        for (Entry<String, List<Map<String, String>>> e : listmapMap.entrySet()) {
-            tmp.put(e.getKey(), new MapListSetting(e.getValue()));
-        }
-        for (Entry<String, Setting<?>> e : tmp.entrySet()) {
-            if (e.getValue().equals(tmpPref.defaultsMap.get(e.getKey()))) continue;
-            tmpPref.settingsMap.put(e.getKey(), e.getValue());
-        }
-    }
-
-    /**
-     * Convert preferences data structures to JavaScript object
-     * @param engine - JS engine to put object
-     * @param tmpPref - preferences to convert
-     * @param whereToPutInJS - variable name to store preferences in JS
-     * @param includeDefaults - include known default values to JS objects
-     * @throws ScriptException if the evaluation fails
-     */
-    public static void loadPrefsToJS(ScriptEngine engine, Preferences tmpPref, String whereToPutInJS, boolean includeDefaults)
-            throws ScriptException {
-        Map<String, String> stringMap = new TreeMap<>();
-        Map<String, List<String>> listMap = new TreeMap<>();
-        Map<String, List<List<String>>> listlistMap = new TreeMap<>();
-        Map<String, List<Map<String, String>>> listmapMap = new TreeMap<>();
-
-        if (includeDefaults) {
-            for (Map.Entry<String, Setting<?>> e: tmpPref.defaultsMap.entrySet()) {
-                Setting<?> setting = e.getValue();
-                if (setting instanceof StringSetting) {
-                    stringMap.put(e.getKey(), ((StringSetting) setting).getValue());
-                } else if (setting instanceof ListSetting) {
-                    listMap.put(e.getKey(), ((ListSetting) setting).getValue());
-                } else if (setting instanceof ListListSetting) {
-                    listlistMap.put(e.getKey(), ((ListListSetting) setting).getValue());
-                } else if (setting instanceof MapListSetting) {
-                    listmapMap.put(e.getKey(), ((MapListSetting) setting).getValue());
-                }
-            }
-        }
-        tmpPref.settingsMap.entrySet().removeIf(e -> e.getValue().getValue() == null);
-
-        for (Map.Entry<String, Setting<?>> e: tmpPref.settingsMap.entrySet()) {
-            Setting<?> setting = e.getValue();
-            if (setting instanceof StringSetting) {
-                stringMap.put(e.getKey(), ((StringSetting) setting).getValue());
-            } else if (setting instanceof ListSetting) {
-                listMap.put(e.getKey(), ((ListSetting) setting).getValue());
-            } else if (setting instanceof ListListSetting) {
-                listlistMap.put(e.getKey(), ((ListListSetting) setting).getValue());
-            } else if (setting instanceof MapListSetting) {
-                listmapMap.put(e.getKey(), ((MapListSetting) setting).getValue());
-            }
-        }
-
-        engine.put("stringMap", stringMap);
-        engine.put("listMap", listMap);
-        engine.put("listlistMap", listlistMap);
-        engine.put("listmapMap", listmapMap);
-
-        String init =
-            "function getJSList( javaList ) {"+
-            " var jsList; var i; "+
-            " if (javaList == null) return null;"+
-            "jsList = [];"+
-            "  for (i = 0; i < javaList.size(); i++) {"+
-            "    jsList.push(String(list.get(i)));"+
-            "  }"+
-            "return jsList;"+
-            "}"+
-            "function getJSMap( javaMap ) {"+
-            " var jsMap; var it; var e; "+
-            " if (javaMap == null) return null;"+
-            " jsMap = {};"+
-            " for (it = javaMap.entrySet().iterator(); it.hasNext();) {"+
-            "    e = it.next();"+
-            "    jsMap[ String(e.getKey()) ] = String(e.getValue()); "+
-            "  }"+
-            "  return jsMap;"+
-            "}"+
-            "for (it = stringMap.entrySet().iterator(); it.hasNext();) {"+
-            "  e = it.next();"+
-            whereToPutInJS+"[String(e.getKey())] = String(e.getValue());"+
-            "}\n"+
-            "for (it = listMap.entrySet().iterator(); it.hasNext();) {"+
-            "  e = it.next();"+
-            "  list = e.getValue();"+
-            "  jslist = getJSList(list);"+
-            "  jslist.type = 'list';"+
-            whereToPutInJS+"[String(e.getKey())] = jslist;"+
-            "}\n"+
-            "for (it = listlistMap.entrySet().iterator(); it.hasNext(); ) {"+
-            "  e = it.next();"+
-            "  listlist = e.getValue();"+
-            "  jslistlist = [];"+
-            "  for (it2 = listlist.iterator(); it2.hasNext(); ) {"+
-            "    list = it2.next(); "+
-            "    jslistlist.push(getJSList(list));"+
-            "    }"+
-            "  jslistlist.type = 'listlist';"+
-            whereToPutInJS+"[String(e.getKey())] = jslistlist;"+
-            "}\n"+
-            "for (it = listmapMap.entrySet().iterator(); it.hasNext();) {"+
-            "  e = it.next();"+
-            "  listmap = e.getValue();"+
-            "  jslistmap = [];"+
-            "  for (it2 = listmap.iterator(); it2.hasNext();) {"+
-            "    map = it2.next();"+
-            "    jslistmap.push(getJSMap(map));"+
-            "    }"+
-            "  jslistmap.type = 'listmap';"+
-            whereToPutInJS+"[String(e.getKey())] = jslistmap;"+
-            "}\n";
-
-        // Execute conversion script
-        engine.eval(init);
-    }
-
     /**
      * Gets an boolean that may be specialized
Index: trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java	(revision 16328)
+++ trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java	(revision 16329)
@@ -25,6 +25,4 @@
 import java.util.regex.Pattern;
 
-import javax.script.ScriptEngine;
-import javax.script.ScriptException;
 import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
@@ -386,8 +384,7 @@
         private Preferences mainPrefs;
         private final Map<String, Element> tasksMap = new HashMap<>();
+        private final Map<String, String> environment = new HashMap<>();
 
         private boolean lastV; // last If condition result
-
-        private ScriptEngine engine;
 
         public void openAndReadXML(File file) {
@@ -395,9 +392,9 @@
             try {
                 String fileDir = file.getParentFile().getAbsolutePath();
-                if (fileDir != null) engine.eval("scriptDir='"+normalizeDirName(fileDir) +"';");
+                environment.put("scriptDir", normalizeDirName(fileDir));
                 try (InputStream is = Files.newInputStream(file.toPath())) {
                     openAndReadXML(is);
                 }
-            } catch (ScriptException | IOException | SecurityException | InvalidPathException ex) {
+            } catch (IOException | SecurityException | InvalidPathException ex) {
                 PreferencesUtils.log(ex, "Error reading custom preferences:");
             }
@@ -417,30 +414,8 @@
 
         public XMLCommandProcessor(Preferences mainPrefs) {
-            try {
-                this.mainPrefs = mainPrefs;
-                PreferencesUtils.resetLog();
-                engine = Utils.getJavaScriptEngine();
-                if (engine == null) {
-                    throw new ScriptException("Failed to retrieve JavaScript engine");
-                }
-                engine.eval("API={}; API.pref={}; API.fragments={};");
-
-                engine.eval("homeDir='"+normalizeDirName(Config.getDirs().getPreferencesDirectory(false).getAbsolutePath()) +"';");
-                engine.eval("josmVersion="+Version.getInstance().getVersion()+';');
-                String className = CustomConfigurator.class.getName();
-                engine.eval("API.messageBox="+className+".messageBox");
-                engine.eval("API.askText=function(text) { return String("+className+".askForText(text));}");
-                engine.eval("API.askOption="+className+".askForOption");
-                engine.eval("API.downloadFile="+className+".downloadFile");
-                engine.eval("API.downloadAndUnpackFile="+className+".downloadAndUnpackFile");
-                engine.eval("API.deleteFile="+className+".deleteFile");
-                engine.eval("API.plugin ="+className+".pluginOperation");
-                engine.eval("API.pluginInstall = function(names) { "+className+".pluginOperation(names,'','');}");
-                engine.eval("API.pluginUninstall = function(names) { "+className+".pluginOperation('',names,'');}");
-                engine.eval("API.pluginDelete = function(names) { "+className+".pluginOperation('','',names);}");
-            } catch (ScriptException ex) {
-                PreferencesUtils.log("Error: initializing script engine: "+ex.getMessage());
-                Logging.error(ex);
-            }
+            this.mainPrefs = mainPrefs;
+            PreferencesUtils.resetLog();
+            setVar("homeDir", normalizeDirName(Config.getDirs().getPreferencesDirectory(false).getAbsolutePath()));
+            setVar("josmVersion", String.valueOf(Version.getInstance().getVersion()));
         }
 
@@ -494,7 +469,4 @@
                     processDeleteElement(elem);
                     break;
-                case "script":
-                    processScriptElement(elem);
-                    break;
                 default:
                     PreferencesUtils.log("Error: Unknown element " + elementName);
@@ -517,15 +489,4 @@
             Preferences tmpPref = readPreferencesFromDOMElement(item);
             PreferencesUtils.showPrefs(tmpPref);
-
-            if (!id.isEmpty()) {
-                try {
-                    String fragmentVar = "API.fragments['"+id+"']";
-                    engine.eval(fragmentVar+"={};");
-                    PreferencesUtils.loadPrefsToJS(engine, tmpPref, fragmentVar, false);
-                    // we store this fragment as API.fragments['id']
-                } catch (ScriptException ex) {
-                    PreferencesUtils.log(ex, "Error: can not load preferences fragment:");
-                }
-            }
 
             if ("replace".equals(oper)) {
@@ -607,9 +568,5 @@
 
         public void setVar(String name, String value) {
-            try {
-                engine.eval(name+"='"+value+"';");
-            } catch (ScriptException ex) {
-                PreferencesUtils.log(ex, String.format("Error: Can not assign variable: %s=%s :", name, value));
-            }
+            environment.put(name, value);
         }
 
@@ -646,16 +603,4 @@
         }
 
-        private void processScriptElement(Element elem) {
-            String js = elem.getChildNodes().item(0).getTextContent();
-            PreferencesUtils.log("Processing script...");
-            try {
-                PreferencesUtils.modifyPreferencesByScript(engine, mainPrefs, js);
-            } catch (ScriptException ex) {
-                messageBox("e", ex.getMessage());
-                PreferencesUtils.log(ex, "JS error:");
-            }
-            PreferencesUtils.log("Script finished");
-        }
-
         /**
          * substitute ${expression} = expression evaluated by JavaScript
@@ -664,13 +609,10 @@
          */
         private String evalVars(String s) {
-            Matcher mr = Pattern.compile("\\$\\{([^\\}]*)\\}").matcher(s);
+            Matcher mr = Pattern.compile("\\$\\{(?<identifier>[^\\}]*)\\}").matcher(s);
             StringBuffer sb = new StringBuffer();
             while (mr.find()) {
-                try {
-                    String result = engine.eval(mr.group(1)).toString();
-                    mr.appendReplacement(sb, result);
-                } catch (ScriptException ex) {
-                    PreferencesUtils.log(ex, String.format("Error: Can not evaluate expression %s :", mr.group(1)));
-                }
+                String identifier = mr.group("identifier");
+                String value = environment.get(identifier);
+                mr.appendReplacement(sb, String.valueOf(value));
             }
             mr.appendTail(sb);
