Changeset 7748 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-11-25T23:51:45+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/upload/UploadNotesTask.java
r7699 r7748 45 45 Map<Note, Exception> failedNotes = new HashMap<>(); 46 46 47 /** 48 * Constructs a new {@code UploadTask}. 49 * @param title message for the user 50 * @param monitor progress monitor 51 */ 47 52 public UploadTask(String title, ProgressMonitor monitor) { 48 53 super(title, monitor, false); … … 71 76 Main.debug("found note change to upload"); 72 77 } 73 try { 74 Note newNote; 75 switch (comment.getNoteAction()) { 76 case opened: 77 if (Main.isDebugEnabled()) { 78 Main.debug("opening new note"); 79 } 80 newNote = api.createNote(note.getLatLon(), comment.getText(), monitor); 81 note.setId(newNote.getId()); 82 break; 83 case closed: 84 if (Main.isDebugEnabled()) { 85 Main.debug("closing note " + note.getId()); 86 } 87 newNote = api.closeNote(note, comment.getText(), monitor); 88 break; 89 case commented: 90 if (Main.isDebugEnabled()) { 91 Main.debug("adding comment to note " + note.getId()); 92 } 93 newNote = api.addCommentToNote(note, comment.getText(), monitor); 94 break; 95 case reopened: 96 if (Main.isDebugEnabled()) { 97 Main.debug("reopening note " + note.getId()); 98 } 99 newNote = api.reopenNote(note, comment.getText(), monitor); 100 break; 101 default: 102 newNote = null; 103 } 104 updatedNotes.put(note, newNote); 105 } catch (Exception e) { 106 Main.error("Failed to upload note to server: " + note.getId()); 107 failedNotes.put(note, e); 108 } 78 processNoteComment(monitor, api, note, comment); 109 79 } 110 80 } 81 } 82 } 83 84 private void processNoteComment(ProgressMonitor monitor, OsmApi api, Note note, NoteComment comment) { 85 try { 86 Note newNote; 87 switch (comment.getNoteAction()) { 88 case opened: 89 if (Main.isDebugEnabled()) { 90 Main.debug("opening new note"); 91 } 92 newNote = api.createNote(note.getLatLon(), comment.getText(), monitor); 93 note.setId(newNote.getId()); 94 break; 95 case closed: 96 if (Main.isDebugEnabled()) { 97 Main.debug("closing note " + note.getId()); 98 } 99 newNote = api.closeNote(note, comment.getText(), monitor); 100 break; 101 case commented: 102 if (Main.isDebugEnabled()) { 103 Main.debug("adding comment to note " + note.getId()); 104 } 105 newNote = api.addCommentToNote(note, comment.getText(), monitor); 106 break; 107 case reopened: 108 if (Main.isDebugEnabled()) { 109 Main.debug("reopening note " + note.getId()); 110 } 111 newNote = api.reopenNote(note, comment.getText(), monitor); 112 break; 113 default: 114 newNote = null; 115 } 116 updatedNotes.put(note, newNote); 117 } catch (Exception e) { 118 Main.error("Failed to upload note to server: " + note.getId()); 119 failedNotes.put(note, e); 111 120 } 112 121 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
r7725 r7748 60 60 */ 61 61 public static class UserInputTag { 62 p ublicString key;63 p ublicString value;64 p ublicboolean defaultKey;62 private final String key; 63 private final String value; 64 private final boolean defaultKey; 65 65 66 66 /** 67 67 * Constructor. 68 * 68 * 69 69 * @param key the tag key 70 70 * @param value the tag value … … 90 90 @Override 91 91 public boolean equals(Object obj) { 92 if (obj == null ) {92 if (obj == null || getClass() != obj.getClass()) { 93 93 return false; 94 94 } 95 if (getClass() != obj.getClass()) {96 return false;97 }98 95 final UserInputTag other = (UserInputTag) obj; 99 if (!Objects.equals(this.key, other.key)) { 100 return false; 101 } 102 if (!Objects.equals(this.value, other.value)) { 103 return false; 104 } 105 if (this.defaultKey != other.defaultKey) { 106 return false; 107 } 108 return true; 96 return Objects.equals(this.key, other.key) 97 && Objects.equals(this.value, other.value) 98 && this.defaultKey == other.defaultKey; 109 99 } 110 100 } … … 121 111 */ 122 112 protected MultiMap<String, String> tagCache; 123 /** 124 * the same as tagCache but for the preset keys and values 125 * can be accessed directly 126 */ 127 protected static final MultiMap<String, String> presetTagCache = new MultiMap<>(); 113 114 /** 115 * the same as tagCache but for the preset keys and values can be accessed directly 116 */ 117 protected static final MultiMap<String, String> PRESET_TAG_CACHE = new MultiMap<>(); 118 128 119 /** 129 120 * Cache for tags that have been entered by the user. 130 121 */ 131 protected static final Set<UserInputTag> userInputTagCache= new LinkedHashSet<>();132 122 protected static final Set<UserInputTag> USER_INPUT_TAG_CACHE = new LinkedHashSet<>(); 123 133 124 /** 134 125 * the cached list of member roles … … 137 128 */ 138 129 protected Set<String> roleCache; 139 /** 140 * the same as roleCache but for the preset roles 141 * can be accessed directly 142 */ 143 protected static final Set<String> presetRoleCache = new HashSet<>(); 144 130 131 /** 132 * the same as roleCache but for the preset roles can be accessed directly 133 */ 134 protected static final Set<String> PRESET_ROLE_CACHE = new HashSet<>(); 135 136 /** 137 * Constructs a new {@code AutoCompletionManager}. 138 * @param ds data set 139 */ 145 140 public AutoCompletionManager(DataSet ds) { 146 141 this.ds = ds; 147 dirty = true;142 this.dirty = true; 148 143 } 149 144 … … 166 161 /** 167 162 * initializes the cache from the primitives in the dataset 168 *169 163 */ 170 164 protected void rebuild() { … … 211 205 /** 212 206 * Initialize the cache for presets. This is done only once. 207 * @param presets Tagging presets to cache 213 208 */ 214 209 public static void cachePresets(Collection<TaggingPreset> presets) { … … 219 214 if (ki.key != null && ki.getValues() != null) { 220 215 try { 221 presetTagCache.putAll(ki.key, ki.getValues());216 PRESET_TAG_CACHE.putAll(ki.key, ki.getValues()); 222 217 } catch (NullPointerException e) { 223 218 Main.error(p+": Unable to cache "+ki); … … 228 223 for (TaggingPresetItems.Role i : r.roles) { 229 224 if (i.key != null) { 230 presetRoleCache.add(i.key);225 PRESET_ROLE_CACHE.add(i.key); 231 226 } 232 227 } … … 235 230 } 236 231 } 237 238 232 233 /** 234 * Remembers user input for the given key/value. 235 * @param key Tag key 236 * @param value Tag value 237 * @param defaultKey true, if the key was not really entered by the user, e.g. for preset text fields 238 */ 239 239 public static void rememberUserInput(String key, String value, boolean defaultKey) { 240 240 UserInputTag tag = new UserInputTag(key, value, defaultKey); 241 userInputTagCache.remove(tag); // re-add, so it gets to the last position of the LinkedHashSet242 userInputTagCache.add(tag);241 USER_INPUT_TAG_CACHE.remove(tag); // re-add, so it gets to the last position of the LinkedHashSet 242 USER_INPUT_TAG_CACHE.add(tag); 243 243 } 244 244 … … 253 253 254 254 protected List<String> getPresetKeys() { 255 return new ArrayList<>( presetTagCache.keySet());256 } 257 255 return new ArrayList<>(PRESET_TAG_CACHE.keySet()); 256 } 257 258 258 protected Collection<String> getUserInputKeys() { 259 259 List<String> keys = new ArrayList<>(); 260 for (UserInputTag tag : userInputTagCache) {260 for (UserInputTag tag : USER_INPUT_TAG_CACHE) { 261 261 if (!tag.defaultKey) { 262 262 keys.add(tag.key); … … 279 279 280 280 protected static List<String> getPresetValues(String key) { 281 return new ArrayList<>( presetTagCache.getValues(key));281 return new ArrayList<>(PRESET_TAG_CACHE.getValues(key)); 282 282 } 283 283 284 284 protected static Collection<String> getUserInputValues(String key) { 285 ArrayList<String> values = new ArrayList<>();286 for (UserInputTag tag : userInputTagCache) {285 List<String> values = new ArrayList<>(); 286 for (UserInputTag tag : USER_INPUT_TAG_CACHE) { 287 287 if (key.equals(tag.key)) { 288 288 values.add(tag.value); … … 309 309 */ 310 310 public void populateWithMemberRoles(AutoCompletionList list) { 311 list.add( presetRoleCache, AutoCompletionItemPriority.IS_IN_STANDARD);311 list.add(PRESET_ROLE_CACHE, AutoCompletionItemPriority.IS_IN_STANDARD); 312 312 list.add(getRoleCache(), AutoCompletionItemPriority.IS_IN_DATASET); 313 313 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r7663 r7748 332 332 // this works around a ruby (or lighttpd) bug where two consecutive slashes in 333 333 // an URL will cause a "404 not found" response. 334 int p; while ((p = rv.indexOf("//", rv.indexOf("://")+2)) > -1) { rv.delete(p, p + 1); } 334 int p; 335 while ((p = rv.indexOf("//", rv.indexOf("://")+2)) > -1) { 336 rv.delete(p, p + 1); 337 } 335 338 return rv.toString(); 336 339 } … … 383 386 osm.setVisible(true); 384 387 } catch(NumberFormatException e) { 385 throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret)); 388 throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", 389 osm.getId(), ret)); 386 390 } 387 391 } … … 467 471 throw e; 468 472 } catch(OsmApiException e) { 469 if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT && ChangesetClosedException.errorHeaderMatchesPattern(e.getErrorHeader())) 470 throw new ChangesetClosedException(e.getErrorHeader(), ChangesetClosedException.Source.UPDATE_CHANGESET); 473 String errorHeader = e.getErrorHeader(); 474 if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT && ChangesetClosedException.errorHeaderMatchesPattern(errorHeader)) 475 throw new ChangesetClosedException(errorHeader, ChangesetClosedException.Source.UPDATE_CHANGESET); 471 476 throw e; 472 477 } finally { … … 512 517 * @throws OsmTransferException if something is wrong 513 518 */ 514 public Collection<OsmPrimitive> uploadDiff(Collection<? extends OsmPrimitive> list, ProgressMonitor monitor) throws OsmTransferException { 519 public Collection<OsmPrimitive> uploadDiff(Collection<? extends OsmPrimitive> list, ProgressMonitor monitor) 520 throws OsmTransferException { 515 521 try { 516 522 monitor.beginTask("", list.size() * 2); … … 588 594 } 589 595 590 protected final String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException { 596 protected final String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) 597 throws OsmTransferException { 591 598 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, true, false); 592 599 } … … 611 618 * been exhausted), or rewrapping a Java exception. 612 619 */ 613 protected final String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, boolean doAuthenticate, boolean fastFail) throws OsmTransferException { 620 protected final String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, 621 boolean doAuthenticate, boolean fastFail) throws OsmTransferException { 614 622 StringBuilder responseBody = new StringBuilder(); 615 623 int retries = fastFail ? 0 : getMaxRetries(); … … 788 796 } 789 797 790 /** 791 * Create a new note on the server 798 private static StringBuilder noteStringBuilder(Note note) { 799 return new StringBuilder().append("notes/").append(note.getId()); 800 } 801 802 /** 803 * Create a new note on the server. 792 804 * @param latlon Location of note 793 805 * @param text Comment entered by user to open the note … … 798 810 public Note createNote(LatLon latlon, String text, ProgressMonitor monitor) throws OsmTransferException { 799 811 initialize(monitor); 800 String url = new StringBuilder()812 String noteUrl = new StringBuilder() 801 813 .append("notes?lat=") 802 814 .append(latlon.lat()) … … 806 818 .append(urlEncode(text)).toString(); 807 819 808 String response = sendRequest("POST", url, null, monitor, true, false);820 String response = sendRequest("POST", noteUrl, null, monitor, true, false); 809 821 return parseSingleNote(response); 810 822 } … … 820 832 public Note addCommentToNote(Note note, String comment, ProgressMonitor monitor) throws OsmTransferException { 821 833 initialize(monitor); 822 String url = new StringBuilder() 823 .append("notes/") 824 .append(note.getId()) 834 String noteUrl = noteStringBuilder(note) 825 835 .append("/comment?text=") 826 836 .append(urlEncode(comment)).toString(); 827 837 828 String response = sendRequest("POST", url, null, monitor, true, false);838 String response = sendRequest("POST", noteUrl, null, monitor, true, false); 829 839 return parseSingleNote(response); 830 840 } 831 841 832 842 /** 833 * Close a note 843 * Close a note. 834 844 * @param note Note to close. Must currently be open 835 845 * @param closeMessage Optional message supplied by the user when closing the note … … 841 851 initialize(monitor); 842 852 String encodedMessage = urlEncode(closeMessage); 843 StringBuilder urlBuilder = new StringBuilder() 844 .append("notes/") 845 .append(note.getId()) 853 StringBuilder urlBuilder = noteStringBuilder(note) 846 854 .append("/close"); 847 855 if (encodedMessage != null && !encodedMessage.trim().isEmpty()) { … … 865 873 initialize(monitor); 866 874 String encodedMessage = urlEncode(reactivateMessage); 867 StringBuilder urlBuilder = new StringBuilder() 868 .append("notes/") 869 .append(note.getId()) 875 StringBuilder urlBuilder = noteStringBuilder(note) 870 876 .append("/reopen"); 871 877 if (encodedMessage != null && !encodedMessage.trim().isEmpty()) { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r7731 r7748 91 91 public class ImageProvider { 92 92 93 private static final String HTTP_PROTOCOL = "http://"; 94 private static final String HTTPS_PROTOCOL = "https://"; 95 private static final String WIKI_PROTOCOL = "wiki://"; 96 93 97 /** 94 98 * Position of an overlay icon … … 266 270 * @since 7687 267 271 */ 268 static public Dimension getImageSizes(ImageSizes size) {272 public static Dimension getImageSizes(ImageSizes size) { 269 273 int sizeval; 270 274 switch(size) { … … 458 462 */ 459 463 public void getInBackground(final ImageCallback callback) { 460 if (name.startsWith( "http://") || name.startsWith("wiki://")) {464 if (name.startsWith(HTTP_PROTOCOL) || name.startsWith(WIKI_PROTOCOL)) { 461 465 Runnable fetch = new Runnable() { 462 466 @Override … … 486 490 */ 487 491 public void getInBackground(final ImageResourceCallback callback) { 488 if (name.startsWith( "http://") || name.startsWith("wiki://")) {492 if (name.startsWith(HTTP_PROTOCOL) || name.startsWith(WIKI_PROTOCOL)) { 489 493 Runnable fetch = new Runnable() { 490 494 @Override … … 572 576 ImageType type = name.toLowerCase().endsWith(".svg") ? ImageType.SVG : ImageType.OTHER; 573 577 574 if (name.startsWith( "http://") || name.startsWith("https://")) {578 if (name.startsWith(HTTP_PROTOCOL) || name.startsWith(HTTPS_PROTOCOL)) { 575 579 String url = name; 576 580 ImageResource ir = cache.get(url); … … 581 585 } 582 586 return ir; 583 } else if (name.startsWith( "wiki://")) {587 } else if (name.startsWith(WIKI_PROTOCOL)) { 584 588 ImageResource ir = cache.get(name); 585 589 if (ir != null) return ir; … … 984 988 * overlay must be transparent in the background. 985 989 * Also scaling is not cared about with current implementation. 990 * @deprecated this method will be refactored 986 991 */ 987 992 @Deprecated
Note:
See TracChangeset
for help on using the changeset viewer.