public void testValidator202() { String[] schemes = {"http","https"}; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS); urlValidator.isValid("http://www.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.log"); }
if (!isValidScheme(urlMatcher.group(PARSE_URL_SCHEME))) { return false; if (!isValidAuthority(urlMatcher.group(PARSE_URL_AUTHORITY))) { return false; if (!isValidPath(urlMatcher.group(PARSE_URL_PATH))) { return false; if (!isValidQuery(urlMatcher.group(PARSE_URL_QUERY))) { return false; if (!isValidFragment(urlMatcher.group(PARSE_URL_FRAGMENT))) { return false;
/** * Returns true if the path is valid. A <code>null</code> value is considered invalid. * @param path Path value to validate. * @return true if path is valid. */ protected boolean isValidPath(String path) { if (path == null) { return false; } if (!PATH_PATTERN.matcher(path).matches()) { return false; } int slash2Count = countToken("//", path); if (options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) { return false; } int slashCount = countToken("/", path); int dot2Count = countToken("..", path); if (dot2Count > 0 && (slashCount - slash2Count - 1) <= dot2Count){ return false; } return true; }
public void testIsValidScheme() { if (printStatus) { System.out.print("\n testIsValidScheme() "); } String[] schemes = {"http", "gopher"}; //UrlValidator urlVal = new UrlValidator(schemes,false,false,false); UrlValidator urlVal = new UrlValidator(schemes, 0); for (int sIndex = 0; sIndex < testScheme.length; sIndex++) { ResultPair testPair = testScheme[sIndex]; boolean result = urlVal.isValidScheme(testPair.item); assertEquals(testPair.item, testPair.valid, result); if (printStatus) { if (result == testPair.valid) { System.out.print('.'); } else { System.out.print('X'); } } } if (printStatus) { System.out.println(); } }
/** * <p>Checks if a field is a valid url address.</p> * If you need to modify what is considered valid then * consider using the UrlValidator directly. * * @param value The value validation is being performed on. * @return true if the value is valid Url. */ public static boolean isUrl(String value) { return URL_VALIDATOR.isValid(value); }
public QueueURLValidator() { this(new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES)); }
@Override public boolean check(final String value) { return URL_VALIDATOR.isValid(Constants.HTTP + value); }
private org.apache.commons.validator.UrlValidator initValidator() { int options = 0; if (isAllow2Slashes()) { options = options | org.apache.commons.validator.UrlValidator.ALLOW_2_SLASHES; } if (isAllowAllSchemas()) { options = options | org.apache.commons.validator.UrlValidator.ALLOW_ALL_SCHEMES; } String [] schemesList = getSchemesList(); org.apache.commons.validator.UrlValidator urlValidator = null; if (schemesList == null){ urlValidator = new org.apache.commons.validator.UrlValidator(options); } else { urlValidator = new org.apache.commons.validator.UrlValidator(schemesList,options); } return urlValidator; }
public void testValidator204() { String[] schemes = {"http","https"}; UrlValidator urlValidator = new UrlValidator(schemes); assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5")); }
private void isValidUri(StartupForm target, List<String> errors, String uri) { if (!isNullOrEmpty(target.getQueueUrl()) && !urlValidator.isValid(uri)) { errors.add(String.format(ERROR_INVALID, QUEUE_URL)); } }
if (!isValidScheme(urlMatcher.getGroup(PARSE_URL_SCHEME))) { return false; if (!isValidAuthority(urlMatcher.getGroup(PARSE_URL_AUTHORITY))) { return false; if (!isValidPath(urlMatcher.getGroup(PARSE_URL_PATH))) { return false; if (!isValidQuery(urlMatcher.getGroup(PARSE_URL_QUERY))) { return false; if (!isValidFragment(urlMatcher.getGroup(PARSE_URL_FRAGMENT))) { return false;
private org.apache.commons.validator.UrlValidator initValidator() { int options = 0; if (isAllow2Slashes()) { options = options | org.apache.commons.validator.UrlValidator.ALLOW_2_SLASHES; } if (isAllowAllSchemas()) { options = options | org.apache.commons.validator.UrlValidator.ALLOW_ALL_SCHEMES; } String [] schemesList = getSchemesList(); org.apache.commons.validator.UrlValidator urlValidator = null; if (schemesList == null){ urlValidator = new org.apache.commons.validator.UrlValidator(options); } else { urlValidator = new org.apache.commons.validator.UrlValidator(schemesList,options); } return urlValidator; }
/** * Returns true if the path is valid. A <code>null</code> value is considered invalid. * @param path Path value to validate. * @return true if path is valid. */ protected boolean isValidPath(String path) { if (path == null) { return false; } if (PATH_PATTERN.exec(path) == null) { return false; } int slash2Count = countToken("//", path); if (options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) { return false; } int slashCount = countToken("/", path); int dot2Count = countToken("..", path); if (dot2Count > 0 && (slashCount - slash2Count - 1) <= dot2Count){ return false; } return true; }
UrlValidator urlVal = new UrlValidator(null, options); assertTrue(urlVal.isValid("http://www.google.com")); assertTrue(urlVal.isValid("http://www.google.com/")); int statusPerLine = 60; int printed = 0; boolean result = urlVal.isValid(url); assertEquals(url, expected, result); if (printStatus) {
/** * method that validates an url address. * it uses the commons-validator */ public void validate( FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException { if (facesContext == null) throw new NullPointerException("facesContext"); if (uiComponent == null) throw new NullPointerException("uiComponent"); if (value == null) { return; } org.apache.commons.validator.UrlValidator urlValidator = initValidator(); if (!urlValidator.isValid(value.toString())) { Object[] args = {value.toString()}; throw new ValidatorException(getFacesMessage(URL_MESSAGE_ID, args)); } }
if (!isValidScheme(matchUrlPat.group(PARSE_URL_SCHEME))) { return false; if (!isValidAuthority(matchUrlPat.group(PARSE_URL_AUTHORITY))) { return false; if (!isValidPath(matchUrlPat.group(PARSE_URL_PATH))) { return false; if (!isValidQuery(matchUrlPat.group(PARSE_URL_QUERY))) { return false; if (!isValidFragment(matchUrlPat.group(PARSE_URL_FRAGMENT))) { return false;
private org.apache.commons.validator.UrlValidator initValidator() { int options = 0; if (isAllow2Slashes()) { options = options | org.apache.commons.validator.UrlValidator.ALLOW_2_SLASHES; } if (isAllowAllSchemas()) { options = options | org.apache.commons.validator.UrlValidator.ALLOW_ALL_SCHEMES; } String [] schemesList = getSchemesList(); org.apache.commons.validator.UrlValidator urlValidator = null; if (schemesList == null) { urlValidator = new org.apache.commons.validator.UrlValidator(options); } else { urlValidator = new org.apache.commons.validator.UrlValidator(schemesList,options); } return urlValidator; }
/** * Returns true if the path is valid. A <code>null</code> value is considered invalid. * @param path Path value to validate. * @return true if path is valid. */ protected boolean isValidPath(String path) { if (path == null) { return false; } Perl5Util pathMatcher = new Perl5Util(); if (!pathMatcher.match(PATH_PATTERN, path)) { return false; } int slash2Count = countToken("//", path); if (this.options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) { return false; } int slashCount = countToken("/", path); int dot2Count = countToken("..", path); if (dot2Count > 0) { if ((slashCount - slash2Count - 1) <= dot2Count) { return false; } } return true; }
@Override public boolean validate(String value) { System.out.println("Validating " + value); String[] schemes = {"http", "https", "ftp"}; UrlValidator urlValidator = new UrlValidator(schemes); return value.isEmpty() || urlValidator.isValid(value); }
/** * method that validates an url address. * it uses the commons-validator */ public void validate( FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException { if (facesContext == null) throw new NullPointerException("facesContext"); if (uiComponent == null) throw new NullPointerException("uiComponent"); if (value == null) { return; } org.apache.commons.validator.UrlValidator urlValidator = initValidator(); if (!urlValidator.isValid(value.toString())) { Object[] args = {value.toString()}; throw new ValidatorException(getFacesMessage(URL_MESSAGE_ID, args)); } }