/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.lib.validator;
import java.io.Serializable;
import java.net.IDN;
import java.util.Arrays;
import java.util.Locale;
/**
* <p>
* <b>Domain name</b> validation routines.
* </p>
*
* <p>
* This validator provides methods for validating Internet domain names
* and top-level domains.
* </p>
*
* <p>
* Domain names are evaluated according
* to the standards <a href="http://www.ietf.org/rfc/rfc1034.txt">RFC1034</a>,
* section 3, and <a href="http://www.ietf.org/rfc/rfc1123.txt">RFC1123</a>,
* section 2.1. No accommodation is provided for the specialized needs of
* other applications; if the domain name has been URL-encoded, for example,
* validation will fail even though the equivalent plaintext version of the
* same name would have passed.
* </p>
*
* <p>
* Validation is also provided for top-level domains (TLDs) as defined and
* maintained by the Internet Assigned Numbers Authority (IANA):
* </p>
*
* <ul>
* <li>{@link #isValidInfrastructureTld} - validates infrastructure TLDs
* (<code>.arpa</code>, etc.)</li>
* <li>{@link #isValidGenericTld} - validates generic TLDs
* (<code>.com, .org</code>, etc.)</li>
* <li>{@link #isValidCountryCodeTld} - validates country code TLDs
* (<code>.us, .uk, .cn</code>, etc.)</li>
* </ul>
*
* <p>
* (<b>NOTE</b>: This class does not provide IP address lookup for domain names or
* methods to ensure that a given domain name matches a specific IP; see
* {@link java.net.InetAddress} for that functionality.)
* </p>
*
* @version $Revision: 1781829 $
* @since Validator 1.4
*/
public class DomainValidator implements Serializable{
private static final int MAX_DOMAIN_LENGTH = 253;
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final long serialVersionUID = -4407125112880174009L;
// Regular expression strings for hostnames (derived from RFC2396 and RFC 1123)
// RFC2396: domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
// Max 63 characters
private static final String DOMAIN_LABEL_REGEX = "\\p{Alnum}(?>[\\p{Alnum}-]{0,61}\\p{Alnum})?";
// RFC2396 toplabel = alpha | alpha *( alphanum | "-" ) alphanum
// Max 63 characters
private static final String TOP_LABEL_REGEX = "\\p{Alpha}(?>[\\p{Alnum}-]{0,61}\\p{Alnum})?";
// RFC2396 hostname = *( domainlabel "." ) toplabel [ "." ]
// Note that the regex currently requires both a domain label and a top level label, whereas
// the RFC does not. This is because the regex is used to detect if a TLD is present.
// If the match fails, input is checked against DOMAIN_LABEL_REGEX (hostnameRegex)
// RFC1123 sec 2.1 allows hostnames to start with a digit
private static final String DOMAIN_NAME_REGEX = "^(?:" + DOMAIN_LABEL_REGEX + "\\.)+" + "(" + TOP_LABEL_REGEX
+ ")\\.?$";
private final boolean allowLocal;
/**
* Singleton instance of this validator, which
* doesn't consider local addresses as valid.
*/
private static final DomainValidator DOMAIN_VALIDATOR = new DomainValidator(false);
/**
* Singleton instance of this validator, which does
* consider local addresses valid.
*/
private static final DomainValidator DOMAIN_VALIDATOR_WITH_LOCAL = new DomainValidator(true);
/**
* RegexValidator for matching domains.
*/
private final RegexValidator domainRegex = new RegexValidator(DOMAIN_NAME_REGEX);
/**
* RegexValidator for matching a local hostname
*/
// RFC1123 sec 2.1 allows hostnames to start with a digit
private final RegexValidator hostnameRegex = new RegexValidator(DOMAIN_LABEL_REGEX);
/**
* Returns the singleton instance of this validator. It
* will not consider local addresses as valid.
*
* @return the singleton instance of this validator
*/
public static synchronized DomainValidator getInstance(){
inUse = true;
return DOMAIN_VALIDATOR;
}
/**
* Returns the singleton instance of this validator,
* with local validation as required.
*
* @param allowLocal
* Should local addresses be considered valid?
* @return the singleton instance of this validator
*/
public static synchronized DomainValidator getInstance(boolean allowLocal){
inUse = true;
if (allowLocal){
return DOMAIN_VALIDATOR_WITH_LOCAL;
}
return DOMAIN_VALIDATOR;
}
/** Private constructor. */
private DomainValidator(boolean allowLocal){
this.allowLocal = allowLocal;
}
/**
* Returns true if the specified <code>String</code> parses
* as a valid domain name with a recognized top-level domain.
* The parsing is case-insensitive.
*
* @param domain
* the parameter to check for domain name syntax
* @return true if the parameter is a valid domain name
*/
public boolean isValid(String domain){
if (domain == null){
return false;
}
domain = unicodeToASCII(domain);
// hosts must be equally reachable via punycode and Unicode;
// Unicode is never shorter than punycode, so check punycode
// if domain did not convert, then it will be caught by ASCII
// checks in the regexes below
if (domain.length() > MAX_DOMAIN_LENGTH){
return false;
}
String[] groups = domainRegex.match(domain);
if (groups != null && groups.length > 0){
return isValidTld(groups[0]);
}
return allowLocal && hostnameRegex.isValid(domain);
}
// package protected for unit test access
// must agree with isValid() above
final boolean isValidDomainSyntax(String domain){
if (domain == null){
return false;
}
domain = unicodeToASCII(domain);
// hosts must be equally reachable via punycode and Unicode;
// Unicode is never shorter than punycode, so check punycode
// if domain did not convert, then it will be caught by ASCII
// checks in the regexes below
if (domain.length() > MAX_DOMAIN_LENGTH){
return false;
}
String[] groups = domainRegex.match(domain);
return (groups != null && groups.length > 0) || hostnameRegex.isValid(domain);
}
/**
* Returns true if the specified <code>String</code> matches any
* IANA-defined top-level domain. Leading dots are ignored if present.
* The search is case-insensitive.
*
* @param tld
* the parameter to check for TLD status, not null
* @return true if the parameter is a TLD
*/
public boolean isValidTld(String tld){
tld = unicodeToASCII(tld);
if (allowLocal && isValidLocalTld(tld)){
return true;
}
return isValidInfrastructureTld(tld) || isValidGenericTld(tld) || isValidCountryCodeTld(tld);
}
/**
Feilong开发工具库是一个广泛使用的Java开发框架,版本v4.0.8提供了一系列的工具类和组件,旨在简化开发过程,提高开发效率。这个压缩包包含的是Feilong库的核心源码,对于学习Java编程,特别是进行系统软件工具和建站模板开发的开发者来说,是一个宝贵的学习资源。 Feilong框架主要由以下几个核心模块组成: 1. **基础工具类**:Feilong提供了一套完善的基础工具类,包括日期时间处理、字符串操作、集合处理、IO流操作等,这些工具类经过优化,性能优秀且易用,可以避免重复造轮子。 2. **Web组件**:Feilong为Web开发提供了丰富的支持,如URL处理、HTTP请求与响应操作、JSON转换、视图渲染等,帮助开发者快速构建Web应用。 3. **MVC框架**:Feilong包含了轻量级的MVC框架,用于处理控制器逻辑,实现模型、视图、控制器的解耦,方便开发者进行业务逻辑的编写。 4. **异常处理**:Feilong提供了统一的异常处理机制,可以帮助开发者更好地管理和处理程序中的异常,提高代码的健壮性。 5. **日志模块**:集成常见的日志框架,如Log4j、SLF4J等,提供灵活的日志配置和记录,便于调试和追踪问题。 6. **国际化支持**:Feilong支持多语言环境,提供便捷的国际化和本地化处理,使得应用能够适应不同的地域市场。 7. **安全组件**:包括验证码生成、密码加密、权限控制等功能,增强了系统的安全性。 8. **性能监控**:提供了一些性能监控工具,如请求统计、内存监控等,有助于开发者对系统的性能进行评估和优化。 9. **测试支持**:Feilong提供了测试相关的工具,如模拟HTTP请求、数据准备等,方便单元测试和集成测试的执行。 10. **兼容性**:Feilong框架兼容多种Java运行环境和Web服务器,与Spring、MyBatis等主流框架无缝集成,降低了迁移成本。 对于毕业设计论文或计算机案例分析,Feilong源码可以作为深入理解Java开发实践、设计模式和最佳实践的实例。通过对源码的阅读和学习,开发者不仅可以掌握Feilong的功能,还能了解到如何设计和实现一个高效、易用的开发工具库。 在建站模板开发中,Feilong的Web组件和MVC框架可以快速搭建页面逻辑,提高开发速度。同时,其异常处理和日志模块能确保模板在运行时的稳定性和可维护性。 "feilong开发工具库 v4.0.8.zip"是一个全面的Java开发辅助工具,包含了大量的实用功能,无论是初学者还是经验丰富的开发者,都能从中受益。通过深入研究和应用,可以提升开发技能,提高项目开发效率。





























































































































- 1
- 2
- 3
- 4
- 5
- 6
- 20

- #完美解决问题
- #运行顺畅
- #内容详尽
- #全网独家
- #注释完整

- 粉丝: 6w+
- 资源: 2万+
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 图书管理系统+jsp--LW.zip
- 实验室耗材管理系统设计与实现+jsp--LW.zip
- 蜀都天香酒楼的网站设计与实现+jsp--LW.zip
- 【计算机课程设计】资源
- 物流选址中粒子群优化算法的MATLAB高效实现及应用
- 【计算机课程设计】资源
- 网络游戏公司官方平台设计与实现+jsp--LW.zip
- 网上服装销售系统+jsp--LW.zip
- 网上花店设计+vue--LW.zip
- 【计算机课程设计】资源
- 物流管理系统设计与实现+jsp--LW.zip
- 网上医院预约挂号系统+jsp--LW.zip
- 【计算机课程设计】资源
- 线上旅行信息管理系统ssm+vue--LW.zip
- 【计算机课程设计】资源
- 乡镇自来水收费系统+jsp--LW.zip


