本文整理汇总了Java中org.apache.commons.validator.routines.DomainValidator类的典型用法代码示例。如果您正苦于以下问题:Java DomainValidator类的具体用法?Java DomainValidator怎么用?Java DomainValidator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DomainValidator类属于org.apache.commons.validator.routines包,在下文中一共展示了DomainValidator类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidAuthorityHostNoDot
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
/**
* Check if the authority contains a valid hostname without "."
* characters and an optional port number
*
* @param authority
* @return <code>true</code> if the authority is valid
*/
private boolean isValidAuthorityHostNoDot(String authority) {
Perl5Util authorityMatcher = new Perl5Util();
if (authority != null
&& authorityMatcher.match(
"/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) {
String hostIP = authorityMatcher.group(1);
if (hostIP.indexOf('.') < 0) {
// the hostname contains no dot, add domain validation to check invalid hostname like "g08fnstd110825-"
DomainValidator domainValidator = DomainValidator.getInstance(true);
if(!domainValidator.isValid(hostIP)) {
return false;
}
String port = authorityMatcher.group(2);
if (!isValidPort(port)) {
return false;
}
String extra = authorityMatcher.group(3);
return GenericValidator.isBlankOrNull(extra);
} else {
return false;
}
} else {
return false;
}
}
示例2: isValidAuthorityHostNoTld
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
/**
* Check if the authority contains a hostname without top level domain
* and an optional port number
*
* @param authority
* @return <code>true</code> if the authority is valid
*/
private boolean isValidAuthorityHostNoTld(String authority) {
Perl5Util authorityMatcher = new Perl5Util();
if (authority != null
&& authorityMatcher.match(
"/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) {
String host = authorityMatcher.group(1);
if (host.indexOf('.') > 0) {
DomainValidator domainValidator = DomainValidator.getInstance();
// Make the host have a valid TLD, so that the "no TLD" host can pass the domain validation.
String patchedHost = host + ".com";
if(!domainValidator.isValid(patchedHost)) {
return false;
}
String port = authorityMatcher.group(2);
if (!isValidPort(port)) {
return false;
}
String extra = authorityMatcher.group(3);
return GenericValidator.isBlankOrNull(extra);
} else {
return false;
}
} else {
return false;
}
}
示例3: validateKaaHost
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Override
public void validateKaaHost(String host) throws SandboxServiceException {
if (host == null || host.length() == 0) {
throw new SandboxServiceException("Kaa host field can not be empty!");
} else if (!InetAddressValidator.getInstance().isValid(host) &&
!DomainValidator.getInstance(true).isValid(host)) {
throw new SandboxServiceException("Invalid hostname/ip address format!");
}
}
示例4: validate
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
private void validate(APICreateL3NetworkMsg msg) {
if (!L3NetworkType.hasType(msg.getType())) {
throw new ApiMessageInterceptionException(argerr("unsupported l3network type[%s]", msg.getType()));
}
if (msg.getDnsDomain() != null) {
DomainValidator validator = DomainValidator.getInstance();
if (!validator.isValid(msg.getDnsDomain())) {
throw new ApiMessageInterceptionException(argerr("%s is not a valid domain name", msg.getDnsDomain()));
}
}
List<L3NetworkCategory> validNetworkCategory = Arrays.asList(L3NetworkCategory.values());
for (L3NetworkCategory category : validNetworkCategory) {
if (category.toString().equalsIgnoreCase(msg.getCategory())) {
msg.setCategory(category.toString());
break;
}
}
if (L3NetworkCategory.checkSystemAndCategory(msg.isSystem(), L3NetworkCategory.valueOf(msg.getCategory()))) {
return;
} else {
throw new ApiMessageInterceptionException(argerr("not valid combination of system and category," +
"only %s are valid", L3NetworkCategory.validCombination));
}
}
示例5: isValid
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Override
public boolean isValid(String s) {
if (s.matches("^.*://.*$")) {
return org.apache.commons.validator.routines.UrlValidator.getInstance().isValid(s);
} else {
String[] parts = s.split("/");
if (parts.length > 1) {
return DomainValidator.getInstance().isValid(parts[0]);
}
}
return DomainValidator.getInstance().isValid(s);
}
示例6: OutgoingEmailValidator
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Inject
OutgoingEmailValidator(@GerritServerConfig Config config) {
String[] allowTLD = config.getStringList("sendemail", null, "allowTLD");
if (allowTLD.length != 0) {
try {
DomainValidator.updateTLDOverride(GENERIC_PLUS, allowTLD);
} catch (IllegalStateException e) {
// Should only happen in tests, where the OutgoingEmailValidator
// is instantiated repeatedly.
log.error("Failed to update TLD override: " + e.getMessage());
}
}
}
示例7: expectDomainName
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
/**
* Validates a field to be a valid IPv4 address
*
* @param name The field to check
* @param message A custom error message instead of the default one
*/
public void expectDomainName(String name, String message) {
String value = Optional.ofNullable(get(name)).orElse("");
if (!DomainValidator.getInstance().isValid(value)) {
addError(name, Optional.ofNullable(message).orElse(messages.get(Validation.DOMAIN_NAME_KEY.name(), name)));
}
}
示例8: test
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Override
public boolean test(String value) {
return DomainValidator.getInstance().isValid(value);
}
示例9: matchesHostname
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
private static boolean matchesHostname(String value) {
return DomainValidator.getInstance().isValid(value);
}
示例10: isValid
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Override
public boolean isValid(final String domain, String attribute) {
boolean allowLocal = ruleAnnotation.allowLocal();
DomainValidator domainValidator = DomainValidator.getInstance(allowLocal);
return domainValidator.isValid(domain);
}
示例11: isValidNonBlankValue
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Override
public boolean isValidNonBlankValue(String value, ConstraintValidatorContext context) {
return DomainValidator.getInstance().isValid(value);
}
示例12: isValid
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Override
public boolean isValid(String s) {
return DomainValidator.getInstance().isValid(s);
}
示例13: getPredicate
import org.apache.commons.validator.routines.DomainValidator; //导入依赖的package包/类
@Override
public Predicate<Object> getPredicate() {
return domain -> DomainValidator.getInstance().isValid(domain == null?null:domain.toString());
}