private void checkUrl(String url, ValidationResults results, boolean allowVars, Severity severity, String crumb) { // TODO Q: Any help from spec in being able to validate URLs with vars? E.g is our treatment here valid? We // assume vars can only appear where simple text can appear, so handling vars means relacing {.*} with "1" and // testing for URL validity. We use a digit instead of a letter because it covers vars in the port, and // elsewhere digits are always allowed where letters are. String origUrl = url; if (allowVars) { url = url.replaceAll("\\{[^}]+\\}", "1"); if (url.startsWith("1:")) { // "1" is not a valid scheme name, so we need to replace it with special scheme, for which we provide a // do-nothing protocol handler implementation url = SPECIAL_SCHEME + url.substring(1); if (!specialSchemeInited) { // register protocol handler for special scheme initSpecialScheme(); } } } try { new URL(url); } catch (MalformedURLException e) { results.addError(m.msg("BadUrl|Invalid URL", origUrl, e.toString()), crumb); } }
public void validateUrl(final String value, final ValidationResults results, boolean required, String crumb, final boolean allowVars, final Severity severity) { validateString(value, results, required, (Pattern) null, crumb); if (value != null) { checkUrl(value, results, allowVars, severity, crumb); } }
private PrinterStateReasons getPrinterStateReasons() { if (isInvalid) { PrinterStateReasons psr = new PrinterStateReasons(); psr.put(PrinterStateReason.SHUTDOWN, Severity.ERROR); return psr; } else { return null; } }
@Override public void validateObject(Xml xml, ValidationResults results) { // no validation for: name, prefix, attribute, wrapped validateUrl(xml.getNamespace(false), results, false, "namespace", false, Severity.WARNING); validateExtensions(xml.getExtensions(false), results); }
public void validateUrl(String value, ValidationResults results, boolean required, String crumb, boolean allowVars) { validateUrl(value, results, required, crumb, allowVars, Severity.ERROR); }