Changeset 34470 in osm for applications/editors/josm/plugins/sds/src/org
- Timestamp:
- 2018-08-15T02:10:49+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/ReadPostprocessor.java
r33589 r34470 5 5 import java.io.IOException; 6 6 import java.io.InputStream; 7 import java.io.UnsupportedEncodingException;8 7 import java.util.ArrayList; 9 8 … … 19 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 20 19 import org.openstreetmap.josm.io.OsmServerReadPostprocessor; 20 import org.openstreetmap.josm.tools.Logging; 21 21 import org.xml.sax.InputSource; 22 22 import org.xml.sax.SAXException; … … 70 70 rv = api.requestShadowsFromSds(nodeList, wayList, relationList, progress); 71 71 } catch (SdsTransferException e) { 72 // TODO Auto-generated catch block 73 e.printStackTrace(); 72 Logging.error(e); 74 73 } 75 74 … … 82 81 InputSource inputSource = new InputSource(xmlStream); 83 82 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new SdsParser(ds, plugin)); 84 } catch (UnsupportedEncodingException e1) { 85 // TODO Auto-generated catch block 86 e1.printStackTrace(); 87 } catch (SAXException e) { 88 // TODO Auto-generated catch block 89 e.printStackTrace(); 90 } catch (IOException e) { 91 // TODO Auto-generated catch block 92 e.printStackTrace(); 93 } catch (ParserConfigurationException e) { 94 // TODO Auto-generated catch block 95 e.printStackTrace(); 83 } catch (SAXException | IOException | ParserConfigurationException e) { 84 Logging.error(e); 96 85 } 97 86 -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsApi.java
r33969 r34470 20 20 import java.util.List; 21 21 22 import org.openstreetmap.josm.Main;23 22 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 23 import org.openstreetmap.josm.spi.preferences.Config; 24 24 import org.openstreetmap.josm.tools.CheckParameterUtil; 25 25 import org.openstreetmap.josm.tools.Logging; … … 62 62 */ 63 63 public static SdsApi getSdsApi() { 64 String serverUrl = Main.pref.get("sds-server.url", "http://datastore.hotosm.org");64 String serverUrl = Config.getPref().get("sds-server.url", "http://datastore.hotosm.org"); 65 65 if (serverUrl == null) 66 66 throw new IllegalStateException(tr("Preference ''{0}'' missing. Cannot initialize SdsApi.", "sds-server.url")); … … 289 289 */ 290 290 protected int getMaxRetries() { 291 int ret = Main.pref.getInt("osm-server.max-num-retries", DEFAULT_MAX_NUM_RETRIES);291 int ret = Config.getPref().getInt("osm-server.max-num-retries", DEFAULT_MAX_NUM_RETRIES); 292 292 return Math.max(ret, 0); 293 293 } … … 306 306 sendRequest("POST", "createshadows", message, pm); 307 307 } catch (SdsTransferException e) { 308 // TODO Auto-generated catch block 309 e.printStackTrace(); 308 Logging.error(e); 310 309 } 311 310 return true; … … 341 340 System.out.print(requestMethod + " " + url + "... "); 342 341 activeConnection = (HttpURLConnection) url.openConnection(); 343 activeConnection.setConnectTimeout(fastFail ? 1000 : Main.pref.getInt("socket.timeout.connect", 15)*1000);342 activeConnection.setConnectTimeout(fastFail ? 1000 : Config.getPref().getInt("socket.timeout.connect", 15)*1000); 344 343 activeConnection.setRequestMethod(requestMethod); 345 344 if (doAuthenticate) { -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsConnection.java
r33589 r34470 30 30 HttpURLConnection.setFollowRedirects(true); 31 31 } catch (SecurityException e) { 32 e.printStackTrace();32 Logging.error(e); 33 33 } 34 34 } -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsCredentialAgent.java
r33589 r34470 12 12 import javax.swing.text.html.HTMLEditorKit; 13 13 14 import org.openstreetmap.josm.Main;15 14 import org.openstreetmap.josm.data.oauth.OAuthToken; 16 15 import org.openstreetmap.josm.gui.io.CredentialDialog; … … 21 20 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 22 21 import org.openstreetmap.josm.io.auth.CredentialsAgentResponse; 22 import org.openstreetmap.josm.spi.preferences.Config; 23 23 24 24 /** … … 40 40 switch(requestorType) { 41 41 case SERVER: 42 user = Main.pref.get("sds-server.username", null);43 password = Main.pref.get("sds-server.password", null);42 user = Config.getPref().get("sds-server.username", null); 43 password = Config.getPref().get("sds-server.password", null); 44 44 if (user == null) 45 45 return null; 46 46 return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray()); 47 47 case PROXY: 48 user = Main.pref.get(DefaultProxySelector.PROXY_USER, null);49 password = Main.pref.get(DefaultProxySelector.PROXY_PASS, null);48 user = Config.getPref().get(DefaultProxySelector.PROXY_USER, null); 49 password = Config.getPref().get(DefaultProxySelector.PROXY_PASS, null); 50 50 if (user == null) 51 51 return null; … … 64 64 switch(requestorType) { 65 65 case SERVER: 66 Main.pref.put("sds-server.username", credentials.getUserName());66 Config.getPref().put("sds-server.username", credentials.getUserName()); 67 67 if (credentials.getPassword() == null) { 68 Main.pref.put("sds-server.password", null);68 Config.getPref().put("sds-server.password", null); 69 69 } else { 70 Main.pref.put("sds-server.password", String.valueOf(credentials.getPassword()));70 Config.getPref().put("sds-server.password", String.valueOf(credentials.getPassword())); 71 71 } 72 72 break; 73 73 case PROXY: 74 Main.pref.put(DefaultProxySelector.PROXY_USER, credentials.getUserName());74 Config.getPref().put(DefaultProxySelector.PROXY_USER, credentials.getUserName()); 75 75 if (credentials.getPassword() == null) { 76 Main.pref.put(DefaultProxySelector.PROXY_PASS, null);76 Config.getPref().put(DefaultProxySelector.PROXY_PASS, null); 77 77 } else { 78 Main.pref.put(DefaultProxySelector.PROXY_PASS, String.valueOf(credentials.getPassword()));78 Config.getPref().put(DefaultProxySelector.PROXY_PASS, String.valueOf(credentials.getPassword())); 79 79 } 80 80 break; … … 91 91 @Override 92 92 public OAuthToken lookupOAuthAccessToken() throws CredentialsAgentException { 93 String accessTokenKey = Main.pref.get("oauth.access-token.key", null);94 String accessTokenSecret = Main.pref.get("oauth.access-token.secret", null);93 String accessTokenKey = Config.getPref().get("oauth.access-token.key", null); 94 String accessTokenSecret = Config.getPref().get("oauth.access-token.secret", null); 95 95 if (accessTokenKey == null && accessTokenSecret == null) 96 96 return null; -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsDiskAccessAction.java
r32703 r34470 9 9 import javax.swing.filechooser.FileFilter; 10 10 11 import org.openstreetmap.josm.Main;12 11 import org.openstreetmap.josm.actions.DiskAccessAction; 13 12 import org.openstreetmap.josm.gui.ExtendedDialog; 13 import org.openstreetmap.josm.gui.MainApplication; 14 14 import org.openstreetmap.josm.gui.widgets.SwingFileChooser; 15 import org.openstreetmap.josm.spi.preferences.Config; 15 16 import org.openstreetmap.josm.tools.Shortcut; 16 17 … … 24 25 25 26 public static SwingFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) { 26 String curDir = Main.pref.get("lastDirectory");27 String curDir = Config.getPref().get("lastDirectory"); 27 28 if (curDir.equals("")) { 28 29 curDir = "."; … … 49 50 }); 50 51 51 int answer = open ? fc.showOpenDialog(Main .parent) : fc.showSaveDialog(Main.parent);52 int answer = open ? fc.showOpenDialog(MainApplication.getMainFrame()) : fc.showSaveDialog(MainApplication.getMainFrame()); 52 53 if (answer != JFileChooser.APPROVE_OPTION) 53 54 return null; 54 55 55 56 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 56 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());57 Config.getPref().put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 57 58 } 58 59 … … 61 62 if (file != null && file.exists()) { 62 63 ExtendedDialog dialog = new ExtendedDialog( 63 Main .parent,64 MainApplication.getMainFrame(), 64 65 tr("Overwrite"), 65 66 new String[] {tr("Overwrite"), tr("Cancel")} … … 77 78 78 79 public static File createAndOpenSaveFileChooser(String title) { 79 String curDir = Main.pref.get("lastDirectory");80 String curDir = Config.getPref().get("lastDirectory"); 80 81 if (curDir.equals("")) { 81 82 curDir = "."; … … 102 103 }); 103 104 104 int answer = fc.showSaveDialog(Main .parent);105 int answer = fc.showSaveDialog(MainApplication.getMainFrame()); 105 106 if (answer != JFileChooser.APPROVE_OPTION) 106 107 return null; 107 108 108 109 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 109 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());110 Config.getPref().put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 110 111 } 111 112 … … 120 121 if (file == null || (file.exists())) { 121 122 ExtendedDialog dialog = new ExtendedDialog( 122 Main .parent,123 MainApplication.getMainFrame(), 123 124 tr("Overwrite"), 124 125 new String[] {tr("Overwrite"), tr("Cancel")} -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsLoadAction.java
r33589 r34470 9 9 import java.io.IOException; 10 10 import java.io.InputStream; 11 import java.io.UnsupportedEncodingException;12 11 import java.util.ArrayList; 13 12 import java.util.Arrays; … … 21 20 import org.openstreetmap.josm.gui.widgets.SwingFileChooser; 22 21 import org.openstreetmap.josm.io.OsmTransferException; 22 import org.openstreetmap.josm.tools.Logging; 23 23 import org.xml.sax.InputSource; 24 24 import org.xml.sax.SAXException; … … 85 85 InputSource inputSource = new InputSource(fileStream); 86 86 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, p); 87 } catch (UnsupportedEncodingException e1) { 88 // TODO Auto-generated catch block 89 e1.printStackTrace(); 90 } catch (SAXException e) { 91 // TODO Auto-generated catch block 92 e.printStackTrace(); 93 } catch (IOException e) { 94 // TODO Auto-generated catch block 95 e.printStackTrace(); 96 } catch (ParserConfigurationException e) { 97 // TODO Auto-generated catch block 98 e.printStackTrace(); 87 } catch (SAXException | IOException | ParserConfigurationException e) { 88 Logging.error(e); 99 89 } 100 101 90 } 102 91 } -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsMenu.java
r33589 r34470 18 18 import javax.swing.JTextArea; 19 19 20 import org.openstreetmap.josm.Main;21 20 import org.openstreetmap.josm.actions.JosmAction; 22 21 import org.openstreetmap.josm.gui.MainApplication; … … 120 119 about.setPreferredSize(new Dimension(500, 300)); 121 120 122 JOptionPane.showMessageDialog(Main .parent, about, tr("About SDS..."),121 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), about, tr("About SDS..."), 123 122 JOptionPane.INFORMATION_MESSAGE, null); 124 123 } … … 143 142 @Override 144 143 public void run() { 145 PreferenceDialog pd = new PreferenceDialog(Main .parent);144 PreferenceDialog pd = new PreferenceDialog(MainApplication.getMainFrame()); 146 145 // unusual reflection mechanism to cater for older JOSM versions where 147 146 // the selectPreferencesTabByName method was not public -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsPluginPreferences.java
r32705 r34470 18 18 import javax.swing.JTextField; 19 19 20 import org.openstreetmap.josm. Main;20 import org.openstreetmap.josm.gui.MainApplication; 21 21 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; 22 22 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 23 import org.openstreetmap.josm.spi.preferences.Config; 23 24 import org.openstreetmap.josm.tools.GBC; 24 25 … … 46 47 access.setBorder(BorderFactory.createTitledBorder(tr("Server"))); 47 48 48 server.setText( Main.pref.get(SDS_SERVER, "http://datastore.hotosm.org"));49 username.setText( Main.pref.get(SDS_USERNAME, ""));50 password.setText( Main.pref.get(SDS_PASSWORD, ""));51 prefix.setText( Main.pref.get(SDS_PREFIX, "hot:"));49 server.setText(Config.getPref().get(SDS_SERVER, "http://datastore.hotosm.org")); 50 username.setText(Config.getPref().get(SDS_USERNAME, "")); 51 password.setText(Config.getPref().get(SDS_PASSWORD, "")); 52 prefix.setText(Config.getPref().get(SDS_PREFIX, "hot:")); 52 53 server.setToolTipText(tr("The URL under which the SDS server can be contacted.")); 53 54 username.setToolTipText(tr("The user name at the SDS server. You need to create an account with the SDS admin first.")); … … 78 79 public void actionPerformed(ActionEvent ev) { 79 80 SdsApi api = new SdsApi(server.getText()); 80 String olduser = Main.pref.get(SDS_USERNAME);81 String oldpass = Main.pref.get(SDS_PASSWORD);82 Main.pref.put(SDS_USERNAME, username.getText());83 Main.pref.put(SDS_PASSWORD, new String(password.getPassword()));81 String olduser = Config.getPref().get(SDS_USERNAME); 82 String oldpass = Config.getPref().get(SDS_PASSWORD); 83 Config.getPref().put(SDS_USERNAME, username.getText()); 84 Config.getPref().put(SDS_PASSWORD, new String(password.getPassword())); 84 85 try { 85 86 api.requestShadowsFromSds(Collections.singletonList(Long.valueOf(1L)), null, null, null); 86 87 JOptionPane.showMessageDialog( 87 Main .parent,88 MainApplication.getMainFrame(), 88 89 tr("Connection successful."), 89 90 tr("Success"), … … 92 93 } catch (Exception ex) { 93 94 JOptionPane.showMessageDialog( 94 Main .parent,95 MainApplication.getMainFrame(), 95 96 tr("Cannot connect to SDS server: ") + ex.getMessage(), 96 97 tr("Error"), … … 100 101 // restore old credentials even if successful; user might still 101 102 // choose to press cancel! 102 Main.pref.put(SDS_USERNAME, olduser);103 Main.pref.put(SDS_PASSWORD, oldpass);103 Config.getPref().put(SDS_USERNAME, olduser); 104 Config.getPref().put(SDS_PASSWORD, oldpass); 104 105 } 105 106 }); … … 108 109 @Override 109 110 public boolean ok() { 110 Main.pref.put(SDS_SERVER, server.getText());111 Main.pref.put(SDS_USERNAME, username.getText());112 Main.pref.put(SDS_PASSWORD, new String(password.getPassword()));113 Main.pref.put(SDS_PREFIX, prefix.getText());111 Config.getPref().put(SDS_SERVER, server.getText()); 112 Config.getPref().put(SDS_USERNAME, username.getText()); 113 Config.getPref().put(SDS_PASSWORD, new String(password.getPassword())); 114 Config.getPref().put(SDS_PREFIX, prefix.getText()); 114 115 return false; 115 116 } -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsSaveAction.java
r33589 r34470 15 15 import javax.swing.JOptionPane; 16 16 17 import org.openstreetmap.josm.Main;18 17 import org.openstreetmap.josm.data.osm.IPrimitive; 18 import org.openstreetmap.josm.gui.MainApplication; 19 19 import org.openstreetmap.josm.gui.layer.Layer; 20 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.spi.preferences.Config; 21 22 import org.openstreetmap.josm.tools.Logging; 22 23 import org.openstreetmap.josm.tools.Utils; … … 81 82 } 82 83 // FIXME - how to close? 83 if (! Main.pref.getBoolean("save.keepbackup", false) && (tmpFile != null)) {84 if (!Config.getPref().getBoolean("save.keepbackup", false) && (tmpFile != null)) { 84 85 tmpFile.delete(); 85 86 } … … 87 88 Logging.error(e); 88 89 JOptionPane.showMessageDialog( 89 Main .parent,90 MainApplication.getMainFrame(), 90 91 tr("<html>An error occurred while saving.<br>Error is:<br>{0}</html>", e.getMessage()), 91 92 tr("Error"), … … 102 103 Logging.error(e2); 103 104 JOptionPane.showMessageDialog( 104 Main .parent,105 MainApplication.getMainFrame(), 105 106 tr("<html>An error occurred while restoring backup file.<br>Error is:<br>{0}</html>", e2.getMessage()), 106 107 tr("Error"), -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SeparateDataStorePlugin.java
r33217 r34470 7 7 import java.util.Map; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.actions.UploadAction; 11 10 import org.openstreetmap.josm.data.osm.INode; … … 21 20 import org.openstreetmap.josm.plugins.Plugin; 22 21 import org.openstreetmap.josm.plugins.PluginInformation; 22 import org.openstreetmap.josm.spi.preferences.Config; 23 23 24 24 /** … … 89 89 90 90 public String getIgnorePrefix() { 91 return Main.pref.get("sds-server.tag-prefix", "hot:");91 return Config.getPref().get("sds-server.tag-prefix", "hot:"); 92 92 } 93 93
Note:
See TracChangeset
for help on using the changeset viewer.