List of usage examples for org.apache.commons.validator.routines DomainValidator isValid
public boolean isValid(String domain)
String
parses as a valid domain name with a recognized top-level domain. From source file:com.netease.backend.collector.rss.common.util.UrlValidator.java
/** * Returns true if the authority is properly formatted. An authority is the combination * of hostname and port. A <code>null</code> authority value is considered invalid. * @param authority Authority value to validate. * @return true if authority (hostname and port) is valid. */// www .j a v a 2 s.com protected boolean isValidAuthority(String authority) { if (authority == null) { return false; } // check manual authority validation if specified if (authorityValidator != null) { if (authorityValidator.isValid(authority)) { return true; } } Matcher authorityMatcher = AUTHORITY_PATTERN.matcher(authority); if (!authorityMatcher.matches()) { return false; } String hostLocation = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP); // check if authority is hostname or IP address: // try a hostname first since that's much more likely DomainValidator domainValidator = DomainValidator.getInstance(isOn(ALLOW_LOCAL_URLS)); if (!domainValidator.isValid(hostLocation)) { // try an IP address InetAddressValidator inetAddressValidator = InetAddressValidator.getInstance(); if (!inetAddressValidator.isValid(hostLocation)) { // isn't either one, so the URL is invalid return false; } } String port = authorityMatcher.group(PARSE_AUTHORITY_PORT); if (port != null) { if (!PORT_PATTERN.matcher(port).matches()) { return false; } } String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA); if (extra != null && extra.trim().length() > 0) { return false; } return true; }
From source file:org.lirazs.gbackbone.validation.client.rule.DomainRule.java
@Override public boolean isValid(final String domain, String attribute) { boolean allowLocal = ruleAnnotation.allowLocal(); DomainValidator domainValidator = DomainValidator.getInstance(allowLocal); return domainValidator.isValid(domain); }
From source file:org.mule.modules.validation.ValidationModule.java
/** * If the specified <code>domain</code> does not parses as a valid domain name with a recognized top-level domain then * throw an exception.//ww w. j a v a 2 s . c o m * <p/> * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:is-domain} * * @param domain Domain name to validate * @param customExceptionClassName Class name of the exception to throw * @throws Exception if not valid */ @Processor public void validateDomain(String domain, @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName) throws Exception { DomainValidator validator = DomainValidator.getInstance(); if (!validator.isValid(domain)) { throw buildException(customExceptionClassName); } }