Ticket #4421: 4421_argument.patch

File 4421_argument.patch, 4.6 KB (added by simon04, 12 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 5aa8449..d853b28 100644
    a b public class CustomConfigurator {  
    415415       
    416416       
    417417        ScriptEngine engine ;
    418        
     418
    419419        public void openAndReadXML(File file) {
    420             log("-- Reading custom preferences from " + file.getAbsolutePath() + " --");
    421             InputStream is = null;
    422420            try {
    423                 is = new BufferedInputStream(new FileInputStream(file));
     421                log("-- Reading custom preferences from " + file.getAbsolutePath() + " --");
     422                openAndReadXML(new BufferedInputStream(new FileInputStream(file)));
     423                log("-- Reading complete --");
     424            } catch (IOException ex) {
     425                log("Error reading custom preferences: " + ex.getMessage());
     426            }
     427        }
     428
     429        public void openAndReadXML(InputStream is) {
     430            try {
    424431                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    425432                builderFactory.setValidating(false);
    426433                builderFactory.setNamespaceAware(true);
    public class CustomConfigurator {  
    438445                    }
    439446                } catch (IOException ex) {         }
    440447            }
    441             log("-- Reading complete --");
    442448        }
    443449
    444450        public XMLCommandProcessor(Preferences mainPrefs) {
  • 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..d108c83 100644
    a b import java.awt.event.ActionEvent;  
    1010import java.awt.event.WindowAdapter;
    1111import java.awt.event.WindowEvent;
    1212import java.io.File;
    13 import java.net.Authenticator;
    14 import java.net.ProxySelector;
     13import java.net.*;
    1514import java.security.AllPermission;
    1615import java.security.CodeSource;
    1716import java.security.PermissionCollection;
    import javax.swing.SwingUtilities;  
    3029import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
    3130import org.openstreetmap.josm.Main;
    3231import org.openstreetmap.josm.data.AutosaveTask;
     32import org.openstreetmap.josm.data.CustomConfigurator;
    3333import org.openstreetmap.josm.data.Preferences;
    3434import org.openstreetmap.josm.data.Version;
    3535import org.openstreetmap.josm.gui.download.DownloadDialog;
    public class MainApplication extends Main {  
    102102                "\t--selection=<searchstring>                "+tr("Select with the given search")+"\n"+
    103103                "\t--[no-]maximize                           "+tr("Launch in maximized mode")+"\n"+
    104104                "\t--reset-preferences                       "+tr("Reset the preferences to default")+"\n\n"+
     105                "\t--load-preferences=<url-to-xml>           "+tr("Reset the preferences to default")+"\n\n"+
    105106                "\t--set=<key>=<value>                       "+tr("Set preference key to value")+"\n\n"+
    106107                "\t--language=<language>                     "+tr("Set the language")+"\n\n"+
    107108                tr("options provided as Java system properties")+":\n"+
    public class MainApplication extends Main {  
    201202        }
    202203        Main.pref.updateSystemProperties();
    203204
     205        JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
     206        Main.parent = mainFrame;
     207        if (args.containsKey("load-preferences")) {
     208            CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
     209            for (String i : args.get("load-preferences")) {
     210                System.out.println("Reading preferences from " + i);
     211                try {
     212                    URL url = new URL(i);
     213                    config.openAndReadXML(url.openStream());
     214                } catch (Exception ex) {
     215                    throw new RuntimeException(ex);
     216                }
     217            }
     218        }
     219
    204220        if (args.containsKey("set")) {
    205221            for (String i : args.get("set")) {
    206222                String[] kv = i.split("=", 2);
    public class MainApplication extends Main {  
    247263        preConstructorInit(args);
    248264
    249265        monitor.indeterminateSubTask(tr("Creating main GUI"));
    250         JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
    251         Main.parent = mainFrame;
    252266        Main.addListener();
    253267        final Main main = new MainApplication(mainFrame);
    254268