Changeset 13145 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-11-22T21:37:46+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/validation/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java
r13017 r13145 199 199 if (condition.matches(".*[0-9]:[0-9]{2}.*")) { 200 200 final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax( 201 "", condition, OpeningHourTest.CheckMode.TIME_RANGE,true, LanguageInfo.getJOSMLocaleCode());201 "", condition, true, LanguageInfo.getJOSMLocaleCode()); 202 202 if (!errors.isEmpty()) { 203 203 return errors.get(0).getMessage(); -
trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
r12620 r13145 57 57 ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};"); 58 58 ENGINE.eval( 59 "var oh = function (value, mode, locale) {" +59 "var oh = function (value, tag_key, locale) {" + 60 60 " try {" + 61 " var r = new opening_hours(value, nominatimJSON, { mode: mode, locale: locale});" +61 " var r = new opening_hours(value, nominatimJSON, {tag_key: tag_key, locale: locale});" + 62 62 " r.getErrors = function() {return [];};" + 63 63 " return r;" + … … 76 76 } 77 77 78 enum CheckMode { 79 TIME_RANGE(0), POINTS_IN_TIME(1), BOTH(2); 80 private final int code; 81 82 CheckMode(int code) { 83 this.code = code; 84 } 85 } 86 87 protected Object parse(String value, CheckMode mode, String locale) throws ScriptException, NoSuchMethodException { 88 return ((Invocable) ENGINE).invokeFunction("oh", value, mode.code, locale); 78 /** 79 * Parses the opening hour syntax of the {@code value} given according to 80 * <a href="https://github.com/ypid/opening_hours.js">opening_hours.js</a> and returns an object on which 81 * methods can be called to extract information. 82 * @param value the opening hour value to be checked 83 * @param tagKey the OSM key (should be "opening_hours", "collection_times" or "service_times") 84 * @param locale the locale code used for localizing messages 85 * @return The value returned by the underlying method. Usually a {@code jdk.nashorn.api.scripting.ScriptObjectMirror} 86 * @throws ScriptException if an error occurs during invocation of the underlying method 87 * @throws NoSuchMethodException if underlying method with given name or matching argument types cannot be found 88 * @since 13145 89 */ 90 public Object parse(String value, String tagKey, String locale) throws ScriptException, NoSuchMethodException { 91 return ((Invocable) ENGINE).invokeFunction("oh", value, tagKey, locale); 89 92 } 90 93 … … 177 180 * @param key the OSM key (should be "opening_hours", "collection_times" or "service_times"). Used in error message 178 181 * @param value the opening hour value to be checked. 179 * @param mode whether to validate {@code value} as a time range, or points in time, or both.180 182 * @return a list of {@link TestError} or an empty list 181 183 */ 182 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value , CheckMode mode) {183 return checkOpeningHourSyntax(key, value, mode,false, LanguageInfo.getJOSMLocaleCode());184 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value) { 185 return checkOpeningHourSyntax(key, value, false, LanguageInfo.getJOSMLocaleCode()); 184 186 } 185 187 … … 190 192 * @param key the OSM key (should be "opening_hours", "collection_times" or "service_times"). 191 193 * @param value the opening hour value to be checked. 192 * @param mode whether to validate {@code value} as a time range, or points in time, or both.193 194 * @param ignoreOtherSeverity whether to ignore errors with {@link Severity#OTHER}. 194 195 * @param locale the locale code used for localizing messages 195 196 * @return a list of {@link TestError} or an empty list 196 197 */ 197 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value, CheckMode mode,198 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value, 198 199 boolean ignoreOtherSeverity, String locale) { 199 200 if (ENGINE == null || value == null || value.isEmpty()) { … … 202 203 final List<OpeningHoursTestError> errors = new ArrayList<>(); 203 204 try { 204 final Object r = parse(value, mode, locale);205 final Object r = parse(value, key, locale); 205 206 String prettifiedValue = null; 206 207 try { … … 243 244 } 244 245 245 /** 246 * Checks for a correct usage of the opening hour syntax of the {@code value} given, in time range mode, according to 247 * <a href="https://github.com/ypid/opening_hours.js">opening_hours.js</a> and returns a list containing 248 * validation errors or an empty list. Null values result in an empty list. 249 * @param key the OSM key (should be "opening_hours", "collection_times" or "service_times"). Used in error message 250 * @param value the opening hour value to be checked. 251 * @return a list of {@link TestError} or an empty list 252 */ 253 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value) { 254 return checkOpeningHourSyntax(key, value, "opening_hours".equals(key) ? CheckMode.TIME_RANGE : CheckMode.BOTH); 255 } 256 257 protected void check(final OsmPrimitive p, final String key, CheckMode mode) { 258 for (OpeningHoursTestError e : checkOpeningHourSyntax(key, p.get(key), mode)) { 246 protected void check(final OsmPrimitive p, final String key) { 247 for (OpeningHoursTestError e : checkOpeningHourSyntax(key, p.get(key))) { 259 248 errors.add(e.getTestError(p, key)); 260 249 } … … 263 252 @Override 264 253 public void check(final OsmPrimitive p) { 265 check(p, "opening_hours" , CheckMode.TIME_RANGE);266 check(p, "collection_times" , CheckMode.BOTH);267 check(p, "service_times" , CheckMode.BOTH);254 check(p, "opening_hours"); 255 check(p, "collection_times"); 256 check(p, "service_times"); 268 257 } 269 258 }
Note:
See TracChangeset
for help on using the changeset viewer.