source: josm/trunk/src/org/openstreetmap/josm/io/UrlPatterns.java@ 15784

Last change on this file since 15784 was 15784, checked in by Don-vip, 4 years ago

see #18613 - rework download tasks / URL patterns

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import org.openstreetmap.josm.data.gpx.GpxData;
5
6/**
7 * Collection of {@link UrlPattern}s.
8 * @since 15784
9 */
10public final class UrlPatterns {
11
12 private static final String HTTPS = "https?://";
13 private static final String COMPRESSED = "(gz|xz|bz2?|zip)";
14
15 private UrlPatterns() {
16 // Hide public constructor
17 }
18
19 // CHECKSTYLE.OFF: MethodParamPad
20 // CHECKSTYLE.OFF: SingleSpaceSeparator
21
22 /**
23 * Patterns for Geojson download URLs.
24 */
25 public enum GeoJsonUrlPattern implements UrlPattern {
26 /** URL of remote geojson files, optionally compressed */
27 COMPRESSED_FILE(".*/(.*\\.(json|geojson)(\\."+COMPRESSED+")?)"),
28 /** URL of generic service providing geojson as output format */
29 FORMAT_GEOJSON (".*format=geojson.*");
30
31 private final String urlPattern;
32
33 GeoJsonUrlPattern(String urlPattern) {
34 this.urlPattern = HTTPS + urlPattern;
35 }
36
37 @Override
38 public String pattern() {
39 return urlPattern;
40 }
41 }
42
43 /**
44 * Patterns for GPX download URLs.
45 */
46 public enum GpxUrlPattern implements UrlPattern {
47 /** URL of identified GPX trace on OpenStreetMap website */
48 TRACE_ID (".*(osm|openstreetmap).org/trace/\\p{Digit}+/data"),
49 /** URL of identified GPX trace belonging to any user on OpenStreetMap website */
50 USER_TRACE_ID(".*(osm|openstreetmap).org/user/[^/]+/traces/(\\p{Digit}+)"),
51 /** URL of the edit link from the OpenStreetMap trace page */
52 EDIT_TRACE_ID(".*(osm|openstreetmap).org/edit/?\\?gpx=(\\p{Digit}+)(#.*)?"),
53
54 /** URL of OSM API trackpoints endpoint */
55 TRACKPOINTS_BBOX(".*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*"),
56 /** URL of HOT Tasking Manager (TM) */
57 TASKING_MANAGER(".*/api/v\\p{Digit}+/projects?/\\p{Digit}+/(tasks_as_gpx?.*|tasks/queries/gpx/\\?tasks=.*)"),
58
59 /** External GPX script */
60 EXTERNAL_GPX_SCRIPT(".*exportgpx.*"),
61 /** External GPX file */
62 EXTERNAL_GPX_FILE (".*/(.*\\.gpx)");
63
64 private final String urlPattern;
65
66 GpxUrlPattern(String urlPattern) {
67 this.urlPattern = HTTPS + urlPattern;
68 }
69
70 @Override
71 public String pattern() {
72 return urlPattern;
73 }
74
75 /**
76 * Determines if the given URL denotes an OSM gpx-related API call.
77 * @param url The url to check
78 * @return true if the url matches "Trace ID" API call or "Trackpoints bbox" API call, false otherwise
79 * @see GpxData#fromServer
80 */
81 public static boolean isGpxFromServer(String url) {
82 return TRACE_ID.matches(url) || TRACKPOINTS_BBOX.matches(url);
83 }
84 }
85
86 /**
87 * Patterns for Note download URLs.
88 */
89 public enum NoteUrlPattern implements UrlPattern {
90 /** URL of OSM API Notes endpoint */
91 API_URL (".*/api/0.6/notes.*"),
92 /** URL of OSM API Notes compressed dump file */
93 DUMP_FILE(".*/(.*\\.osn(\\."+COMPRESSED+")?)");
94
95 private final String urlPattern;
96
97 NoteUrlPattern(String urlPattern) {
98 this.urlPattern = HTTPS + urlPattern;
99 }
100
101 @Override
102 public String pattern() {
103 return urlPattern;
104 }
105 }
106
107 /**
108 * Patterns for OsmChange data download URLs.
109 */
110 public enum OsmChangeUrlPattern implements UrlPattern {
111 /** URL of OSM changeset on OpenStreetMap website */
112 OSM_WEBSITE ("www\\.(osm|openstreetmap)\\.org/changeset/(\\p{Digit}+).*"),
113 /** URL of OSM API 0.6 changeset */
114 OSM_API (".*/api/0.6/changeset/\\p{Digit}+/download"),
115 /** URL of remote .osc file */
116 EXTERNAL_OSC_FILE (".*/(.*\\.osc)"),
117 /** URL of remote compressed osc file */
118 EXTERNAL_COMPRESSED_FILE(".*/(.*\\.osc."+COMPRESSED+")");
119
120 private final String urlPattern;
121
122 OsmChangeUrlPattern(String urlPattern) {
123 this.urlPattern = HTTPS + urlPattern;
124 }
125
126 @Override
127 public String pattern() {
128 return urlPattern;
129 }
130 }
131
132 /**
133 * Patterns for OSM data download URLs.
134 */
135 public enum OsmUrlPattern implements UrlPattern {
136 /** URL of OSM API */
137 OSM_API_URL (".*/api/0.6/(map|nodes?|ways?|relations?|\\*).*"),
138 /** URL of Overpass API */
139 OVERPASS_API_URL (".*/interpreter\\?data=.*"),
140 /** URL of Overpass API (XAPI compatibility) */
141 OVERPASS_API_XAPI_URL (".*/xapi(\\?.*\\[@meta\\]|_meta\\?).*"),
142 /** URL of remote .osm file */
143 EXTERNAL_OSM_FILE (".*/(.*\\.osm)"),
144 /** URL of remote compressed osm file */
145 EXTERNAL_COMPRESSED_FILE(".*/(.*\\.osm\\."+COMPRESSED+")");
146
147 private final String urlPattern;
148
149 OsmUrlPattern(String urlPattern) {
150 this.urlPattern = HTTPS + urlPattern;
151 }
152
153 @Override
154 public String pattern() {
155 return urlPattern;
156 }
157 }
158
159 // CHECKSTYLE.ON: SingleSpaceSeparator
160 // CHECKSTYLE.ON: MethodParamPad
161}
Note: See TracBrowser for help on using the repository browser.