Ticket #8902: patterns.diff
File patterns.diff, 67.0 KB (added by , 11 years ago) |
---|
-
src/org/openstreetmap/josm/actions/PasteTagsAction.java
12 12 import java.util.HashMap; 13 13 import java.util.List; 14 14 import java.util.Map; 15 import java.util.regex.Pattern; 15 16 16 17 import org.openstreetmap.josm.Main; 17 18 import org.openstreetmap.josm.command.ChangePropertyCommand; … … 60 61 61 62 /** 62 63 * Replies true if the source for tag pasting is heterogeneous, i.e. if it doesn't consist of 63 * {@link OsmPrimitive}s of exactly one type64 * {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s of exactly one type 64 65 */ 65 66 protected boolean isHeteogeneousSource() { 66 67 int count = 0; … … 135 136 } 136 137 137 138 /** 138 * Pastes the tags from a homogeneous source (the {@link Main#pasteBuffer}s selection consisting139 * of one type of {@link OsmPrimitive}s only).139 * Pastes the tags from a homogeneous source (the {@link org.openstreetmap.josm.Main#pasteBuffer}s selection consisting 140 * of one type of {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s only). 140 141 * 141 142 * Tags from a homogeneous source can be pasted to a heterogeneous target. All target primitives, 142 143 * regardless of their type, receive the same tags. … … 241 242 242 243 } 243 244 245 private static final Pattern ACTION_PERFORMED_PATTERN = Pattern.compile("(\\d+,)*\\d+"); 246 244 247 @Override 245 248 public void actionPerformed(ActionEvent e) { 246 249 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); … … 249 252 return; 250 253 251 254 String buf = Utils.getClipboardContent(); 252 if (buf == null || buf.isEmpty() || buf.matches("(\\d+,)*\\d+")) {255 if (buf == null || buf.isEmpty() || ACTION_PERFORMED_PATTERN.matcher(buf).matches()) { 253 256 pasteTagsFromJOSMBuffer(selection); 254 257 } else { 255 258 // Paste tags from arbitrary text … … 285 288 List<PrimitiveData> directlyAdded = Main.pasteBuffer.getDirectlyAdded(); 286 289 if (directlyAdded==null || directlyAdded.isEmpty()) return false; 287 290 288 PasteTagsAction.TagPaster tagPaster = new PasteTagsAction.TagPaster(directlyAdded, selection);291 TagPaster tagPaster = new TagPaster(directlyAdded, selection); 289 292 List<Command> commands = new ArrayList<Command>(); 290 293 for (Tag tag : tagPaster.execute()) { 291 294 commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue()) ? null : tag.getValue())); -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java
2 2 package org.openstreetmap.josm.actions.downloadtasks; 3 3 4 4 import java.util.concurrent.Future; 5 import java.util.regex.Pattern; 5 6 6 7 import static org.openstreetmap.josm.tools.I18n.tr; 7 8 … … 17 18 */ 18 19 public class DownloadOsmChangeCompressedTask extends DownloadOsmChangeTask { 19 20 21 20 22 @Override 21 23 public String[] getPatterns() { 22 24 return new String[]{"https?://.*/.*\\.osc.(gz|bz2?)"}; … … 26 28 public String getTitle() { 27 29 return tr("Download Compressed OSM Change"); 28 30 } 29 31 32 private static final Pattern LOAD_URL_PATTERN = Pattern.compile("https?://.*/.*\\.osc.bz2?"); 33 30 34 /** 31 35 * Loads a given URL 32 36 * @param new_layer {@code true} if the data should be saved to a new layer … … 39 43 @Override 40 44 protected DataSet parseDataSet() throws OsmTransferException { 41 45 ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 42 if ( url.matches("https?://.*/.*\\.osc.bz2?")) {46 if (LOAD_URL_PATTERN.matcher(url).matches()) { 43 47 return reader.parseOsmChangeBzip2(subTaskMonitor); 44 48 } else { 45 49 return reader.parseOsmChangeGzip(subTaskMonitor); -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java
2 2 package org.openstreetmap.josm.actions.downloadtasks; 3 3 4 4 import java.util.concurrent.Future; 5 import java.util.regex.Pattern; 5 6 6 7 import static org.openstreetmap.josm.tools.I18n.tr; 7 8 … … 38 39 ProgressMonitor progressMonitor) { 39 40 return null; 40 41 } 41 42 43 private static final Pattern LOAD_URL_PATTERN = Pattern.compile("https?://.*/.*\\.osm.bz2?"); 44 42 45 /** 43 46 * Loads a given URL 44 47 * @param new_layer {@code true} if the data should be saved to a new layer … … 51 54 @Override 52 55 protected DataSet parseDataSet() throws OsmTransferException { 53 56 ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 54 if ( url.matches("https?://.*/.*\\.osm.bz2?")) {57 if (LOAD_URL_PATTERN.matcher(url).matches()) { 55 58 return reader.parseOsmBzip2(subTaskMonitor); 56 59 } else { 57 60 return reader.parseOsmGzip(subTaskMonitor); -
src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
21 21 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 22 22 import org.openstreetmap.josm.gui.layer.Layer; 23 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;25 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 25 import org.openstreetmap.josm.io.BoundingBoxDownloader; 27 26 import org.openstreetmap.josm.io.OsmServerLocationReader; … … 41 40 private static final String PATTERN_OVERPASS_API_XAPI_URL = "http://.*/xapi\\?.*\\[@meta\\].*"; 42 41 private static final String PATTERN_EXTERNAL_OSM_FILE = "https?://.*/.*\\.osm"; 43 42 43 private static final Pattern PATTERN_OVERPASS_API_URL_COMPILED = Pattern.compile(PATTERN_OVERPASS_API_URL); 44 private static final Pattern PATTERN_OVERPASS_API_XAPI_URL_COMPILED = Pattern.compile(PATTERN_OVERPASS_API_XAPI_URL); 45 private static final Pattern PATTERN_OSM_API_URL_COMPILED = Pattern.compile(PATTERN_OSM_API_URL); 46 44 47 protected Bounds currentBounds; 45 48 protected DataSet downloadedData; 46 49 protected DownloadTask downloadTask; … … 73 76 } 74 77 75 78 /** 76 * Replies the {@link DataSet} containing the downloaded OSM data.77 * @return The {@link DataSet} containing the downloaded OSM data.79 * Replies the {@link org.openstreetmap.josm.data.osm.DataSet} containing the downloaded OSM data. 80 * @return The {@link org.openstreetmap.josm.data.osm.DataSet} containing the downloaded OSM data. 78 81 */ 79 82 public DataSet getDownloadedData() { 80 83 return downloadedData; … … 89 92 * Asynchronously launches the download task for a given bounding box. 90 93 * 91 94 * Set <code>progressMonitor</code> to null, if the task should create, open, and close a progress monitor. 92 * Set progressMonitor to {@link NullProgressMonitor#INSTANCE} if progress information is to95 * Set progressMonitor to {@link org.openstreetmap.josm.gui.progress.NullProgressMonitor#INSTANCE} if progress information is to 93 96 * be discarded. 94 97 * 95 98 * You can wait for the asynchronous download task to finish by synchronizing on the returned 96 * {@link Future}, but make sure not to freeze up JOSM. Example:99 * {@link java.util.concurrent.Future}, but make sure not to freeze up JOSM. Example: 97 100 * <pre> 98 101 * Future<?> future = task.download(...); 99 102 * // DON'T run this on the Swing EDT or JOSM will freeze … … 115 118 * } 116 119 * Main.worker.submit(runAfterTask); 117 120 * </pre> 118 * @param reader the reader used to parse OSM data (see {@link OsmServerReader#parseOsm})121 * @param reader the reader used to parse OSM data (see {@link org.openstreetmap.josm.io.OsmServerReader#parseOsm}) 119 122 * @param newLayer true, if the data is to be downloaded into a new layer. If false, the task 120 123 * selects one of the existing layers as download layer, preferably the active layer. 121 124 * @param downloadArea the area to download … … 156 159 */ 157 160 @Override 158 161 public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) { 159 if ( url.matches(PATTERN_OVERPASS_API_URL)) {162 if (PATTERN_OVERPASS_API_URL_COMPILED.matcher(url).matches()) { 160 163 url = encodePartialUrl(url, "/interpreter?data="); // encode only the part after the = sign 161 164 162 } else if ( url.matches(PATTERN_OVERPASS_API_XAPI_URL)) {165 } else if (PATTERN_OVERPASS_API_XAPI_URL_COMPILED.matcher(url).matches()) { 163 166 url = encodePartialUrl(url, "/xapi?"); // encode only the part after the ? sign 164 167 } 165 168 downloadTask = new DownloadTask(new_layer, … … 315 318 } 316 319 } 317 320 321 private static final Pattern CLEAR_URL_PATTERN = Pattern.compile(",\\s*"); 322 318 323 @Override 319 324 public String getConfirmationMessage(URL url) { 320 325 if (url != null) { 321 326 String urlString = url.toExternalForm(); 322 if ( urlString.matches(PATTERN_OSM_API_URL)) {327 if (PATTERN_OSM_API_URL_COMPILED.matcher(urlString).matches()) { 323 328 // TODO: proper i18n after stabilization 324 329 String message = "<ul><li>"+tr("OSM Server URL:") + " " + url.getHost() + "</li><li>" + 325 330 tr("Command")+": "+url.getPath()+"</li>"; 326 331 if (url.getQuery() != null) { 327 message += "<li>" + tr("Request details: {0}", url.getQuery().replaceAll(",\\s*",", ")) + "</li>";332 message += "<li>" + tr("Request details: {0}", CLEAR_URL_PATTERN.matcher(url.getQuery()).replaceAll(", ")) + "</li>"; 328 333 } 329 334 message += "</ul>"; 330 335 return message; -
src/org/openstreetmap/josm/data/AutosaveTask.java
271 271 changedDatasets.add(event.getDataset()); 272 272 } 273 273 274 private static final Pattern REPLACE_FIRST_PATTERN = Pattern.compile("[.][^.]+$"); 275 274 276 private final File getPidFile(File osmFile) { 275 return new File(autosaveDir, osmFile.getName().replaceFirst("[.][^.]+$",".pid"));277 return new File(autosaveDir, REPLACE_FIRST_PATTERN.matcher(osmFile.getName()).replaceFirst(".pid")); 276 278 } 277 279 278 280 /** -
src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
402 402 termsOfUseURL = text; 403 403 } 404 404 405 private static final Pattern EXTENDED_URL_PATTERN = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*"); 406 405 407 public void setExtendedUrl(String url) { 406 408 CheckParameterUtil.ensureParameterNotNull(url); 407 409 … … 429 431 if(serverProjections == null || serverProjections.isEmpty()) { 430 432 try { 431 433 serverProjections = new ArrayList<String>(); 432 Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase());434 Matcher m = EXTENDED_URL_PATTERN.matcher(url.toUpperCase()); 433 435 if(m.matches()) { 434 436 for(String p : m.group(1).split(",")) 435 437 serverProjections.add(p); -
src/org/openstreetmap/josm/data/osm/TagCollection.java
15 15 import java.util.Map; 16 16 import java.util.Map.Entry; 17 17 import java.util.Set; 18 import java.util.regex.Pattern; 19 18 20 import org.openstreetmap.josm.tools.Utils; 19 21 20 22 /** 21 23 * TagCollection is a collection of tags which can be used to manipulate 22 * tags managed by {@link OsmPrimitive}s.24 * tags managed by {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s. 23 25 * 24 26 * A TagCollection can be created: 25 27 * <ul> 26 * <li>from the tags managed by a specific {@link OsmPrimitive} with {@link #from(Tagged)}</li>27 * <li>from the union of all tags managed by a collection of {@link OsmPrimitive}s with {@link #unionOfAllPrimitives(Collection)}</li>28 * <li>from the union of all tags managed by a {@link DataSet} with {@link #unionOfAllPrimitives(DataSet)}</li>29 * <li>from the intersection of all tags managed by a collection of primitives with {@link #commonToAllPrimitives( Collection)}</li>28 * <li>from the tags managed by a specific {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with {@link #from(org.openstreetmap.josm.data.osm.Tagged)}</li> 29 * <li>from the union of all tags managed by a collection of {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s with {@link #unionOfAllPrimitives(java.util.Collection)}</li> 30 * <li>from the union of all tags managed by a {@link org.openstreetmap.josm.data.osm.DataSet} with {@link #unionOfAllPrimitives(org.openstreetmap.josm.data.osm.DataSet)}</li> 31 * <li>from the intersection of all tags managed by a collection of primitives with {@link #commonToAllPrimitives(java.util.Collection)}</li> 30 32 * </ul> 31 33 * 32 34 * It provides methods to query the collection, like {@link #size()}, {@link #hasTagsFor(String)}, etc. 33 35 * 34 36 * Basic set operations allow to create the union, the intersection and the difference 35 * of tag collections, see {@link #union( TagCollection)}, {@link #intersect(TagCollection)},36 * and {@link #minus( TagCollection)}.37 * of tag collections, see {@link #union(org.openstreetmap.josm.data.osm.TagCollection)}, {@link #intersect(org.openstreetmap.josm.data.osm.TagCollection)}, 38 * and {@link #minus(org.openstreetmap.josm.data.osm.TagCollection)}. 37 39 * 38 40 * 39 41 */ … … 41 43 42 44 /** 43 45 * Creates a tag collection from the tags managed by a specific 44 * {@link OsmPrimitive}. If <code>primitive</code> is null, replies46 * {@link org.openstreetmap.josm.data.osm.OsmPrimitive}. If <code>primitive</code> is null, replies 45 47 * an empty tag collection. 46 48 * 47 49 * @param primitive the primitive 48 50 * @return a tag collection with the tags managed by a specific 49 * {@link OsmPrimitive}51 * {@link org.openstreetmap.josm.data.osm.OsmPrimitive} 50 52 */ 51 53 public static TagCollection from(Tagged primitive) { 52 54 TagCollection tags = new TagCollection(); … … 589 591 } 590 592 591 593 /** 592 * Applies this tag collection to an {@link OsmPrimitive}. Does nothing if594 * Applies this tag collection to an {@link org.openstreetmap.josm.data.osm.OsmPrimitive}. Does nothing if 593 595 * primitive is null 594 596 * 595 597 * @param primitive the primitive … … 610 612 } 611 613 612 614 /** 613 * Applies this tag collection to a collection of {@link OsmPrimitive}s. Does nothing if615 * Applies this tag collection to a collection of {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s. Does nothing if 614 616 * primitives is null 615 617 * 616 618 * @param primitives the collection of primitives … … 627 629 } 628 630 629 631 /** 630 * Replaces the tags of an {@link OsmPrimitive} by the tags in this collection . Does nothing if632 * Replaces the tags of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} by the tags in this collection . Does nothing if 631 633 * primitive is null 632 634 * 633 635 * @param primitive the primitive … … 645 647 } 646 648 647 649 /** 648 * Replaces the tags of a collection of{@link OsmPrimitive}s by the tags in this collection.650 * Replaces the tags of a collection of{@link org.openstreetmap.josm.data.osm.OsmPrimitive}s by the tags in this collection. 649 651 * Does nothing if primitives is null 650 652 * 651 653 * @param primitives the collection of primitives … … 715 717 return ret; 716 718 } 717 719 720 private static final Pattern SPLIT_VALUES_PATTERN = Pattern.compile(";\\s*"); 721 718 722 /** 719 723 * Replies the concatenation of all tag values (concatenated by a semicolon) 720 724 * … … 731 735 Set<String> values = new LinkedHashSet<String>(); 732 736 Map<String, Collection<String>> originalSplitValues = new LinkedHashMap<String, Collection<String>>(); 733 737 for (String v : originalValues) { 734 List<String> vs = Arrays.asList( v.split(";\\s*"));738 List<String> vs = Arrays.asList(SPLIT_VALUES_PATTERN.split(v)); 735 739 originalSplitValues.put(v, vs); 736 740 values.addAll(vs); 737 741 } -
src/org/openstreetmap/josm/data/preferences/ColorProperty.java
2 2 package org.openstreetmap.josm.data.preferences; 3 3 4 4 import java.awt.Color; 5 import java.util.regex.Pattern; 5 6 6 7 import org.openstreetmap.josm.Main; 7 8 import org.openstreetmap.josm.data.Preferences.ColorKey; 8 9 9 10 /** 10 * A property containing a {@link Color} value.11 * A property containing a {@link java.awt.Color} value. 11 12 * @since 5464 12 13 */ 13 14 public class ColorProperty extends AbstractProperty<Color> implements ColorKey { … … 33 34 public boolean put(Color value) { 34 35 return Main.pref.putColor(getColorKey(name), value); 35 36 } 36 37 38 private static final Pattern COLOR_KEY_PATTERN = Pattern.compile("[^a-z0-9]+"); 39 37 40 /** 38 41 * Replies the color key used in JOSM preferences for this property. 39 42 * @param colName The color name 40 43 * @return The color key for this property 41 44 */ 42 45 public static String getColorKey(String colName) { 43 return colName == null ? null : colName.toLowerCase().replaceAll("[^a-z0-9]+",".");46 return colName == null ? null : COLOR_KEY_PATTERN.matcher(colName.toLowerCase()).replaceAll("."); 44 47 } 45 48 46 49 @Override -
src/org/openstreetmap/josm/data/projection/CustomProjection.java
155 155 156 156 private Map<String, String> parseParameterList(String pref) throws ProjectionConfigurationException { 157 157 Map<String, String> parameters = new HashMap<String, String>(); 158 String[] parts = pref.trim().split("\\s+");158 String[] parts = Utils.WHITE_SPACES_PATTERN.split(pref.trim()); 159 159 if (pref.trim().isEmpty()) { 160 160 parts = new String[0]; 161 161 } -
src/org/openstreetmap/josm/data/validation/tests/NameMismatch.java
6 6 import java.util.Collection; 7 7 import java.util.HashSet; 8 8 import java.util.Map.Entry; 9 import java.util.regex.Pattern; 9 10 10 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 12 import org.openstreetmap.josm.data.validation.Severity; … … 31 32 public class NameMismatch extends Test { 32 33 protected static final int NAME_MISSING = 1501; 33 34 protected static final int NAME_TRANSLATION_MISSING = 1502; 35 private static final Pattern NAME_SPLIT_PATTERN = Pattern.compile(" - "); 34 36 35 37 public NameMismatch() { 36 38 super(tr("Missing name:* translation"), … … 81 83 composition of some (not necessarily all) name:* labels. 82 84 Check if this is the case. */ 83 85 84 String[] split_names = name.split(" - ");86 String[] split_names = NAME_SPLIT_PATTERN.split(name); 85 87 if (split_names.length == 1) { 86 88 /* The name is not composed of multiple parts. Complain. */ 87 89 missingTranslation(p); -
src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
823 823 } 824 824 }; 825 825 826 public String getData(String str) { 827 Matcher m = Pattern.compile(" *# *([^#]+) *$").matcher(str); 828 str = m.replaceFirst("").trim(); 826 private static final Pattern CLEAN_STR_PATTERN = Pattern.compile(" *# *([^#]+) *$"); 827 private static final Pattern SPLIT_TRIMMED_PATTERN = Pattern.compile(" *: *"); 828 private static final Pattern SPLIT_ELEMENTS_PATTERN = Pattern.compile(" *&& *"); 829 830 public String getData(final String str) { 831 Matcher m = CLEAN_STR_PATTERN.matcher(str); 832 String trimmed = m.replaceFirst("").trim(); 829 833 try { 830 834 description = m.group(1); 831 835 if (description != null && description.length() == 0) { … … 834 838 } catch (IllegalStateException e) { 835 839 description = null; 836 840 } 837 String[] n = str.split(" *: *", 3);841 String[] n = SPLIT_TRIMMED_PATTERN.split(trimmed, 3); 838 842 if (n[0].equals("way")) { 839 843 type = OsmPrimitiveType.WAY; 840 844 } else if (n[0].equals("node")) { … … 859 863 code = TAG_CHECK_INFO; 860 864 } else 861 865 return tr("Could not find warning level"); 862 for (String exp: n[2].split(" *&& *")) {866 for (String exp: SPLIT_ELEMENTS_PATTERN.split(n[2])) { 863 867 try { 864 868 data.add(new CheckerElement(exp)); 865 869 } catch (IllegalStateException e) { -
src/org/openstreetmap/josm/gui/dialogs/LatLonDialog.java
55 55 private static final char E_TR = LatLon.EAST.charAt(0); 56 56 private static final char W_TR = LatLon.WEST.charAt(0); 57 57 58 private static final Pattern p= Pattern.compile(58 private static final Pattern LAT_LNG_PATTERN = Pattern.compile( 59 59 "([+|-]?\\d+[.,]\\d+)|" // (1) 60 60 + "([+|-]?\\d+)|" // (2) 61 61 + "("+DEG+"|o|deg)|" // (3) … … 66 66 + "\\s+|" 67 67 + "(.+)"); 68 68 69 private static final Pattern TYPE1_PATTERN = Pattern.compile("Ro?,?Ro?"); 70 private static final Pattern TYPE2_PATTERN = Pattern.compile("xRo?,?xRo?"); 71 private static final Pattern TYPE3_PATTERN = Pattern.compile("Ro?x,?Ro?x"); 72 private static final Pattern TYPE4_PATTERN = Pattern.compile("Zo[RZ]'?,?Zo[RZ]'?|Z[RZ],?Z[RZ]"); 73 private static final Pattern TYPE5_PATTERN = Pattern.compile("xZo[RZ]'?,?xZo[RZ]'?|xZo?[RZ],?xZo?[RZ]"); 74 private static final Pattern TYPE6_PATTERN = Pattern.compile("Zo[RZ]'?x,?Zo[RZ]'?x|Zo?[RZ]x,?Zo?[RZ]x"); 75 private static final Pattern TYPE7_PATTERN = Pattern.compile("ZoZ'[RZ]\"?x,?ZoZ'[RZ]\"?x|ZZ[RZ]x,?ZZ[RZ]x"); 76 private static final Pattern TYPE8_PATTERN = Pattern.compile("xZoZ'[RZ]\"?,?xZoZ'[RZ]\"?|xZZ[RZ],?xZZ[RZ]"); 77 private static final Pattern TYPE9_PATTERN = Pattern.compile("ZZ[RZ],?ZZ[RZ]"); 78 69 79 protected JPanel buildLatLon() { 70 80 JPanel pnl = new JPanel(new GridBagLayout()); 71 81 pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); … … 341 351 } 342 352 343 353 private static LatLon parseLatLon(final String coord) { 344 final Matcher m = p.matcher(coord);354 final Matcher m = LAT_LNG_PATTERN.matcher(coord); 345 355 346 356 final StringBuilder sb = new StringBuilder(); 347 357 final List<Object> list = new ArrayList<Object>(); … … 380 390 final Object[] params = list.toArray(); 381 391 final LatLonHolder latLon = new LatLonHolder(); 382 392 383 if ( pattern.matches("Ro?,?Ro?")) {393 if (TYPE1_PATTERN.matcher(pattern).matches()) { 384 394 setLatLonObj(latLon, 385 395 params[0], ZERO, ZERO, "N", 386 396 params[1], ZERO, ZERO, "E"); 387 } else if ( pattern.matches("xRo?,?xRo?")) {397 } else if (TYPE2_PATTERN.matcher(pattern).matches()) { 388 398 setLatLonObj(latLon, 389 399 params[1], ZERO, ZERO, params[0], 390 400 params[3], ZERO, ZERO, params[2]); 391 } else if ( pattern.matches("Ro?x,?Ro?x")) {401 } else if (TYPE3_PATTERN.matcher(pattern).matches()) { 392 402 setLatLonObj(latLon, 393 403 params[0], ZERO, ZERO, params[1], 394 404 params[2], ZERO, ZERO, params[3]); 395 } else if ( pattern.matches("Zo[RZ]'?,?Zo[RZ]'?|Z[RZ],?Z[RZ]")) {405 } else if (TYPE4_PATTERN.matcher(pattern).matches()) { 396 406 setLatLonObj(latLon, 397 407 params[0], params[1], ZERO, "N", 398 408 params[2], params[3], ZERO, "E"); 399 } else if ( pattern.matches("xZo[RZ]'?,?xZo[RZ]'?|xZo?[RZ],?xZo?[RZ]")) {409 } else if (TYPE5_PATTERN.matcher(pattern).matches()) { 400 410 setLatLonObj(latLon, 401 411 params[1], params[2], ZERO, params[0], 402 412 params[4], params[5], ZERO, params[3]); 403 } else if ( pattern.matches("Zo[RZ]'?x,?Zo[RZ]'?x|Zo?[RZ]x,?Zo?[RZ]x")) {413 } else if (TYPE6_PATTERN.matcher(pattern).matches()) { 404 414 setLatLonObj(latLon, 405 415 params[0], params[1], ZERO, params[2], 406 416 params[3], params[4], ZERO, params[5]); 407 } else if ( pattern.matches("ZoZ'[RZ]\"?x,?ZoZ'[RZ]\"?x|ZZ[RZ]x,?ZZ[RZ]x")) {417 } else if (TYPE7_PATTERN.matcher(pattern).matches()) { 408 418 setLatLonObj(latLon, 409 419 params[0], params[1], params[2], params[3], 410 420 params[4], params[5], params[6], params[7]); 411 } else if ( pattern.matches("xZoZ'[RZ]\"?,?xZoZ'[RZ]\"?|xZZ[RZ],?xZZ[RZ]")) {421 } else if (TYPE8_PATTERN.matcher(pattern).matches()) { 412 422 setLatLonObj(latLon, 413 423 params[1], params[2], params[3], params[0], 414 424 params[5], params[6], params[7], params[4]); 415 } else if ( pattern.matches("ZZ[RZ],?ZZ[RZ]")) {425 } else if (TYPE9_PATTERN.matcher(pattern).matches()) { 416 426 setLatLonObj(latLon, 417 427 params[0], params[1], params[2], "N", 418 428 params[3], params[4], params[5], "E"); … … 423 433 return new LatLon(latLon.lat, latLon.lon); 424 434 } 425 435 436 private static final Pattern SPLIT_EN_PATTERN = Pattern.compile("[;, ]+"); 437 426 438 private static EastNorth parseEastNorth(String s) { 427 String[] en = s.split("[;, ]+");439 String[] en = SPLIT_EN_PATTERN.split(s); 428 440 if (en.length != 2) return null; 429 441 try { 430 442 double east = Double.parseDouble(en[0]); -
src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorter.java
9 9 import java.util.LinkedList; 10 10 import java.util.List; 11 11 import java.util.Map; 12 import java.util.regex.Pattern; 12 13 13 14 import org.openstreetmap.josm.data.osm.RelationMember; 15 import org.openstreetmap.josm.tools.Utils; 14 16 15 17 public class RelationSorter { 16 18 … … 47 49 String addrB = b.getMember().get("addr:housenumber").trim(); 48 50 if (addrA.equals(addrB)) return 0; 49 51 // Strip non-digits (from "1B" addresses for example) 50 String addrAnum = addrA.replaceAll("\\D+", ""); 51 String addrBnum = addrB.replaceAll("\\D+", ""); 52 String addrAnum = Utils.DIGITS_PATTERN.matcher(addrA).replaceAll(""); 53 String addrBnum = Utils.DIGITS_PATTERN.matcher(addrB).replaceAll(""); 54 52 55 // Compare only numbers 53 56 try { 54 57 Integer res = Integer.parseInt(addrAnum) - Integer.parseInt(addrBnum); -
src/org/openstreetmap/josm/gui/help/HelpBrowser.java
18 18 import java.util.Locale; 19 19 import java.util.Observable; 20 20 import java.util.Observer; 21 import java.util.regex.Pattern; 21 22 22 23 import javax.swing.AbstractAction; 23 24 import javax.swing.JButton; … … 38 39 import javax.swing.text.Document; 39 40 import javax.swing.text.Element; 40 41 import javax.swing.text.SimpleAttributeSet; 42 import javax.swing.text.html.HTML; 41 43 import javax.swing.text.html.HTML.Tag; 42 44 import javax.swing.text.html.HTMLDocument; 43 45 import javax.swing.text.html.StyleSheet; … … 55 57 import org.openstreetmap.josm.tools.WindowGeometry; 56 58 57 59 public class HelpBrowser extends JDialog { 60 58 61 /** the unique instance */ 59 62 private static HelpBrowser instance; 60 63 … … 435 438 } 436 439 } 437 440 441 private static final Pattern CLEAN_URL_PATTERN = Pattern.compile("#[^#]*$"); 442 438 443 class EditAction extends AbstractAction { 444 439 445 public EditAction() { 440 446 // putValue(NAME, tr("Edit")); 441 447 putValue(SHORT_DESCRIPTION, tr("Edit the current help page")); … … 463 469 ); 464 470 return; 465 471 } 466 url = url.replaceAll("#[^#]*$","");472 url = CLEAN_URL_PATTERN.matcher(url).replaceAll(""); 467 473 OpenBrowser.displayUrl(url+"?action=edit"); 468 474 } 469 475 } … … 537 543 } 538 544 } 539 545 546 private static final Pattern HYPERLINK_URL_PATTERN = Pattern.compile("#.*"); 547 540 548 class HyperlinkHandler implements HyperlinkListener { 541 549 542 550 /** … … 582 590 Object value = set.getAttribute(Tag.A); 583 591 if (value == null || ! (value instanceof SimpleAttributeSet)) return null; 584 592 SimpleAttributeSet atts = (SimpleAttributeSet)value; 585 value = atts.getAttribute( javax.swing.text.html.HTML.Attribute.HREF);593 value = atts.getAttribute(HTML.Attribute.HREF); 586 594 if (value == null) return null; 587 595 String s = (String)value; 588 if ( s.matches("#.*"))596 if (HYPERLINK_URL_PATTERN.matcher(s).matches()) 589 597 return s.substring(1); 590 598 return null; 591 599 } -
src/org/openstreetmap/josm/gui/preferences/imagery/AddImageryPanel.java
5 5 import java.awt.LayoutManager; 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.regex.Pattern; 8 9 9 10 import javax.swing.AbstractButton; 10 11 import javax.swing.JPanel; … … 20 21 21 22 /** 22 23 * An abstract imagery panel used to add WMS/TMS imagery sources. See implementations. 23 * @see AddTMSLayerPanel24 * @see AddWMSLayerPanel24 * @see org.openstreetmap.josm.gui.preferences.imagery.AddTMSLayerPanel 25 * @see org.openstreetmap.josm.gui.preferences.imagery.AddWMSLayerPanel 25 26 * @since 5617 26 27 */ 27 28 public abstract class AddImageryPanel extends JPanel { … … 67 68 68 69 protected abstract ImageryInfo getImageryInfo(); 69 70 71 private static final Pattern SANITIZE_PATTERN = Pattern.compile("[\r\n]+"); 72 70 73 protected static String sanitize(String s) { 71 return s.replaceAll("[\r\n]+","").trim();74 return SANITIZE_PATTERN.matcher(s).replaceAll("").trim(); 72 75 } 73 76 74 77 protected final String getImageryName() { -
src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.preferences.shortcut; 3 3 4 import java.awt.Color; 5 import java.awt.Component; 6 import java.awt.Dimension; 7 import java.awt.GridBagConstraints; 8 import java.awt.GridBagLayout; 9 import java.awt.Insets; 10 import java.awt.Toolkit; 4 import java.awt.*; 11 5 12 6 import static org.openstreetmap.josm.tools.I18n.marktr; 13 7 import static org.openstreetmap.josm.tools.I18n.tr; 14 8 9 import java.awt.event.ActionEvent; 15 10 import java.awt.event.KeyEvent; 16 11 import java.lang.reflect.Field; 17 12 import java.util.ArrayList; 18 13 import java.util.LinkedHashMap; 19 14 import java.util.Map; 20 15 16 import java.util.regex.Pattern; 21 17 import java.util.regex.PatternSyntaxException; 22 18 import javax.swing.AbstractAction; 23 19 import javax.swing.BorderFactory; … … 47 43 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 48 44 import org.openstreetmap.josm.tools.Shortcut; 49 45 import org.openstreetmap.josm.gui.widgets.JosmTextField; 46 import org.openstreetmap.josm.tools.Utils; 50 47 51 48 /** 52 49 * This is the keyboard preferences content. … … 194 191 CbAction action = new CbAction(this); 195 192 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 196 193 add(buildFilterPanel()); 197 listPane.setLayout(new java.awt.GridLayout());194 listPane.setLayout(new GridLayout()); 198 195 199 196 // This is the list of shortcuts: 200 197 shortcutTable.setModel(model); … … 212 209 add(listPane); 213 210 214 211 // and here follows the edit area. I won't object to someone re-designing it, it looks, um, "minimalistic" ;) 215 shortcutEditPane.setLayout(new java.awt.GridLayout(5, 2));212 shortcutEditPane.setLayout(new GridLayout(5, 2)); 216 213 217 214 cbDefault.setAction(action); 218 215 cbDefault.setText(tr("Use default")); … … 321 318 } 322 319 } 323 320 @Override 324 public void actionPerformed( java.awt.event.ActionEvent e) {321 public void actionPerformed(ActionEvent e) { 325 322 ListSelectionModel lsm = panel.shortcutTable.getSelectionModel(); 326 323 if (lsm != null && !lsm.isSelectionEmpty()) { 327 324 if (e != null) { // only if we've been called by a user action … … 375 372 expr = expr.replace("+", "\\+"); 376 373 // split search string on whitespace, do case-insensitive AND search 377 374 ArrayList<RowFilter<Object, Object>> andFilters = new ArrayList<RowFilter<Object, Object>>(); 378 for (String word : expr.split("\\s+")) {375 for (String word : Utils.WHITE_SPACES_PATTERN.split(expr)) { 379 376 andFilters.add(RowFilter.regexFilter("(?i)" + word)); 380 377 } 381 378 sorter.setRowFilter(RowFilter.andFilter(andFilters)); -
src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
23 23 import java.util.List; 24 24 import java.util.Map; 25 25 import java.util.TreeSet; 26 import java.util.regex.Pattern; 26 27 import javax.swing.ButtonGroup; 27 28 import javax.swing.ImageIcon; 28 29 import javax.swing.JButton; … … 145 146 : short_description; 146 147 } 147 148 149 private static final Pattern REMOVE_MARKUP_PATTERN = Pattern.compile("<.*>"); 148 150 // toString is mainly used to initialize the Editor 149 151 @Override 150 152 public String toString() { 151 153 if (value.equals(DIFFERENT)) 152 154 return DIFFERENT; 153 return getDisplayValue(true).replaceAll("<.*>",""); // remove additional markup, e.g. <br>155 return REMOVE_MARKUP_PATTERN.matcher(getDisplayValue(true)).replaceAll(""); // remove additional markup, e.g. <br> 154 156 } 155 157 } 156 158 -
src/org/openstreetmap/josm/gui/util/GuiHelper.java
21 21 import java.lang.reflect.InvocationTargetException; 22 22 import java.util.Arrays; 23 23 import java.util.List; 24 import java.util.regex.Pattern; 24 25 25 26 import javax.swing.GrayFilter; 26 27 import javax.swing.Icon; … … 37 38 * basic gui utils 38 39 */ 39 40 public class GuiHelper { 41 40 42 /** 41 43 * disable / enable a component and all its child components 42 44 */ … … 171 173 return timer; 172 174 } 173 175 176 private static final Pattern CUSTOMIZED_STROKE_PATTERN = Pattern.compile("[^\\.0-9]+"); 177 174 178 /** 175 179 * Return s new BasicStroke object with given thickness and style 176 180 * @param code = 3.5 -> thickness=3.5px; 3.5 10 5 -> thickness=3.5px, dashed: 10px filled + 5px empty 177 181 * @return stroke for drawing 178 182 */ 179 183 public static Stroke getCustomizedStroke(String code) { 180 String[] s = code.trim().split("[^\\.0-9]+");184 String[] s = CUSTOMIZED_STROKE_PATTERN.split(code.trim()); 181 185 182 186 if (s.length==0) return new BasicStroke(); 183 187 float w; -
src/org/openstreetmap/josm/io/CacheFiles.java
10 10 import java.util.Iterator; 11 11 import java.util.Set; 12 12 import java.util.TreeMap; 13 import java.util.regex.Pattern; 13 14 14 15 import javax.imageio.ImageIO; 15 16 … … 308 309 return dirsize; 309 310 } 310 311 312 private static final Pattern IDENT_PATTERN = Pattern.compile("[^a-zA-Z0-9]"); 313 private static final Pattern IDENT_PATTERN_2 = Pattern.compile("[acegikmoqsuwy]"); 314 311 315 /** 312 316 * Returns a short and unique file name for a given long identifier 313 317 * @return String short filename … … 320 324 } catch(Exception e) { 321 325 // Fall back. Remove unsuitable characters and some random ones to shrink down path length. 322 326 // Limit it to 70 characters, that leaves about 190 for the path on Windows/NTFS 323 ident = ident.replaceAll("[^a-zA-Z0-9]","");324 ident = ident.replaceAll("[acegikmoqsuwy]","");327 ident = IDENT_PATTERN.matcher(ident).replaceAll(""); 328 ident = IDENT_PATTERN_2.matcher(ident).replaceAll(""); 325 329 return ident.substring(ident.length() - 70); 326 330 } 327 331 } -
src/org/openstreetmap/josm/io/MirroredInputStream.java
17 17 import java.util.Arrays; 18 18 import java.util.Enumeration; 19 19 import java.util.List; 20 import java.util.regex.Pattern; 20 21 import java.util.zip.ZipEntry; 21 22 import java.util.zip.ZipFile; 22 23 … … 29 30 * The file mirrored is only downloaded if it has been more than 7 days since last download 30 31 */ 31 32 public class MirroredInputStream extends InputStream { 33 32 34 InputStream fs = null; 33 35 File file = null; 34 36 … … 55 57 * - http://... a url. It will be cached on disk. 56 58 * @param destDir the destination directory for the cache file. only applies for urls. 57 59 * @param maxTime the maximum age of the cache file (in seconds) 58 * @throws IOException when the resource with the given name could not be retrieved60 * @throws java.io.IOException when the resource with the given name could not be retrieved 59 61 */ 60 62 public MirroredInputStream(String name, String destDir, long maxTime) throws IOException { 61 63 URL url; … … 74 76 file = checkLocal(url, destDir, maxTime); 75 77 } 76 78 } 77 } catch ( java.net.MalformedURLException e) {79 } catch (MalformedURLException e) { 78 80 if (name.startsWith("resource://")) { 79 81 fs = getClass().getResourceAsStream( 80 82 name.substring("resource:/".length())); … … 158 160 } 159 161 Main.pref.putCollection(prefKey, null); 160 162 } 161 } catch ( java.net.MalformedURLException e) {}163 } catch (MalformedURLException e) {} 162 164 } 163 165 164 166 /** … … 176 178 return prefKey.toString().replaceAll("=","_"); 177 179 } 178 180 181 private static final Pattern CHECK_LOCAL_PATTERN = Pattern.compile("[^A-Za-z0-9_.-]"); 182 179 183 private File checkLocal(URL url, String destDir, long maxTime) throws IOException { 180 184 String prefKey = getPrefKey(url, destDir); 181 185 long age = 0L; … … 206 210 destDirFile.mkdirs(); 207 211 } 208 212 209 String a = url.toString().replaceAll("[^A-Za-z0-9_.-]","_");213 String a = CHECK_LOCAL_PATTERN.matcher(url.toString()).replaceAll("_"); 210 214 String localPath = "mirror_" + a; 211 215 destDirFile = new File(destDir, localPath + ".tmp"); 212 216 BufferedOutputStream bos = null; … … 254 258 * Opens a connection for downloading a resource. 255 259 * <p> 256 260 * Manually follows redirects because 257 * {@link HttpURLConnection#setFollowRedirects(boolean)} fails if the redirect261 * {@link java.net.HttpURLConnection#setFollowRedirects(boolean)} fails if the redirect 258 262 * is going from a http to a https URL, see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4620571">bug report</a>. 259 263 * <p> 260 264 * This can causes problems when downloading from certain GitHub URLs. 261 265 * 262 266 * @param downloadUrl The resource URL to download 263 267 * @return The HTTP connection effectively linked to the resource, after all potential redirections 264 * @throws MalformedURLException If a redirected URL is wrong265 * @throws IOException If any I/O operation goes wrong268 * @throws java.net.MalformedURLException If a redirected URL is wrong 269 * @throws java.io.IOException If any I/O operation goes wrong 266 270 * @since 6073 267 271 */ 268 272 public static HttpURLConnection connectFollowingRedirect(URL downloadUrl) throws MalformedURLException, IOException { -
src/org/openstreetmap/josm/io/OsmApi.java
23 23 import java.util.Collection; 24 24 import java.util.Collections; 25 25 import java.util.HashMap; 26 import java.util.regex.Pattern; 26 27 27 28 import javax.xml.parsers.ParserConfigurationException; 28 29 import javax.xml.parsers.SAXParserFactory; … … 73 74 */ 74 75 static public final String DEFAULT_API_URL = "http://api.openstreetmap.org/api"; 75 76 77 private static final Pattern API_URL_PATTERN = Pattern.compile(".*openstreetmap.org/api.*"); 78 76 79 // The collection of instantiated OSM APIs 77 80 private static HashMap<String, OsmApi> instances = new HashMap<String, OsmApi>(); 78 81 79 82 /** 80 * Replies the {@link OsmApi} for a given server URL83 * Replies the {@link org.openstreetmap.josm.io.OsmApi} for a given server URL 81 84 * 82 85 * @param serverUrl the server URL 83 86 * @return the OsmApi … … 94 97 } 95 98 96 99 /** 97 * Replies the {@link OsmApi} for the URL given by the preference <code>osm-server.url</code>100 * Replies the {@link org.openstreetmap.josm.io.OsmApi} for the URL given by the preference <code>osm-server.url</code> 98 101 * 99 102 * @return the OsmApi 100 103 * @throws IllegalStateException thrown, if the preference <code>osm-server.url</code> is not set … … 197 200 * Initializes this component by negotiating a protocol version with the server. 198 201 * 199 202 * @param monitor the progress monitor 200 * @throws OsmTransferCanceledException If the initialisation has been cancelled by user.201 * @throws OsmApiInitializationException If any other exception occurs. Use getCause() to get the original exception.203 * @throws org.openstreetmap.josm.io.OsmTransferCanceledException If the initialisation has been cancelled by user. 204 * @throws org.openstreetmap.josm.io.OsmApiInitializationException If any other exception occurs. Use getCause() to get the original exception. 202 205 */ 203 206 public void initialize(ProgressMonitor monitor) throws OsmTransferCanceledException, OsmApiInitializationException { 204 207 initialize(monitor, false); … … 209 212 * 210 213 * @param monitor the progress monitor 211 214 * @param fastFail true to request quick initialisation with a small timeout (more likely to throw exception) 212 * @throws OsmTransferCanceledException If the initialisation has been cancelled by user.213 * @throws OsmApiInitializationException If any other exception occurs. Use getCause() to get the original exception.215 * @throws org.openstreetmap.josm.io.OsmTransferCanceledException If the initialisation has been cancelled by user. 216 * @throws org.openstreetmap.josm.io.OsmApiInitializationException If any other exception occurs. Use getCause() to get the original exception. 214 217 */ 215 218 public void initialize(ProgressMonitor monitor, boolean fastFail) throws OsmTransferCanceledException, OsmApiInitializationException { 216 219 if (initialized) … … 238 241 /* This is an interim solution for openstreetmap.org not currently 239 242 * transmitting their imagery blacklist in the capabilities call. 240 243 * remove this as soon as openstreetmap.org adds blacklists. */ 241 if ( this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty())244 if (API_URL_PATTERN.matcher(this.serverUrl).matches() && capabilities.getImageryBlacklist().isEmpty()) 242 245 { 243 246 capabilities.put("blacklist", "regex", ".*\\.google\\.com/.*"); 244 247 capabilities.put("blacklist", "regex", ".*209\\.85\\.2\\d\\d.*"); … … 332 335 * 333 336 * @param osm the primitive 334 337 * @param monitor the progress monitor 335 * @throws OsmTransferException if something goes wrong338 * @throws org.openstreetmap.josm.io.OsmTransferException if something goes wrong 336 339 */ 337 340 public void createPrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 338 341 String ret = ""; … … 352 355 * 353 356 * @param osm the primitive. Must not be null. 354 357 * @param monitor the progress monitor 355 * @throws OsmTransferException if something goes wrong358 * @throws org.openstreetmap.josm.io.OsmTransferException if something goes wrong 356 359 */ 357 360 public void modifyPrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 358 361 String ret = null; … … 373 376 * Deletes an OSM primitive on the server. 374 377 * @param osm the primitive 375 378 * @param monitor the progress monitor 376 * @throws OsmTransferException if something goes wrong379 * @throws org.openstreetmap.josm.io.OsmTransferException if something goes wrong 377 380 */ 378 381 public void deletePrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 379 382 ensureValidChangeset(); … … 394 397 * 395 398 * @param changeset the changeset toe be created. Must not be null. 396 399 * @param progressMonitor the progress monitor 397 * @throws OsmTransferException signifying a non-200 return code, or connection errors400 * @throws org.openstreetmap.josm.io.OsmTransferException signifying a non-200 return code, or connection errors 398 401 * @throws IllegalArgumentException thrown if changeset is null 399 402 */ 400 403 public void openChangeset(Changeset changeset, ProgressMonitor progressMonitor) throws OsmTransferException { … … 421 424 * be null and id > 0 must be true. 422 425 * 423 426 * @param changeset the changeset to update. Must not be null. 424 * @param monitor the progress monitor. If null, uses the {@link NullProgressMonitor#INSTANCE}.427 * @param monitor the progress monitor. If null, uses the {@link org.openstreetmap.josm.gui.progress.NullProgressMonitor#INSTANCE}. 425 428 * 426 * @throws OsmTransferException if something goes wrong.429 * @throws org.openstreetmap.josm.io.OsmTransferException if something goes wrong. 427 430 * @throws IllegalArgumentException if changeset is null 428 431 * @throws IllegalArgumentException if changeset.getId() <= 0 429 432 * … … 462 465 * succeeds. 463 466 * 464 467 * @param changeset the changeset to be closed. Must not be null. changeset.getId() > 0 required. 465 * @param monitor the progress monitor. If null, uses {@link NullProgressMonitor#INSTANCE}468 * @param monitor the progress monitor. If null, uses {@link org.openstreetmap.josm.gui.progress.NullProgressMonitor#INSTANCE} 466 469 * 467 * @throws OsmTransferException if something goes wrong.470 * @throws org.openstreetmap.josm.io.OsmTransferException if something goes wrong. 468 471 * @throws IllegalArgumentException thrown if changeset is null 469 472 * @throws IllegalArgumentException thrown if changeset.getId() <= 0 470 473 */ … … 493 496 * @param list the list of changed OSM Primitives 494 497 * @param monitor the progress monitor 495 498 * @return list of processed primitives 496 * @throws OsmTransferException if something is wrong499 * @throws org.openstreetmap.josm.io.OsmTransferException if something is wrong 497 500 */ 498 501 public Collection<IPrimitive> uploadDiff(Collection<? extends IPrimitive> list, ProgressMonitor monitor) throws OsmTransferException { 499 502 try { … … 585 588 * @param fastFail true to request a short timeout 586 589 * 587 590 * @return the body of the HTTP response, if and only if the response code was "200 OK". 588 * @throws OsmTransferException if the HTTP return code was not 200 (and retries have591 * @throws org.openstreetmap.josm.io.OsmTransferException if the HTTP return code was not 200 (and retries have 589 592 * been exhausted), or rewrapping a Java exception. 590 593 */ 591 594 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, boolean doAuthenticate, boolean fastFail) throws OsmTransferException { … … 724 727 /** 725 728 * Ensures that the current changeset can be used for uploading data 726 729 * 727 * @throws OsmTransferException thrown if the current changeset can't be used for730 * @throws org.openstreetmap.josm.io.OsmTransferException thrown if the current changeset can't be used for 728 731 * uploading data 729 732 */ 730 733 protected void ensureValidChangeset() throws OsmTransferException { -
src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java
17 17 import java.util.HashSet; 18 18 import java.util.Map; 19 19 import java.util.Set; 20 import java.util.regex.Pattern; 20 21 import javax.swing.AbstractAction; 21 22 import javax.swing.JCheckBox; 22 23 … … 287 288 findExistingTags(); 288 289 } 289 290 290 /* 291 private static final Pattern ADD_TAGS_PATTERN = Pattern.compile("\\s*=\\s*"); 292 293 /* 291 294 * parse addtags parameters Example URL (part): 292 295 * addtags=wikipedia:de%3DResidenzschloss Dresden|name:en%3DDresden Castle 293 296 */ … … 314 317 int i = 0; 315 318 for (String tag : tagSet) { 316 319 // support a = b===c as "a"="b===c" 317 String [] pair = tag.split("\\s*=\\s*",2);320 String [] pair = ADD_TAGS_PATTERN.split(tag, 2); 318 321 keyValue[i][0] = pair[0]; 319 322 keyValue[i][1] = pair.length<2 ? "": pair[1]; 320 323 i++; -
src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
9 9 import java.util.HashMap; 10 10 import java.util.LinkedList; 11 11 import java.util.List; 12 import java.util.regex.Pattern; 12 13 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.actions.AutoScaleAction; … … 22 23 import org.openstreetmap.josm.gui.util.GuiHelper; 23 24 import org.openstreetmap.josm.io.remotecontrol.AddTagsDialog; 24 25 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 25 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;26 26 27 27 /** 28 28 * Adds a way to the current dataset. For instance, {@code /add_way?way=lat1,lon2;lat2,lon2}. … … 80 80 return PermissionPrefWithDefault.CREATE_OBJECTS; 81 81 } 82 82 83 private static final Pattern SPLIT_WAY_PATTERN = Pattern.compile(";\\s*"); 84 private static final Pattern COORDINATES_PATTERN = Pattern.compile(",\\s*"); 85 83 86 @Override 84 87 protected void validateRequest() throws RequestHandlerBadRequestException { 85 88 allCoordinates.clear(); 86 for (String coordinatesString : args.get("way").split(";\\s*")) {87 String[] coordinates = coordinatesString.split(",\\s*", 2);89 for (String coordinatesString : SPLIT_WAY_PATTERN.split(args.get("way"))) { 90 String[] coordinates = COORDINATES_PATTERN.split(coordinatesString, 2); 88 91 if (coordinates.length < 2) { 89 92 throw new RequestHandlerBadRequestException( 90 93 tr("Invalid coordinates: {0}", Arrays.toString(coordinates))); -
src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java
5 5 6 6 import java.util.LinkedList; 7 7 import java.util.List; 8 import java.util.regex.Pattern; 8 9 9 10 import org.openstreetmap.josm.Main; 10 11 import org.openstreetmap.josm.actions.DownloadPrimitiveAction; … … 80 81 return PermissionPrefWithDefault.LOAD_DATA; 81 82 } 82 83 84 private static final Pattern SPLIT_OBJECTS_PATTERN = Pattern.compile(",\\s*"); 85 83 86 @Override 84 87 protected void validateRequest() throws RequestHandlerBadRequestException { 85 88 ps.clear(); 86 for (String i : args.get("objects").split(",\\s*")) {89 for (String i : SPLIT_OBJECTS_PATTERN.split(args.get("objects"))) { 87 90 try { 88 91 ps.add(SimplePrimitiveId.fromString(i)); 89 92 } catch (IllegalArgumentException e) { -
src/org/openstreetmap/josm/plugins/PluginInformation.java
22 22 import java.util.jar.Attributes; 23 23 import java.util.jar.JarInputStream; 24 24 import java.util.jar.Manifest; 25 import java.util.regex.Pattern; 25 26 import javax.swing.ImageIcon; 26 27 27 28 import org.openstreetmap.josm.Main; … … 37 38 * @author imi 38 39 */ 39 40 public class PluginInformation { 41 40 42 public File file = null; 41 43 public String name = null; 42 44 public int mainversion = 0; … … 332 334 } 333 335 } 334 336 337 private static final Pattern PLUGIN_NAME_PATTERN = Pattern.compile("[-. ]"); 338 335 339 /** 336 340 * Try to find a plugin after some criterias. Extract the plugin-information 337 341 * from the plugin and return it. The plugin is searched in the following way: … … 369 373 */ 370 374 public static PluginInformation findPlugin(String pluginName) throws PluginException { 371 375 String name = pluginName; 372 name = name.replaceAll("[-. ]","");376 name = PLUGIN_NAME_PATTERN.matcher(name).replaceAll(""); 373 377 InputStream manifestStream = PluginInformation.class.getResourceAsStream("/org/openstreetmap/josm/plugins/"+name+"/MANIFEST.MF"); 374 378 if (manifestStream != null) 375 379 return new PluginInformation(manifestStream, pluginName, null); … … 441 445 */ 442 446 public boolean matches(String filter) { 443 447 if (filter == null) return true; 444 String[] words = filter.split("\\s+");448 String[] words = Utils.WHITE_SPACES_PATTERN.split(filter); 445 449 for (String word: words) { 446 450 if (matches(word, name) 447 451 || matches(word, description) -
src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
12 12 import java.util.HashMap; 13 13 import java.util.List; 14 14 import java.util.Map; 15 import java.util.regex.Pattern; 15 16 16 17 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 17 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 35 36 * 36 37 */ 37 38 public class ReadLocalPluginInformationTask extends PleaseWaitRunnable { 39 38 40 private Map<String, PluginInformation> availablePlugins; 39 41 private boolean canceled; 40 42 … … 70 72 } 71 73 } 72 74 75 private static final Pattern SITE_NAME_PATTERN = Pattern.compile("^([0-9]+-)?site.*\\.txt$"); 76 73 77 protected void scanSiteCacheFiles(ProgressMonitor monitor, File pluginsDirectory) { 74 78 File[] siteCacheFiles = pluginsDirectory.listFiles( 75 79 new FilenameFilter() { 76 80 @Override 77 81 public boolean accept(File dir, String name) { 78 return name.matches("^([0-9]+-)?site.*\\.txt$");82 return SITE_NAME_PATTERN.matcher(name).matches(); 79 83 } 80 84 } 81 85 ); … … 96 100 } 97 101 } 98 102 103 private static final Pattern ICON_NAME_PATTERN = Pattern.compile("^([0-9]+-)?site.*plugin-icons\\.zip$"); 104 99 105 protected void scanIconCacheFiles(ProgressMonitor monitor, File pluginsDirectory) { 100 106 File[] siteCacheFiles = pluginsDirectory.listFiles( 101 107 new FilenameFilter() { 102 108 @Override 103 109 public boolean accept(File dir, String name) { 104 return name.matches("^([0-9]+-)?site.*plugin-icons\\.zip$");110 return ICON_NAME_PATTERN.matcher(name).matches(); 105 111 } 106 112 } 107 113 ); -
src/org/openstreetmap/josm/tools/LanguageInfo.java
2 2 package org.openstreetmap.josm.tools; 3 3 4 4 import java.util.Locale; 5 import java.util.regex.Pattern; 5 6 6 7 public class LanguageInfo { 8 7 9 /** 8 10 * Type of the locale to use 9 11 * @since 5915 … … 19 21 ENGLISH 20 22 }; 21 23 24 private static final Pattern WL_PREFFIX_PATTERN = Pattern.compile("[^_]+_[^_]+"); 25 22 26 /** 23 27 * Replies the wiki language prefix for the given locale. The wiki language 24 28 * prefix has the form 'Xy:' where 'Xy' is a ISO 639 language code in title 25 29 * case (or Xy_AB: for sub languages). 26 30 * 27 31 * @param type the type 28 * @return the wiki language prefix or {@code null} for {@link LocaleType#BASELANGUAGE}, when32 * @return the wiki language prefix or {@code null} for {@link org.openstreetmap.josm.tools.LanguageInfo.LocaleType#BASELANGUAGE}, when 29 33 * base language is identical to default or english 30 34 * @since 5915 31 35 */ … … 35 39 36 40 String code = getJOSMLocaleCode(); 37 41 if(type == LocaleType.BASELANGUAGE) { 38 if( code.matches("[^_]+_[^_]+")) {42 if(WL_PREFFIX_PATTERN.matcher(code).matches()) { 39 43 code = code.substring(0,2); 40 44 if(code == "en") 41 45 return null; … … 51 55 * Replies the wiki language prefix for the current locale. 52 56 * 53 57 * @return the wiki language prefix 54 * @see Locale#getDefault()55 * @see #getWikiLanguagePrefix( LocaleType)58 * @see java.util.Locale#getDefault() 59 * @see #getWikiLanguagePrefix(org.openstreetmap.josm.tools.LanguageInfo.LocaleType) 56 60 */ 57 61 static public String getWikiLanguagePrefix() { 58 62 return getWikiLanguagePrefix(LocaleType.DEFAULT); … … 62 66 * Replies the JOSM locale code for the default locale. 63 67 * 64 68 * @return the JOSM locale code for the default locale 65 * @see #getJOSMLocaleCode( Locale)69 * @see #getJOSMLocaleCode(java.util.Locale) 66 70 */ 67 71 static public String getJOSMLocaleCode() { 68 72 return getJOSMLocaleCode(Locale.getDefault()); … … 71 75 /** 72 76 * Replies the locale code used by JOSM for a given locale. 73 77 * 74 * In most cases JOSM uses the 2-character ISO 639 language code ({@link Locale#getLanguage()}78 * In most cases JOSM uses the 2-character ISO 639 language code ({@link java.util.Locale#getLanguage()} 75 79 * to identify the locale of a localized resource, but in some cases it may use the 76 * programmatic name for locales, as replied by {@link Locale#toString()}.80 * programmatic name for locales, as replied by {@link java.util.Locale#toString()}. 77 81 * 78 82 * @param locale the locale. Replies "en" if null. 79 83 * @return the JOSM code for the given locale -
src/org/openstreetmap/josm/tools/Utils.java
32 32 import java.util.Collection; 33 33 import java.util.Iterator; 34 34 import java.util.List; 35 import java.util.regex.Pattern; 35 36 import java.util.zip.ZipFile; 36 37 37 38 import org.openstreetmap.josm.Main; … … 42 43 */ 43 44 public class Utils { 44 45 46 public static final Pattern WHITE_SPACES_PATTERN = Pattern.compile("\\s+"); 47 public static final Pattern DIGITS_PATTERN = Pattern.compile("\\D+"); 48 45 49 public static <T> boolean exists(Iterable<? extends T> collection, Predicate<? super T> predicate) { 46 50 for (T item : collection) { 47 51 if (predicate.evaluate(item)) … … 245 249 * Taken from <a href="http://www.rgagnon.com/javadetails/java-0064.html">this article</a> (CC-NC-BY-SA) 246 250 * @param in The source file 247 251 * @param out The destination file 248 * @throws IOException If any I/O error occurs252 * @throws java.io.IOException If any I/O error occurs 249 253 */ 250 254 public static void copyFile(File in, File out) throws IOException { 251 255 // TODO: remove this function when we move to Java 7 (use Files.copy instead) … … 293 297 } 294 298 295 299 /** 296 * <p>Utility method for closing a {@link Closeable} object.</p>300 * <p>Utility method for closing a {@link java.io.Closeable} object.</p> 297 301 * 298 302 * @param c the closeable object. May be null. 299 303 */ … … 307 311 } 308 312 309 313 /** 310 * <p>Utility method for closing a {@link ZipFile}.</p>314 * <p>Utility method for closing a {@link java.util.zip.ZipFile}.</p> 311 315 * 312 316 * @param zip the zip file. May be null. 313 317 */ … … 476 480 477 481 /** 478 482 * Transforms the collection {@code c} into an unmodifiable collection and 479 * applies the {@link Function} {@code f} on each element upon access.483 * applies the {@link org.openstreetmap.josm.tools.Utils.Function} {@code f} on each element upon access. 480 484 * @param <A> class of input collection 481 485 * @param <B> class of transformed collection 482 486 * @param c a collection … … 518 522 519 523 /** 520 524 * Transforms the list {@code l} into an unmodifiable list and 521 * applies the {@link Function} {@code f} on each element upon access.525 * applies the {@link org.openstreetmap.josm.tools.Utils.Function} {@code f} on each element upon access. 522 526 * @param <A> class of input collection 523 527 * @param <B> class of transformed collection 524 528 * @param l a collection … … 561 565 return new Color(Integer.parseInt(clr, 16)); 562 566 } 563 567 568 private static final Pattern HTTP_PREFFIX_PATTERN = Pattern.compile("https?"); 569 564 570 /** 565 571 * Opens a HTTP connection to the given URL and sets the User-Agent property to JOSM's one. 566 572 * @param httpURL The HTTP url to open (must use http:// or https://) 567 573 * @return An open HTTP connection to the given URL 568 * @throws IOException if an I/O exception occurs.574 * @throws java.io.IOException if an I/O exception occurs. 569 575 * @since 5587 570 576 */ 571 577 public static HttpURLConnection openHttpConnection(URL httpURL) throws IOException { 572 if (httpURL == null || ! httpURL.getProtocol().matches("https?")) {578 if (httpURL == null || !HTTP_PREFFIX_PATTERN.matcher(httpURL.getProtocol()).matches()) { 573 579 throw new IllegalArgumentException("Invalid HTTP url"); 574 580 } 575 581 HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection(); … … 581 587 * Opens a connection to the given URL and sets the User-Agent property to JOSM's one. 582 588 * @param url The url to open 583 589 * @return An stream for the given URL 584 * @throws IOException if an I/O exception occurs.590 * @throws java.io.IOException if an I/O exception occurs. 585 591 * @since 5867 586 592 */ 587 593 public static InputStream openURL(URL url) throws IOException { … … 607 613 * Opens a connection to the given URL and sets the User-Agent property to JOSM's one. 608 614 * @param url The url to open 609 615 * @return An buffered stream reader for the given URL (using UTF-8) 610 * @throws IOException if an I/O exception occurs.616 * @throws java.io.IOException if an I/O exception occurs. 611 617 * @since 5868 612 618 */ 613 619 public static BufferedReader openURLReader(URL url) throws IOException { … … 619 625 * @param httpURL The HTTP url to open (must use http:// or https://) 620 626 * @param keepAlive 621 627 * @return An open HTTP connection to the given URL 622 * @throws IOException if an I/O exception occurs.628 * @throws java.io.IOException if an I/O exception occurs. 623 629 * @since 5587 624 630 */ 625 631 public static HttpURLConnection openHttpConnection(URL httpURL, boolean keepAlive) throws IOException {