Changeset 13147 in josm for trunk/src/org
- Timestamp:
- 2017-11-23T00:44:47+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
r13145 r13147 199 199 if (condition.matches(".*[0-9]:[0-9]{2}.*")) { 200 200 final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax( 201 "", condition, true, LanguageInfo.getJOSMLocaleCode());201 "", condition, OpeningHourTest.CheckMode.TIME_RANGE, 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
r13145 r13147 57 57 ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};"); 58 58 ENGINE.eval( 59 "var oh = function (value, tag_key, locale) {" +59 "var oh = function (value, tag_key, mode, locale) {" + 60 60 " try {" + 61 " var r = new opening_hours(value, nominatimJSON, {tag_key: tag_key, locale: locale});" + 61 " var conf = {tag_key: tag_key, locale: locale};" + 62 " if (mode > -1) {" + 63 " conf.mode = mode;" + 64 " }" + 65 " var r = new opening_hours(value, nominatimJSON, conf);" + 62 66 " r.getErrors = function() {return [];};" + 63 67 " return r;" + … … 77 81 78 82 /** 83 * In OSM, the syntax originally designed to describe opening hours, is now used to describe a few other things as well. 84 * Some of those other tags work with points in time instead of time ranges. 85 * To support this the mode can be specified. 86 * @since 13147 87 */ 88 public enum CheckMode { 89 /** time ranges (opening_hours, lit, …) default */ 90 TIME_RANGE(0), 91 /** points in time */ 92 POINTS_IN_TIME(1), 93 /** both (time ranges and points in time, used by collection_times, service_times, …) */ 94 BOTH(2); 95 private final int code; 96 97 CheckMode(int code) { 98 this.code = code; 99 } 100 } 101 102 /** 79 103 * Parses the opening hour syntax of the {@code value} given according to 80 104 * <a href="https://github.com/ypid/opening_hours.js">opening_hours.js</a> and returns an object on which … … 82 106 * @param value the opening hour value to be checked 83 107 * @param tagKey the OSM key (should be "opening_hours", "collection_times" or "service_times") 108 * @param mode whether to validate {@code value} as a time range, or points in time, or both. Can be null 84 109 * @param locale the locale code used for localizing messages 85 110 * @return The value returned by the underlying method. Usually a {@code jdk.nashorn.api.scripting.ScriptObjectMirror} 86 111 * @throws ScriptException if an error occurs during invocation of the underlying method 87 112 * @throws NoSuchMethodException if underlying method with given name or matching argument types cannot be found 88 * @since 1314 589 */ 90 public Object parse(String value, String tagKey, String locale) throws ScriptException, NoSuchMethodException {91 return ((Invocable) ENGINE).invokeFunction("oh", value, tagKey, locale);113 * @since 13147 114 */ 115 public Object parse(String value, String tagKey, CheckMode mode, String locale) throws ScriptException, NoSuchMethodException { 116 return ((Invocable) ENGINE).invokeFunction("oh", value, tagKey, mode != null ? mode.code : -1, locale); 92 117 } 93 118 … … 183 208 */ 184 209 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value) { 185 return checkOpeningHourSyntax(key, value, false, LanguageInfo.getJOSMLocaleCode());210 return checkOpeningHourSyntax(key, value, null, false, LanguageInfo.getJOSMLocaleCode()); 186 211 } 187 212 … … 192 217 * @param key the OSM key (should be "opening_hours", "collection_times" or "service_times"). 193 218 * @param value the opening hour value to be checked. 219 * @param mode whether to validate {@code value} as a time range, or points in time, or both. Can be null 194 220 * @param ignoreOtherSeverity whether to ignore errors with {@link Severity#OTHER}. 195 221 * @param locale the locale code used for localizing messages 196 222 * @return a list of {@link TestError} or an empty list 197 223 */ 198 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value, 224 public List<OpeningHoursTestError> checkOpeningHourSyntax(final String key, final String value, CheckMode mode, 199 225 boolean ignoreOtherSeverity, String locale) { 200 226 if (ENGINE == null || value == null || value.isEmpty()) { … … 203 229 final List<OpeningHoursTestError> errors = new ArrayList<>(); 204 230 try { 205 final Object r = parse(value, key, locale);231 final Object r = parse(value, key, mode, locale); 206 232 String prettifiedValue = null; 207 233 try {
Note:
See TracChangeset
for help on using the changeset viewer.