Changeset 32703 in osm for applications/editors/josm/plugins/sds/src/org/openstreetmap
- Timestamp:
- 2016-07-23T23:41:17+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/DetermineSdsModificationsUploadHook.java
r30738 r32703 1 // License: GPL. See LICENSE file for details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 16 16 /** 17 17 * This upload hook does the following things: 18 * 19 * 1. Find out if there are any changes in the special tags that need to 18 * 19 * 1. Find out if there are any changes in the special tags that need to 20 20 * be uploaded to a different server. 21 * 2. Find out if any objects that did have special tags have now been 21 * 2. Find out if any objects that did have special tags have now been 22 22 * deleted, resulting in tag deletions on the special server. 23 23 * 3. Find out if any objects carrying special tags have been newly created. 24 24 * 4. Also, if it is determined that an object modification consists exclusively 25 * of special tags, then skip uploading that object, by removing it from 25 * of special tags, then skip uploading that object, by removing it from 26 26 * the apiDataSet. 27 * 27 * 28 28 * This upload hook stores its findings with the SeparateDataStorePlugin, and 29 29 * changes are sent to the SDS server only after the OSM upload has sucessfully 30 30 * completed. The UploadSuccessHook is responsible for that. 31 31 */ 32 public class DetermineSdsModificationsUploadHook implements UploadHook 33 { 32 public class DetermineSdsModificationsUploadHook implements UploadHook { 34 33 private SeparateDataStorePlugin plugin; 35 34 36 DetermineSdsModificationsUploadHook(SeparateDataStorePlugin plugin) 35 DetermineSdsModificationsUploadHook(SeparateDataStorePlugin plugin) { 37 36 this.plugin = plugin; 38 37 } 39 38 39 @Override 40 40 public boolean checkUpload(APIDataSet apiDataSet) { 41 41 42 42 ArrayList<OsmPrimitive> droplist = new ArrayList<>(); 43 43 44 44 // check deleted primitives for special tags. 45 45 for (OsmPrimitive del : apiDataSet.getPrimitivesToDelete()) { … … 53 53 // check modified primitives. 54 54 for (OsmPrimitive upd : apiDataSet.getPrimitivesToUpdate()) { 55 55 56 56 HashSet<String> allKeys = new HashSet<>(); 57 57 boolean specialTags = false; 58 58 59 59 // process tags of new object 60 60 for (String key : upd.keySet()) { … … 62 62 if (!specialTags && isSpecialKey(key)) specialTags = true; 63 63 } 64 64 65 65 // process tags of old object 66 66 IPrimitive old = plugin.getOriginalPrimitive(upd); … … 72 72 // if neither has special tags, done with this object. 73 73 if (!specialTags) continue; 74 74 75 75 // special tags are involved. find out what, exactly, has changed. 76 76 boolean changeInSpecialTags = false; … … 82 82 } 83 83 } 84 84 85 85 // change *only* in standard tags - done with this object. 86 86 if (!changeInSpecialTags) continue; 87 87 88 88 // assemble new set of special tags. might turn out to be empty. 89 89 HashMap<String, String> newSpecialTags = new HashMap<>(); … … 91 91 if (isSpecialKey(key)) newSpecialTags.put(key, upd.get(key)); 92 92 } 93 93 94 94 boolean uploadToOsm = changeInOtherTags; 95 96 // not done yet: if no changes in standard tags, we need to find out if 95 96 // not done yet: if no changes in standard tags, we need to find out if 97 97 // there were changes in the other properties (node: lat/lon, way/relation: 98 // member list). If the answer is no, then the object must be removed from 98 // member list). If the answer is no, then the object must be removed from 99 99 // JOSM's normal upload queue, else we would be uploading a non-edit. 100 100 if (!changeInOtherTags) { … … 111 111 uploadToOsm = true; 112 112 break; 113 } 113 } 114 114 for (int i = 0; i < wold.getNodesCount(); i++) { 115 115 if (wold.getNodeId(i) != wupd.getNodeId(i)) { … … 122 122 IRelation rold = (IRelation) old; 123 123 IRelation rupd = (IRelation) upd; 124 if (rold.getMembersCount() != rupd.getMembersCount()) {124 if (rold.getMembersCount() != rupd.getMembersCount()) { 125 125 uploadToOsm = true; 126 126 break; 127 } 127 } 128 128 for (int i = 0; i < rold.getMembersCount(); i++) { 129 129 if (rold.getMemberType(i) != rupd.getMemberType(i) || … … 136 136 } 137 137 } 138 138 139 139 // request that new set of special tags be uploaded 140 140 plugin.enqueueForUpload(upd, newSpecialTags, !uploadToOsm); 141 142 // we cannot remove from getPrimitivesToUpdate, this would result in a 141 142 // we cannot remove from getPrimitivesToUpdate, this would result in a 143 143 // ConcurrentModificationException. 144 144 if (!uploadToOsm) droplist.add(upd); 145 145 146 146 } 147 147 148 148 apiDataSet.getPrimitivesToUpdate().removeAll(droplist); 149 150 // check added primitives. 149 150 // check added primitives. 151 151 for (OsmPrimitive add : apiDataSet.getPrimitivesToAdd()) { 152 152 // assemble new set of special tags. might turn out to be empty. … … 157 157 if (!newSpecialTags.isEmpty()) plugin.enqueueForUpload(add, newSpecialTags, false); 158 158 } 159 159 160 160 // FIXME it is possible that the list of OSM edits is totally empty. 161 161 return true; 162 162 163 163 } 164 164 165 165 boolean hasSpecialTags(IPrimitive p) { 166 166 for (String key : p.keySet()) { 167 167 if (isSpecialKey(key)) return true; 168 } 168 } 169 169 return false; 170 170 } 171 171 172 172 boolean isSpecialKey(String key) { 173 173 return key.startsWith(plugin.getIgnorePrefix()); -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/ReadPostprocessor.java
r30738 r32703 24 24 25 25 public class ReadPostprocessor implements OsmServerReadPostprocessor { 26 26 27 27 private ArrayList<Long> nodeList; 28 28 private ArrayList<Long> wayList; 29 29 private ArrayList<Long> relationList; 30 30 31 31 private SeparateDataStorePlugin plugin; 32 32 … … 34 34 this.plugin = plugin; 35 35 } 36 36 37 37 @Override 38 38 public void postprocessDataSet(DataSet ds, ProgressMonitor progress) { 39 39 40 40 nodeList = new ArrayList<>(); 41 41 wayList = new ArrayList<>(); … … 48 48 plugin.originalNodes.put(n.getId(), n.save()); 49 49 } 50 50 51 @Override 51 52 public void visit(Way w) { … … 53 54 plugin.originalWays.put(w.getId(), w.save()); 54 55 } 56 55 57 @Override 56 58 public void visit(Relation e) { … … 58 60 plugin.originalNodes.put(e.getId(), e.save()); 59 61 } 62 60 63 @Override 61 64 public void visit(Changeset cs) {} 62 65 }; 63 66 64 67 for (OsmPrimitive p : ds.allPrimitives()) { 65 68 p.accept(adder); 66 69 } 67 70 68 71 SdsApi api = SdsApi.getSdsApi(); 69 72 String rv = ""; … … 74 77 e.printStackTrace(); 75 78 } 76 77 // this is slightly inefficient, as we're re-making the string into 79 80 // this is slightly inefficient, as we're re-making the string into 78 81 // an input stream when there was an input stream to be had inside the 79 82 // SdsApi already, but this encapsulates things better. -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsApi.java
r31152 r32703 1 // License: GPL. See README for details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 38 38 public class SdsApi extends SdsConnection { 39 39 /** max number of retries to send a request in case of HTTP 500 errors or timeouts */ 40 static public final int DEFAULT_MAX_NUM_RETRIES = 5;40 public static final int DEFAULT_MAX_NUM_RETRIES = 5; 41 41 42 42 /** the collection of instantiated OSM APIs */ … … 51 51 * 52 52 */ 53 static public SdsApi getSdsApi(String serverUrl) {53 public static SdsApi getSdsApi(String serverUrl) { 54 54 SdsApi api = instances.get(serverUrl); 55 55 if (api == null) { 56 56 api = new SdsApi(serverUrl); 57 instances.put(serverUrl, api);57 instances.put(serverUrl, api); 58 58 } 59 59 return api; 60 60 } 61 61 62 /** 62 63 * replies the {@see OsmApi} for the URL given by the preference <code>sds-server.url</code> … … 65 66 * 66 67 */ 67 static public SdsApi getSdsApi() {68 public static SdsApi getSdsApi() { 68 69 String serverUrl = Main.pref.get("sds-server.url", "http://datastore.hotosm.org"); 69 70 if (serverUrl == null) … … 86 87 * @exception IllegalArgumentException thrown, if serverUrl is null 87 88 */ 88 protected SdsApi(String serverUrl) 89 protected SdsApi(String serverUrl) { 89 90 CheckParameterUtil.ensureParameterNotNull(serverUrl, "serverUrl"); 90 91 this.serverUrl = serverUrl; … … 98 99 return version; 99 100 } 100 101 101 102 102 /** … … 113 113 // this works around a ruby (or lighttpd) bug where two consecutive slashes in 114 114 // an URL will cause a "404 not found" response. 115 int p; while ((p = rv.indexOf("//", 6)) > -1) { rv.delete(p, p + 1); } 115 int p; 116 while ((p = rv.indexOf("//", 6)) > -1) { 117 rv.delete(p, p + 1); 118 } 116 119 return rv.toString(); 117 120 } 118 121 119 /* *122 /* 120 123 * Creates an OSM primitive on the server. The OsmPrimitive object passed in 121 124 * is modified by giving it the server-assigned id. … … 123 126 * @param osm the primitive 124 127 * @throws SdsTransferException if something goes wrong 125 126 128 public void createPrimitive(IPrimitive osm, ProgressMonitor monitor) throws SdsTransferException { 127 129 String ret = ""; … … 132 134 osm.setOsmId(Long.parseLong(ret.trim()), 1); 133 135 osm.setChangesetId(getChangeset().getId()); 134 } catch (NumberFormatException e){136 } catch (NumberFormatException e){ 135 137 throw new SdsTransferException(tr("Unexpected format of ID replied by the server. Got ''{0}''.", ret)); 136 138 } … … 138 140 */ 139 141 140 /* *142 /* 141 143 * Modifies an OSM primitive on the server. 142 144 * … … 144 146 * @param monitor the progress monitor 145 147 * @throws SdsTransferException if something goes wrong 146 147 148 public void modifyPrimitive(IPrimitive osm, ProgressMonitor monitor) throws SdsTransferException { 148 149 String ret = null; … … 155 156 osm.setChangesetId(getChangeset().getId()); 156 157 osm.setVisible(true); 157 } catch (NumberFormatException e) {158 } catch (NumberFormatException e) { 158 159 throw new SdsTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret)); 159 160 } … … 161 162 */ 162 163 163 /* *164 /* 164 165 * Deletes an OSM primitive on the server. 165 166 * @param osm the primitive 166 167 * @throws SdsTransferException if something goes wrong 167 168 168 public void deletePrimitive(IPrimitive osm, ProgressMonitor monitor) throws SdsTransferException { 169 169 ensureValidChangeset(); … … 177 177 */ 178 178 179 /* *179 /* 180 180 * Uploads a list of changes in "diff" form to the server. 181 181 * … … 186 186 * @throws SdsTransferException 187 187 * @throws SdsTransferException if something is wrong 188 189 188 public Collection<IPrimitive> uploadDiff(Collection<? extends IPrimitive> list, ProgressMonitor monitor) throws SdsTransferException { 190 189 try { … … 218 217 monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false) 219 218 ); 220 } catch (SdsTransferException e) {219 } catch (SdsTransferException e) { 221 220 throw e; 222 } catch (OsmDataParsingException e) {221 } catch (OsmDataParsingException e) { 223 222 throw new SdsTransferException(e); 224 223 } finally { … … 228 227 */ 229 228 230 public String requestShadowsFromSds(List<Long> nodes, List<Long> ways, List<Long> relations, ProgressMonitor pm) throws SdsTransferException { 229 public String requestShadowsFromSds(List<Long> nodes, List<Long> ways, List<Long> relations, ProgressMonitor pm) 230 throws SdsTransferException { 231 231 232 232 StringBuilder request = new StringBuilder(); … … 268 268 } 269 269 270 return sendRequest("POST", "collectshadows", request.toString(), pm ,true); 271 270 return sendRequest("POST", "collectshadows", request.toString(), pm, true); 272 271 } 273 272 274 273 private void sleepAndListen(int retry, ProgressMonitor monitor) throws SdsTransferException { 275 274 System.out.print(tr("Waiting 10 seconds ... ")); 276 for (int i=0; i < 10; i++) {275 for (int i = 0; i < 10; i++) { 277 276 if (monitor != null) { 278 monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry, getMaxRetries(), 10-i));277 monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry, getMaxRetries(), 10-i)); 279 278 } 280 279 if (cancel) … … 282 281 try { 283 282 Thread.sleep(1000); 284 } catch (InterruptedException ex) {} 283 } catch (InterruptedException ex) { 284 Main.trace(ex); 285 } 285 286 } 286 287 System.out.println(tr("OK - trying again.")); … … 294 295 protected int getMaxRetries() { 295 296 int ret = Main.pref.getInteger("osm-server.max-num-retries", DEFAULT_MAX_NUM_RETRIES); 296 return Math.max(ret, 0);297 return Math.max(ret, 0); 297 298 } 298 299 … … 301 302 } 302 303 303 private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, boolean doAuth) throws SdsTransferException { 304 private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, boolean doAuth) 305 throws SdsTransferException { 304 306 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, doAuth, false); 305 307 } … … 334 336 * been exhausted), or rewrapping a Java exception. 335 337 */ 336 private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, boolean doAuthenticate, boolean fastFail) throws SdsTransferException { 338 private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, 339 boolean doAuthenticate, boolean fastFail) throws SdsTransferException { 337 340 StringBuffer responseBody = new StringBuffer(); 338 341 int retries = getMaxRetries(); 339 342 340 while (true) { // the retry loop343 while (true) { // the retry loop 341 344 try { 342 345 URL url = new URL(new URL(getBaseUrl()), urlSuffix); 343 346 System.out.print(requestMethod + " " + url + "... "); 344 activeConnection = (HttpURLConnection) url.openConnection();345 activeConnection.setConnectTimeout(fastFail ? 1000 : Main.pref.getInteger("socket.timeout.connect", 15)*1000);347 activeConnection = (HttpURLConnection) url.openConnection(); 348 activeConnection.setConnectTimeout(fastFail ? 1000 : Main.pref.getInteger("socket.timeout.connect", 15)*1000); 346 349 activeConnection.setRequestMethod(requestMethod); 347 350 if (doAuthenticate) { … … 375 378 if (retries-- > 0) { 376 379 sleepAndListen(retries, monitor); 377 System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries, getMaxRetries()));380 System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries, getMaxRetries())); 378 381 continue; 379 382 } … … 398 401 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 399 402 String s; 400 while ((s = in.readLine()) != null) {403 while ((s = in.readLine()) != null) { 401 404 responseBody.append(s); 402 405 responseBody.append("\n"); … … 408 411 errorHeader = activeConnection.getHeaderField("Error"); 409 412 System.err.println("Error header: " + errorHeader); 410 } else if (retCode != 200 && responseBody.length() >0) {413 } else if (retCode != 200 && responseBody.length() > 0) { 411 414 System.err.println("Error body: " + responseBody); 412 415 } 413 416 activeConnection.disconnect(); 414 417 415 errorHeader = errorHeader == null ? null : errorHeader.trim();416 String errorBody = responseBody.length() == 0 ? null : responseBody.toString().trim();418 errorHeader = errorHeader == null ? null : errorHeader.trim(); 419 String errorBody = responseBody.length() == 0 ? null : responseBody.toString().trim(); 417 420 switch(retCode) { 418 421 case HttpURLConnection.HTTP_OK: … … 435 438 } 436 439 throw new SdsTransferException(e); 437 } catch (IOException e){440 } catch (IOException e) { 438 441 throw new SdsTransferException(e); 439 } catch (SdsTransferException e) {442 } catch (SdsTransferException e) { 440 443 throw e; 441 444 } … … 449 452 try { 450 453 url = new URL(urlStr.replace(" ", "%20")); 451 } catch (MalformedURLException e) {454 } catch (MalformedURLException e) { 452 455 throw new SdsTransferException(e); 453 456 } 454 457 try { 455 activeConnection = (HttpURLConnection) url.openConnection();456 } catch (Exception e) {458 activeConnection = (HttpURLConnection) url.openConnection(); 459 } catch (Exception e) { 457 460 throw new SdsTransferException(tr("Failed to open connection to API {0}.", url.toExternalForm()), e); 458 461 } … … 470 473 } 471 474 472 activeConnection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect", 15)*1000);475 activeConnection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect", 15)*1000); 473 476 474 477 try { … … 481 484 try { 482 485 if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) 483 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, null,null);486 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, null, null); 484 487 485 488 if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH) … … 490 493 String errorHeader = activeConnection.getHeaderField("Error"); 491 494 StringBuilder errorBody = new StringBuilder(); 492 try 493 { 495 try { 494 496 InputStream i = FixEncoding(activeConnection.getErrorStream(), encoding); 495 497 if (i != null) { 496 498 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 497 499 String s; 498 while ((s = in.readLine()) != null) {500 while ((s = in.readLine()) != null) { 499 501 errorBody.append(s); 500 502 errorBody.append("\n"); 501 503 } 502 504 } 503 } 504 catch(Exception e) { 505 } catch (Exception e) { 505 506 errorBody.append(tr("Reading error text failed.")); 506 507 } … … 510 511 511 512 return FixEncoding(new ProgressInputStream(activeConnection, progressMonitor), encoding); 512 } catch (Exception e) {513 } catch (Exception e) { 513 514 if (e instanceof SdsTransferException) 514 throw (SdsTransferException) e;515 throw (SdsTransferException) e; 515 516 else 516 517 throw new SdsTransferException(e); … … 522 523 } 523 524 524 private InputStream FixEncoding(InputStream stream, String encoding) throws IOException 525 { 525 private InputStream FixEncoding(InputStream stream, String encoding) throws IOException { 526 526 if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 527 527 stream = new GZIPInputStream(stream); 528 } 529 else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { 528 } else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { 530 529 stream = new InflaterInputStream(stream, new Inflater(true)); 531 530 } 532 531 return stream; 533 532 } 534 535 536 533 } -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsConnection.java
r32702 r32703 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 7 7 import java.util.Base64; 8 8 9 import org.openstreetmap.josm.Main; 9 10 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 10 11 import org.openstreetmap.josm.io.auth.CredentialsAgentResponse; … … 13 14 * Base class that handles common things like authentication for the reader and writer 14 15 * to the SDS server. 15 * 16 * 16 17 * Modeled after JOSM's OsmConnection class. 17 18 */ 18 19 public class SdsConnection { 19 20 20 21 protected boolean cancel = false; 21 22 protected HttpURLConnection activeConnection; 22 23 private SdsCredentialAgent credAgent = new SdsCredentialAgent(); 23 24 24 25 /** 25 26 * Initialize the http defaults and the authenticator. … … 44 45 Thread.sleep(100); 45 46 } catch (InterruptedException ex) { 47 Main.trace(ex); 46 48 } 47 49 … … 63 65 String token; 64 66 try { 65 response = credAgent.getCredentials(RequestorType.SERVER, con.getURL().getHost(), false /* don't know yet whether the credentials will succeed */); 67 response = credAgent.getCredentials(RequestorType.SERVER, con.getURL().getHost(), 68 false /* don't know yet whether the credentials will succeed */); 66 69 } catch (CredentialsAgentException e) { 67 70 throw new SdsTransferException(e); … … 73 76 return; 74 77 } else { 75 String username = response.getUsername() == null ? "" : response.getUsername();78 String username = response.getUsername() == null ? "" : response.getUsername(); 76 79 String password = response.getPassword() == null ? "" : String.valueOf(response.getPassword()); 77 80 token = username + ":" + password; … … 88 91 * 89 92 * @return true if this connection is canceled 90 * @return91 93 */ 92 94 public boolean isCanceled() { -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsCredentialAgent.java
r30738 r32703 23 23 24 24 /** 25 * Factored after JOSM's JosmPreferencesCredentialAgent. 25 * Factored after JOSM's JosmPreferencesCredentialAgent. 26 26 */ 27 27 public class SdsCredentialAgent extends AbstractCredentialsAgent { … … 33 33 */ 34 34 @Override 35 public PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException {35 public PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException { 36 36 if (requestorType == null) 37 37 return null; … … 101 101 public Component getPreferencesDecorationPanel() { 102 102 HtmlPanel pnlMessage = new HtmlPanel(); 103 HTMLEditorKit kit = (HTMLEditorKit)pnlMessage.getEditorPane().getEditorKit(); 104 kit.getStyleSheet().addRule(".warning-body {background-color:rgb(253,255,221);padding: 10pt; border-color:rgb(128,128,128);border-style: solid;border-width: 1px;}"); 103 HTMLEditorKit kit = (HTMLEditorKit) pnlMessage.getEditorPane().getEditorKit(); 104 kit.getStyleSheet().addRule( 105 ".warning-body {background-color:rgb(253,255,221);padding: 10pt; " + 106 "border-color:rgb(128,128,128);border-style: solid;border-width: 1px;}"); 105 107 pnlMessage.setText( 106 108 tr( … … 114 116 return pnlMessage; 115 117 } 116 118 117 119 @Override 118 120 public String getSaveUsernameAndPasswordCheckboxText() { … … 124 126 throws CredentialsAgentException { 125 127 // no-op 126 127 } 128 129 @Override 130 public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException{ 128 129 } 130 131 @Override 132 public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) 133 throws CredentialsAgentException { 131 134 if (requestorType == null) 132 135 return null; 133 PasswordAuthentication credentials = 136 PasswordAuthentication credentials = lookup(requestorType, host); 134 137 String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName(); 135 138 String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword()); … … 158 161 CredentialDialog dialog = null; 159 162 switch(requestorType) { 160 case SERVER: dialog = SdsCredentialDialog.getSdsApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 161 case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break; 163 case SERVER: 164 dialog = SdsCredentialDialog.getSdsApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); 165 break; 166 case PROXY: 167 dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); 168 break; 162 169 } 163 170 dialog.setVisible(true); … … 190 197 return response; 191 198 } 192 199 193 200 } -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsCredentialDialog.java
r30738 r32703 11 11 public class SdsCredentialDialog extends CredentialDialog { 12 12 13 static public SdsCredentialDialog getSdsApiCredentialDialog(String username, String password, String host, String saveUsernameAndPasswordCheckboxText) { 13 public static SdsCredentialDialog getSdsApiCredentialDialog(String username, String password, String host, 14 String saveUsernameAndPasswordCheckboxText) { 14 15 SdsCredentialDialog dialog = new SdsCredentialDialog(saveUsernameAndPasswordCheckboxText); 15 16 dialog.prepareForSdsApiCredentials(username, password); … … 23 24 super(saveUsernameAndPasswordCheckboxText); 24 25 } 25 26 26 27 public void prepareForSdsApiCredentials(String username, String password) { 27 28 setTitle(tr("Enter credentials for Separate Data Store API")); … … 30 31 validate(); 31 32 } 32 33 33 34 private static class SdsApiCredentialsPanel extends CredentialPanel { 34 35 … … 44 45 } 45 46 46 publicSdsApiCredentialsPanel(SdsCredentialDialog owner) {47 SdsApiCredentialsPanel(SdsCredentialDialog owner) { 47 48 super(owner); 48 49 build(); 49 50 } 50 51 } 51 52 } 52 } -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsDiskAccessAction.java
r30738 r32703 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.hot.sds; 2 3 … … 16 17 @SuppressWarnings("serial") 17 18 public abstract class SdsDiskAccessAction extends DiskAccessAction { 18 19 19 20 public SdsDiskAccessAction(String name, String iconName, String tooltip, 20 21 Shortcut shortcut) { … … 35 36 fc.setMultiSelectionEnabled(multiple); 36 37 fc.setAcceptAllFileFilterUsed(false); 37 38 38 39 fc.setFileFilter(new FileFilter() { 39 public boolean accept(File pathname) { return pathname.getName().endsWith(".sds") || pathname.isDirectory(); } 40 public String getDescription() { return (tr("SDS data file")); } 41 }); 40 @Override 41 public boolean accept(File pathname) { 42 return pathname.getName().endsWith(".sds") || pathname.isDirectory(); 43 } 44 45 @Override 46 public String getDescription() { 47 return (tr("SDS data file")); 48 } 49 }); 42 50 43 51 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent); … … 81 89 fc.setMultiSelectionEnabled(false); 82 90 fc.setAcceptAllFileFilterUsed(false); 83 91 84 92 fc.setFileFilter(new FileFilter() { 85 public boolean accept(File pathname) { return pathname.getName().endsWith(".sds") || pathname.isDirectory(); } 86 public String getDescription() { return (tr("SDS data file")); } 87 }); 88 93 @Override 94 public boolean accept(File pathname) { 95 return pathname.getName().endsWith(".sds") || pathname.isDirectory(); 96 } 97 98 @Override 99 public String getDescription() { 100 return (tr("SDS data file")); 101 } 102 }); 103 89 104 int answer = fc.showSaveDialog(Main.parent); 90 105 if (answer != JFileChooser.APPROVE_OPTION) … … 101 116 return file; 102 117 } 103 118 104 119 public static boolean confirmOverwrite(File file) { 105 120 if (file == null || (file.exists())) { -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsLoadAction.java
r32480 r32703 1 // License: GPL.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 26 26 @SuppressWarnings("serial") 27 27 public class SdsLoadAction extends SdsDiskAccessAction { 28 28 29 29 private SeparateDataStorePlugin plugin; 30 30 … … 33 33 plugin = p; 34 34 } 35 35 36 @Override 36 37 public void actionPerformed(ActionEvent e) { 37 38 SwingFileChooser fc = createAndOpenFileChooser(true, true, null); -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsMenu.java
r32480 r32703 1 // License: GPL. See README for details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 52 52 aboutItem = new JMenuItem(new SdsAboutAction()); 53 53 menu.add(aboutItem); 54 54 55 55 Main.getLayerManager().addLayerChangeListener(this); 56 56 Main.getLayerManager().addActiveLayerChangeListener(this); … … 63 63 saveItem.setEnabled(en); 64 64 } 65 65 66 66 @Override 67 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { setEnabledState(); } 67 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 68 setEnabledState(); 69 } 68 70 69 71 @Override … … 71 73 72 74 @Override 73 public void layerAdded(LayerAddEvent e) { setEnabledState(); } 75 public void layerAdded(LayerAddEvent e) { 76 setEnabledState(); 77 } 74 78 75 79 @Override 76 public void layerRemoving(LayerRemoveEvent e) { setEnabledState(); } 80 public void layerRemoving(LayerRemoveEvent e) { 81 setEnabledState(); 82 } 77 83 78 84 private class SdsAboutAction extends JosmAction { 79 85 80 publicSdsAboutAction() {86 SdsAboutAction() { 81 87 super(tr("About"), "sds", tr("Information about SDS."), null, true); 82 88 } 83 89 90 @Override 84 91 public void actionPerformed(ActionEvent e) { 85 92 JPanel about = new JPanel(); … … 89 96 l.setWrapStyleWord(true); 90 97 l.setEditable(false); 91 l.setText("Separate Data Store\n\nThis plugin provides access to a \"Separate Data Store\" server. " + 92 "Whenever data is loaded from the OSM API, it queries the SDS for additional tags that have been stored for the objects just loaded, " + 93 "and adds these tags. When you upload data to JOSM, SDS tags will again be separated and, instead of sending them to OSM, they will be uplaoded to SDS." + 94 "\n\n" + 95 "This depends on SDS tags starting with a special prefix, which can be configured in the SDS preferences." + 96 "\n\n" + 97 "Using the SDS server will usually require an account to be set up there, which is completely independent of your OSM account."); 98 99 l.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 98 l.setText( 99 "Separate Data Store\n\nThis plugin provides access to a \"Separate Data Store\" server. " + 100 "Whenever data is loaded from the OSM API, " + 101 "it queries the SDS for additional tags that have been stored for the objects just loaded, " + 102 "and adds these tags. When you upload data to JOSM, SDS tags will again be separated and, " + 103 "instead of sending them to OSM, they will be uploaded to SDS." + 104 "\n\n" + 105 "This depends on SDS tags starting with a special prefix, which can be configured in the SDS preferences." + 106 "\n\n" + 107 "Using the SDS server will usually require an account to be set up there, which is completely independent of your OSM account."); 108 109 l.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 100 110 l.setOpaque(false); 101 l.setPreferredSize(new Dimension(500, 300));111 l.setPreferredSize(new Dimension(500, 300)); 102 112 JScrollPane sp = new JScrollPane(l); 103 113 sp.setBorder(null); 104 114 sp.setOpaque(false); 105 115 106 116 about.add(sp); 107 108 about.setPreferredSize(new Dimension(500, 300));117 118 about.setPreferredSize(new Dimension(500, 300)); 109 119 110 120 JOptionPane.showMessageDialog(Main.parent, about, tr("About SDS..."), … … 112 122 } 113 123 } 114 115 private class SdsPreferencesAction extends JosmAction implements Runnable {124 125 private final class SdsPreferencesAction extends JosmAction implements Runnable { 116 126 117 127 private SdsPreferencesAction() { … … 124 134 * Launch the preferences dialog. 125 135 */ 136 @Override 126 137 public void actionPerformed(ActionEvent e) { 127 138 run(); 128 139 } 129 140 141 @Override 130 142 public void run() { 131 143 PreferenceDialog pd = new PreferenceDialog(Main.parent); 132 // unusual reflection mechanism to cater for older JOSM versions where 144 // unusual reflection mechanism to cater for older JOSM versions where 133 145 // the selectPreferencesTabByName method was not public 134 146 try { … … 136 148 sptbn.invoke(pd, "sds"); 137 149 } catch (Exception ex) { 138 // ignore150 Main.trace(ex); 139 151 } 140 152 pd.setVisible(true); 141 153 } 142 154 } 143 144 145 155 } -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsOsmWriter.java
r30738 r32703 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 17 17 * sure that special tags are never written to JOSM's standard 18 18 * output channels. 19 * 19 * 20 20 * In the context of HOT's separate data store, this is very 21 21 * important as otherwise private/confidential information could 22 22 * end up on public servers. 23 * 23 * 24 24 * @author Frederik Ramm 25 25 * … … 28 28 29 29 private SeparateDataStorePlugin plugin; 30 30 31 31 public SdsOsmWriter(SeparateDataStorePlugin plugin, PrintWriter out, boolean osmConform, String version) { 32 32 super(out, osmConform, version); … … 45 45 String key = e.getKey(); 46 46 if (!(osm instanceof Changeset) && ("created_by".equals(key))) continue; 47 if (key.startsWith(plugin.getIgnorePrefix())) continue; 47 if (key.startsWith(plugin.getIgnorePrefix())) continue; 48 48 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) + 49 49 "' v='"+XmlWriter.encode(e.getValue())+ "' />"); -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsParser.java
r30738 r32703 11 11 /** 12 12 * Parser for answers from SDS. These anwers look like this: 13 * 13 * 14 14 * <pre> 15 15 <?xml version="1.0" encoding="UTF-8"?> … … 24 24 * @author Frederik Ramm 25 25 */ 26 public class SdsParser extends DefaultHandler 27 { 26 public class SdsParser extends DefaultHandler { 28 27 private DataSet dataSet; 29 28 private OsmPrimitive currentPrimitive; 30 29 private SeparateDataStorePlugin plugin; 31 30 private boolean ensureMatch; 32 31 33 32 public SdsParser(DataSet ds, SeparateDataStorePlugin p, boolean ensureMatch) { 34 33 this.dataSet = ds; … … 36 35 this.ensureMatch = ensureMatch; 37 36 } 38 37 39 38 public SdsParser(DataSet ds, SeparateDataStorePlugin p) { 40 39 this(ds, p, true); 41 40 } 42 43 @Override public void endElement(String namespaceURI, String localName, String qName) 44 { 41 42 @Override public void endElement(String namespaceURI, String localName, String qName) { 45 43 // after successfully reading a full set of tags from the separate data store, 46 44 // update it in our cache so we can determine changes later. … … 49 47 } 50 48 } 51 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException 52 { 53 if ("osm_shadow".equals(qName)) 54 { 49 50 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 51 if ("osm_shadow".equals(qName)) { 55 52 String type = atts.getValue("osm_type"); 56 String id = atts.getValue("osm_id"); 53 String id = atts.getValue("osm_id"); 57 54 currentPrimitive = dataSet.getPrimitiveById(Long.parseLong(id), OsmPrimitiveType.fromApiTypeName(type)); 58 55 if (currentPrimitive == null && ensureMatch) { 59 56 throw new SAXException("unexpected object in response"); 60 57 } 61 } 62 else if ("tag".equals(qName)) 63 { 58 } else if ("tag".equals(qName)) { 64 59 String v = atts.getValue("v"); 65 60 String k = atts.getValue("k"); -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsPluginPreferences.java
r30738 r32703 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.hot.sds; 2 3 … … 33 34 private final JPasswordField password = new JPasswordField(8); 34 35 private final JTextField prefix = new JTextField(8); 35 36 36 37 public SdsPluginPreferences() { 37 38 super("sds", tr("Separate Data Store"), tr("Configures access to the Separate Data Store.")); 38 39 } 40 39 41 @Override 40 42 public void addGui(final PreferenceTabbedPane gui) { 41 43 final JPanel tab = gui.createPreferenceTab(this); 42 44 43 45 final JPanel access = new JPanel(new GridBagLayout()); 44 46 access.setBorder(BorderFactory.createTitledBorder(tr("Server"))); … … 54 56 55 57 access.add(new JLabel(tr("SDS server URL")), GBC.std()); 56 access.add(server, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0,0,5));58 access.add(server, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 57 59 58 60 access.add(new JLabel(tr("SDS username")), GBC.std()); 59 access.add(username, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0,0,5));61 access.add(username, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 60 62 61 63 access.add(new JLabel(tr("SDS password")), GBC.std()); 62 access.add(password, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0,0,5));64 access.add(password, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 63 65 64 66 JButton test = new JButton(tr("Test credentials now")); 65 access.add(test, GBC.eol().anchor(GBC.EAST).insets(5, 0,0,5));67 access.add(test, GBC.eol().anchor(GBC.EAST).insets(5, 0, 0, 5)); 66 68 67 69 tab.add(access, GBC.eol().fill(GBC.HORIZONTAL)); 68 70 69 71 tab.add(new JLabel(tr("SDS tag prefix")), GBC.std()); 70 tab.add(prefix, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0,0,5));72 tab.add(prefix, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 71 73 72 74 tab.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 73 75 74 76 test.addActionListener(new ActionListener() { 77 @Override 75 78 public void actionPerformed(ActionEvent ev) { 76 79 SdsApi api = new SdsApi(server.getText()); … … 87 90 JOptionPane.PLAIN_MESSAGE 88 91 ); 89 } catch (Exception ex) {92 } catch (Exception ex) { 90 93 JOptionPane.showMessageDialog( 91 94 Main.parent, 92 tr("Cannot connect to SDS server: ") + ex.getMessage(), 95 tr("Cannot connect to SDS server: ") + ex.getMessage(), 93 96 tr("Error"), 94 97 JOptionPane.ERROR_MESSAGE 95 98 ); 96 99 } 97 // restore old credentials even if successful; user might still 100 // restore old credentials even if successful; user might still 98 101 // choose to press cancel! 99 102 Main.pref.put(SDS_USERNAME, olduser); -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsSaveAction.java
r32329 r32703 1 // License: GPL.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsWriter.java
r30738 r32703 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 24 24 out.print("<osm_sds>"); 25 25 } 26 26 27 public void footer() { 27 28 out.println("</osm_sds>"); 28 29 } 29 30 30 public void write(IPrimitive what, Map<String, String> tags) {31 public void write(IPrimitive what, Map<String, String> tags) { 31 32 out.print("<osm_shadow osm_type=\""); 32 33 out.print(what.getType().getAPIName()); … … 34 35 out.print(what.getId()); 35 36 out.println("\">"); 36 37 37 38 if (tags != null) { 38 for (Entry<String,String> e : tags.entrySet()) {39 for (Entry<String, String> e : tags.entrySet()) { 39 40 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) + 40 41 "' v='"+XmlWriter.encode(e.getValue())+ "' />"); 41 42 } 42 43 } 43 44 44 45 out.println("</osm_shadow>"); 45 46 } 46 47 48 @Override 47 49 public void close() { 48 50 out.close(); -
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SeparateDataStorePlugin.java
r30738 r32703 1 // License: GPL. See LICENSE file for details.1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.hot.sds; 3 3 … … 24 24 * Plugin that loads extra data from HOT separate data store. 25 25 * 26 * @author Frederik Ramm <frederik.ramm@geofabrik.de>26 * @author Frederik Ramm <frederik.ramm@geofabrik.de> 27 27 */ 28 public class SeparateDataStorePlugin extends Plugin 29 { 28 public class SeparateDataStorePlugin extends Plugin { 30 29 31 30 public HashMap<Long, IPrimitive> originalNodes = new HashMap<>(); 32 31 public HashMap<Long, IPrimitive> originalWays = new HashMap<>(); 33 32 public HashMap<Long, IPrimitive> originalRelations = new HashMap<>(); 34 33 35 34 public ArrayList<QueueItem> uploadQueue = new ArrayList<>(); 36 35 37 36 private PrimitiveVisitor learnVisitor = new PrimitiveVisitor() { 38 public void visit(INode i) { originalNodes.put(i.getId(), i); } 39 public void visit(IWay i) { originalWays.put(i.getId(), i); } 40 public void visit(IRelation i) { originalRelations.put(i.getId(), i); } 37 @Override 38 public void visit(INode i) { 39 originalNodes.put(i.getId(), i); 40 } 41 42 @Override 43 public void visit(IWay i) { 44 originalWays.put(i.getId(), i); 45 } 46 47 @Override 48 public void visit(IRelation i) { 49 originalRelations.put(i.getId(), i); 50 } 41 51 }; 42 52 43 53 class QueueItem { 44 54 public IPrimitive primitive; 45 public HashMap<String, String> tags;55 public HashMap<String, String> tags; 46 56 public boolean sdsOnly; 47 57 public boolean processed; 48 public QueueItem(IPrimitive p, HashMap<String,String> t, boolean s) {58 QueueItem(IPrimitive p, HashMap<String, String> t, boolean s) { 49 59 primitive = p; 50 60 tags = t; … … 53 63 } 54 64 } 55 65 56 66 /** 57 67 * Creates the plugin 58 68 */ 59 public SeparateDataStorePlugin(PluginInformation info) 60 { 69 public SeparateDataStorePlugin(PluginInformation info) { 61 70 super(info); 62 71 System.out.println("initializing SDS plugin"); 63 72 64 73 // this lets us see what JOSM load from the server, and augment it with our data: 65 74 OsmReader.registerPostprocessor(new ReadPostprocessor(this)); 66 75 67 76 // this makes sure that our data is never written to the OSM server on a low level; 68 77 OsmWriterFactory.theFactory = new SdsOsmWriterFactory(this); 69 78 70 79 // this lets us see what JOSM is planning to upload, and prepare our own uploads 71 80 // accordingly 72 81 UploadAction.registerUploadHook(new DetermineSdsModificationsUploadHook(this)); 73 82 74 83 // this lets us perform our own uploads after JOSM has succeeded: 75 84 OsmServerWriter.registerPostprocessor(new WritePostprocessor(this)); … … 82 91 return Main.pref.get("sds-server.tag-prefix", "hot:"); 83 92 } 84 93 85 94 public IPrimitive getOriginalPrimitive(IPrimitive other) { 86 95 switch (other.getType()) { … … 89 98 case RELATION: return originalRelations.get(other.getId()); 90 99 } 91 return null; 100 return null; 92 101 } 93 102 94 103 protected void enqueueForUpload(IPrimitive prim, HashMap<String, String> tags, boolean onlySds) { 95 104 uploadQueue.add(new QueueItem(prim, tags, onlySds)); 96 105 } 97 98 /** 106 107 /** 99 108 * Stores the given primitive in the plugin's cache in order to 100 109 * determine changes later. 101 * @param prim102 110 */ 103 111 protected void learn(IPrimitive prim) { 104 112 if (prim instanceof OsmPrimitive) { 105 ((OsmPrimitive) prim).save().accept(learnVisitor);113 ((OsmPrimitive) prim).save().accept(learnVisitor); 106 114 } else { 107 115 prim.accept(learnVisitor); 108 116 } 109 117 } 110 118 111 119 /** 112 120 * removes all elements from the upload queue that have the processed flag set. … … 119 127 uploadQueue = newQueue; 120 128 } 121 129 122 130 /** 123 131 * reset the processed flag for all elements of the queue. … … 129 137 } 130 138 139 @Override 131 140 public PreferenceSetting getPreferenceSetting() { 132 141 return new SdsPluginPreferences();
Note:
See TracChangeset
for help on using the changeset viewer.