/** * Validates a given primitive tag against a given validator. * * @param p The OSM primitive to test * @param k The key to validate * @param v The value to validate. May be {@code null} to use {@code p.get(k)} * @param validator The validator to run * @param code The error code to set if the validation fails * @return The error if the validation fails, {@code null} otherwise */ private TestError doValidateTag( OsmPrimitive p, String k, String v, AbstractValidator validator, int code) { TestError error = null; String value = v != null ? v : p.get(k); if (!validator.isValid(value)) { String errMsg = validator.getErrorMessage(); // Special treatment to allow URLs without protocol. See UrlValidator#isValid if (tr("URL contains an invalid protocol: {0}", (String) null).equals(errMsg)) { String proto = validator instanceof EmailValidator ? "mailto://" : "http://"; return doValidateTag(p, k, proto + value, validator, code); } String msg = tr("''{0}'': {1}", k, errMsg); String fix = validator.getFix(); if (fix != null) { error = new FixableTestError( this, Severity.WARNING, msg, code, p, new ChangePropertyCommand(p, k, fix)); } else { error = new TestError(this, Severity.WARNING, msg, code, p); } } return error; }