Changeset 5162 in josm for trunk


Ignore:
Timestamp:
2012-04-04T11:06:00+02:00 (8 years ago)
Author:
akks
Message:

Josm XML-JS configurator, see #4421: bugfixes, JS variables for directories and version

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r5115 r5162  
    228228        try {
    229229            String toXML = Main.pref.toXML(true);
    230             InputStream is = new ByteArrayInputStream(toXML.getBytes());
     230            InputStream is = new ByteArrayInputStream(toXML.getBytes("UTF-8"));
    231231            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    232232            builderFactory.setValidating(false);
     
    422422            try {
    423423                is = new BufferedInputStream(new FileInputStream(file));
     424                String fileDir = file.getParentFile().getAbsolutePath();
     425                if (fileDir!=null) engine.eval("scriptDir='"+normalizeDirName(fileDir) +"';");
    424426                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    425427                builderFactory.setValidating(false);
     
    448450                engine = new ScriptEngineManager().getEngineByName("rhino");
    449451                engine.eval("API={}; API.pref={}; API.fragments={};");
     452               
     453                engine.eval("homeDir='"+normalizeDirName(Main.pref.getPreferencesDir()) +"';");
     454                engine.eval("josmVersion="+Version.getInstance().getVersion()+";");
    450455                String className =  CustomConfigurator.class.getName();
    451456                engine.eval("API.messageBox="+className+".messageBox");
     
    679684         */
    680685        private String evalVars(String s) {
    681             Pattern p = Pattern.compile("\\$\\{(.*)\\}");
     686            Pattern p = Pattern.compile("\\$\\{([^\\}]*)\\}");
    682687            Matcher mr =  p.matcher(s);
    683688            StringBuffer sb = new StringBuffer();
     
    713718
    714719            return tmpPref;
     720        }
     721
     722        private String normalizeDirName(String dir) {
     723            String s = dir.replace("\\", "/");
     724            if (s.endsWith("/")) s=s.substring(0,s.length()-1);
     725            return s;
    715726        }
    716727
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r5115 r5162  
    304304            // plugins preference keys may be changed directly later, after plugins are downloaded
    305305            // so we do not want to show it in the table as "changed" now
    306             loaded.put("plugins", orig.get("plugins"));
     306            Setting pluginSetting = orig.get("plugins");
     307            if (pluginSetting!=null) {
     308                loaded.put("plugins", pluginSetting);
     309            }
    307310        } else {
    308311            loaded = orig;
Note: See TracChangeset for help on using the changeset viewer.