Ticket #4421: 4421_argument_v2.patch

File 4421_argument_v2.patch, 4.3 KB (added by simon04, 14 years ago)
  • src/org/openstreetmap/josm/data/CustomConfigurator.java

    diff --git a/src/org/openstreetmap/josm/data/CustomConfigurator.java b/src/org/openstreetmap/josm/data/CustomConfigurator.java
    index e845e2d..98f4488 100644
    a b public class CustomConfigurator {  
    415415       
    416416       
    417417        ScriptEngine engine ;
    418        
     418
    419419        public void openAndReadXML(File file) {
    420420            log("-- Reading custom preferences from " + file.getAbsolutePath() + " --");
    421             InputStream is = null;
    422421            try {
    423                 is = new BufferedInputStream(new FileInputStream(file));
    424422                String fileDir = file.getParentFile().getAbsolutePath();
    425423                if (fileDir!=null) engine.eval("scriptDir='"+normalizeDirName(fileDir) +"';");
     424                openAndReadXML(new BufferedInputStream(new FileInputStream(file)));
     425            } catch (Exception ex) {
     426                log("Error reading custom preferences: " + ex.getMessage());
     427            }
     428        }
     429
     430        public void openAndReadXML(InputStream is) {
     431            try {
    426432                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    427433                builderFactory.setValidating(false);
    428434                builderFactory.setNamespaceAware(true);
  • src/org/openstreetmap/josm/gui/MainApplication.java

    diff --git a/src/org/openstreetmap/josm/gui/MainApplication.java b/src/org/openstreetmap/josm/gui/MainApplication.java
    index 01676f4..1573010 100644
    a b import java.awt.event.WindowEvent;  
    1212import java.io.File;
    1313import java.net.Authenticator;
    1414import java.net.ProxySelector;
     15import java.net.URL;
    1516import java.security.AllPermission;
    1617import java.security.CodeSource;
    1718import java.security.PermissionCollection;
    import javax.swing.SwingUtilities;  
    3031import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
    3132import org.openstreetmap.josm.Main;
    3233import org.openstreetmap.josm.data.AutosaveTask;
     34import org.openstreetmap.josm.data.CustomConfigurator;
    3335import org.openstreetmap.josm.data.Preferences;
    3436import org.openstreetmap.josm.data.Version;
    3537import org.openstreetmap.josm.gui.download.DownloadDialog;
    public class MainApplication extends Main {  
    102104                "\t--selection=<searchstring>                "+tr("Select with the given search")+"\n"+
    103105                "\t--[no-]maximize                           "+tr("Launch in maximized mode")+"\n"+
    104106                "\t--reset-preferences                       "+tr("Reset the preferences to default")+"\n\n"+
     107                "\t--load-preferences=<url-to-xml>           "+tr("Changes preferences according to the XML file")+"\n\n"+
    105108                "\t--set=<key>=<value>                       "+tr("Set preference key to value")+"\n\n"+
    106109                "\t--language=<language>                     "+tr("Set the language")+"\n\n"+
    107110                tr("options provided as Java system properties")+":\n"+
    public class MainApplication extends Main {  
    201204        }
    202205        Main.pref.updateSystemProperties();
    203206
     207        JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
     208        Main.parent = mainFrame;
     209
     210        if (args.containsKey("load-preferences")) {
     211            CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
     212            for (String i : args.get("load-preferences")) {
     213                System.out.println("Reading preferences from " + i);
     214                try {
     215                    URL url = new URL(i);
     216                    config.openAndReadXML(url.openStream());
     217                } catch (Exception ex) {
     218                    throw new RuntimeException(ex);
     219                }
     220            }
     221        }
     222
    204223        if (args.containsKey("set")) {
    205224            for (String i : args.get("set")) {
    206225                String[] kv = i.split("=", 2);
    public class MainApplication extends Main {  
    247266        preConstructorInit(args);
    248267
    249268        monitor.indeterminateSubTask(tr("Creating main GUI"));
    250         JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
    251         Main.parent = mainFrame;
    252269        Main.addListener();
    253270        final Main main = new MainApplication(mainFrame);
    254271