优化代码注释为简体中文
This commit is contained in:
@@ -169,9 +169,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize destination postcode for zone match / persist.
|
||||
* Removes all Unicode whitespace (incl. NBSP / U+2005) and ASCII spaces;
|
||||
* strips Excel-style trailing ".0" on pure digits.
|
||||
* 规范化目的地邮编,用于分区匹配/持久化。
|
||||
* 移除所有 Unicode 空白字符(包括 NBSP / U+2005)和 ASCII 空格;
|
||||
* 去除纯数字末尾 Excel 风格的 ".0"。
|
||||
*/
|
||||
public static String normalizePostcode(String postcode)
|
||||
{
|
||||
@@ -681,12 +681,12 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares given {@code string} to a CharSequences vararg of {@code searchStrings},
|
||||
* returning {@code true} if the {@code string} is equal to any of the {@code searchStrings}, ignoring case.
|
||||
* 将给定的 {@code string} 与 {@code searchStrings} 可变参数中的字符序列进行比较,
|
||||
* 如果 {@code string} 与其中任意一个 {@code searchStrings} 相等(忽略大小写),则返回 {@code true}。
|
||||
*
|
||||
* @param string to compare, may be {@code null}.
|
||||
* @param searchStrings a vararg of strings, may be {@code null}.
|
||||
* @return {@code true} if the string is equal (case-insensitive) to any other element of {@code searchStrings};
|
||||
* @param string 要比较的字符串,可能为 {@code null}。
|
||||
* @param searchStrings 字符串可变参数,可能为 {@code null}。
|
||||
* @return 如果字符串与 {@code searchStrings} 中的任意其他元素相等(不区分大小写),则返回 {@code true};
|
||||
*/
|
||||
public static boolean equalsAnyIgnoreCase(final CharSequence string, final CharSequence... searchStrings)
|
||||
{
|
||||
|
||||
@@ -29,13 +29,13 @@ public class MimeTypeUtils
|
||||
public static final String[] DEFAULT_ALLOWED_EXTENSION = {
|
||||
// 图片
|
||||
"bmp", "gif", "jpg", "jpeg", "png",
|
||||
// word excel powerpoint
|
||||
// Word、Excel、PowerPoint 文档
|
||||
"doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt",
|
||||
// 压缩文件
|
||||
"rar", "zip", "gz", "bz2",
|
||||
// 视频格式
|
||||
"mp4", "avi", "rmvb",
|
||||
// pdf
|
||||
// pdf 文档
|
||||
"pdf" };
|
||||
|
||||
public static String getExtension(String prefix)
|
||||
|
||||
@@ -20,7 +20,7 @@ public class EscapeUtil
|
||||
TEXT[i] = new char[] { (char) i };
|
||||
}
|
||||
|
||||
// special HTML characters
|
||||
// 特殊的 HTML 字符
|
||||
TEXT['\''] = "'".toCharArray(); // 单引号
|
||||
TEXT['"'] = """.toCharArray(); // 双引号
|
||||
TEXT['&'] = "&".toCharArray(); // &符
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.regex.Pattern;
|
||||
public final class HTMLFilter
|
||||
{
|
||||
/**
|
||||
* regex flag union representing /si modifiers in php
|
||||
* 表示 php 中 /si 修饰符的正则表达式标志组合
|
||||
**/
|
||||
private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;
|
||||
private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL);
|
||||
@@ -45,60 +45,60 @@ public final class HTMLFilter
|
||||
private static final Pattern P_RIGHT_ARROW = Pattern.compile(">");
|
||||
private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>");
|
||||
|
||||
// @xxx could grow large... maybe use sesat's ReferenceMap
|
||||
// @xxx 可能会变得很大……也许可以使用 sesat 的 ReferenceMap
|
||||
private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* set of allowed html elements, along with allowed attributes for each element
|
||||
* 允许的 html 元素集合,以及每个元素允许的属性
|
||||
**/
|
||||
private final Map<String, List<String>> vAllowed;
|
||||
/**
|
||||
* counts of open tags for each (allowable) html element
|
||||
* 每个(允许的)html 元素当前打开的标签计数
|
||||
**/
|
||||
private final Map<String, Integer> vTagCounts = new HashMap<>();
|
||||
|
||||
/**
|
||||
* html elements which must always be self-closing (e.g. "<img />")
|
||||
* 必须始终自闭合的 html 元素(例如 "<img />")
|
||||
**/
|
||||
private final String[] vSelfClosingTags;
|
||||
/**
|
||||
* html elements which must always have separate opening and closing tags (e.g. "<b></b>")
|
||||
* 必须始终具有独立开始和结束标签的 html 元素(例如 "<b></b>")
|
||||
**/
|
||||
private final String[] vNeedClosingTags;
|
||||
/**
|
||||
* set of disallowed html elements
|
||||
* 不允许的 html 元素集合
|
||||
**/
|
||||
private final String[] vDisallowed;
|
||||
/**
|
||||
* attributes which should be checked for valid protocols
|
||||
* 需要校验协议是否有效的属性
|
||||
**/
|
||||
private final String[] vProtocolAtts;
|
||||
/**
|
||||
* allowed protocols
|
||||
* 允许的协议
|
||||
**/
|
||||
private final String[] vAllowedProtocols;
|
||||
/**
|
||||
* tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />")
|
||||
* 内容为空时应移除的标签(例如 "<b></b>" 或 "<b />")
|
||||
**/
|
||||
private final String[] vRemoveBlanks;
|
||||
/**
|
||||
* entities allowed within html markup
|
||||
* html 标记中允许的实体
|
||||
**/
|
||||
private final String[] vAllowedEntities;
|
||||
/**
|
||||
* flag determining whether comments are allowed in input String.
|
||||
* 用于标识输入字符串中是否允许注释的标志。
|
||||
*/
|
||||
private final boolean stripComment;
|
||||
private final boolean encodeQuotes;
|
||||
/**
|
||||
* flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>"
|
||||
* becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped.
|
||||
* 用于标识在遇到“不配对”的尖括号时是否尝试构造标签的标志(例如 "<b text </b>"
|
||||
* 会变成 "<b> text </b>")。如果设置为 false,不配对的尖括号将被 html 转义。
|
||||
*/
|
||||
private final boolean alwaysMakeTags;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* 默认构造方法。
|
||||
*/
|
||||
public HTMLFilter()
|
||||
{
|
||||
@@ -125,7 +125,7 @@ public final class HTMLFilter
|
||||
vSelfClosingTags = new String[] { "img" };
|
||||
vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" };
|
||||
vDisallowed = new String[] {};
|
||||
vAllowedProtocols = new String[] { "http", "mailto", "https" }; // no ftp.
|
||||
vAllowedProtocols = new String[] { "http", "mailto", "https" }; // 不支持 ftp。
|
||||
vProtocolAtts = new String[] { "src", "href" };
|
||||
vRemoveBlanks = new String[] { "a", "b", "strong", "i", "em" };
|
||||
vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" };
|
||||
@@ -135,9 +135,9 @@ public final class HTMLFilter
|
||||
}
|
||||
|
||||
/**
|
||||
* Map-parameter configurable constructor.
|
||||
* 可通过 Map 参数配置的构造方法。
|
||||
*
|
||||
* @param conf map containing configuration. keys match field names.
|
||||
* @param conf 包含配置的 map。键与字段名一致。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public HTMLFilter(final Map<String, Object> conf)
|
||||
@@ -171,7 +171,7 @@ public final class HTMLFilter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// my versions of some PHP library functions
|
||||
// 我实现的某些 PHP 库函数版本
|
||||
public static String chr(final int decimal)
|
||||
{
|
||||
return String.valueOf((char) decimal);
|
||||
@@ -190,10 +190,10 @@ public final class HTMLFilter
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* given a user submitted input String, filter out any invalid or restricted html.
|
||||
* 对用户提交的输入字符串,过滤掉任何无效或受限的 html。
|
||||
*
|
||||
* @param input text (i.e. submitted by a user) than may contain html
|
||||
* @return "clean" version of input, with only valid, whitelisted html elements allowed
|
||||
* @param input 可能包含 html 的文本(即用户提交的内容)
|
||||
* @return 输入的“干净”版本,仅允许有效且在 html 白名单中的元素
|
||||
*/
|
||||
public String filter(final String input)
|
||||
{
|
||||
@@ -242,7 +242,7 @@ public final class HTMLFilter
|
||||
if (alwaysMakeTags)
|
||||
{
|
||||
//
|
||||
// try and form html
|
||||
// 尝试构造 html
|
||||
//
|
||||
s = regexReplace(P_END_ARROW, "", s);
|
||||
// 不追加结束标签
|
||||
@@ -253,15 +253,15 @@ public final class HTMLFilter
|
||||
else
|
||||
{
|
||||
//
|
||||
// escape stray brackets
|
||||
// 转义多余的括号
|
||||
//
|
||||
s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s);
|
||||
s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s);
|
||||
|
||||
//
|
||||
// the last regexp causes '<>' entities to appear
|
||||
// (we need to do a lookahead assertion so that the last bracket can
|
||||
// be used in the next pass of the regexp)
|
||||
// 上一个正则表达式会导致出现 "<>" 实体
|
||||
// (我们需要使用先行断言,以便最后一个括号
|
||||
// 可以在正则表达式的下一次匹配中使用)
|
||||
//
|
||||
s = regexReplace(P_BOTH_ARROWS, "", s);
|
||||
}
|
||||
@@ -282,8 +282,8 @@ public final class HTMLFilter
|
||||
}
|
||||
m.appendTail(buf);
|
||||
|
||||
// these get tallied in processTag
|
||||
// (remember to reset before subsequent calls to filter method)
|
||||
// 这些计数在 processTag 中进行累加
|
||||
// (记住在后续调用 filter 方法之前重置计数)
|
||||
final StringBuilder sBuilder = new StringBuilder(buf.toString());
|
||||
for (String key : vTagCounts.keySet())
|
||||
{
|
||||
@@ -325,7 +325,7 @@ public final class HTMLFilter
|
||||
|
||||
private String processTag(final String s)
|
||||
{
|
||||
// ending tags
|
||||
// 结束标签
|
||||
Matcher m = P_END_TAG.matcher(s);
|
||||
if (m.find())
|
||||
{
|
||||
@@ -343,7 +343,7 @@ public final class HTMLFilter
|
||||
}
|
||||
}
|
||||
|
||||
// starting tags
|
||||
// 开始标签
|
||||
m = P_START_TAG.matcher(s);
|
||||
if (m.find())
|
||||
{
|
||||
@@ -424,7 +424,7 @@ public final class HTMLFilter
|
||||
}
|
||||
}
|
||||
|
||||
// comments
|
||||
// 注释
|
||||
m = P_COMMENT.matcher(s);
|
||||
if (!stripComment && m.find())
|
||||
{
|
||||
@@ -443,7 +443,7 @@ public final class HTMLFilter
|
||||
final String protocol = m.group(1);
|
||||
if (!inArray(protocol, vAllowedProtocols))
|
||||
{
|
||||
// bad protocol, turn into local anchor link instead
|
||||
// 协议不合法,改为本地锚点链接
|
||||
s = "#" + s.substring(protocol.length() + 1);
|
||||
if (s.startsWith("#//"))
|
||||
{
|
||||
@@ -499,7 +499,7 @@ public final class HTMLFilter
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
// validate entities throughout the string
|
||||
// 校验整个字符串中的实体
|
||||
Matcher m = P_VALID_ENTITIES.matcher(s);
|
||||
while (m.find())
|
||||
{
|
||||
|
||||
@@ -569,12 +569,12 @@ public class ExcelUtil<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Common one-liner export for controllers.
|
||||
* 供控制器使用的通用一行式导出方法。
|
||||
*
|
||||
* @param response HTTP response
|
||||
* @param list export rows
|
||||
* @param clazz row class with @Excel fields
|
||||
* @param sheetName sheet / file title
|
||||
* @param response HTTP 响应
|
||||
* @param list 导出的数据行
|
||||
* @param clazz 带有 @Excel 注解字段的数据行类
|
||||
* @param sheetName sheet / 文件标题
|
||||
*/
|
||||
public static <E> void export(HttpServletResponse response, List<E> list, Class<E> clazz, String sheetName)
|
||||
{
|
||||
|
||||
@@ -75,10 +75,10 @@ public final class Base64
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes hex octects into Base64
|
||||
* 将十六进制字节编码为 Base64
|
||||
*
|
||||
* @param binaryData Array containing binaryData
|
||||
* @return Encoded Base64 array
|
||||
* @param binaryData 包含二进制数据的数组
|
||||
* @return 编码后的 Base64 数组
|
||||
*/
|
||||
public static String encode(byte[] binaryData)
|
||||
{
|
||||
@@ -124,7 +124,7 @@ public final class Base64
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f];
|
||||
}
|
||||
|
||||
// form integral number of 6-bit groups
|
||||
// 组成完整的 6 位组
|
||||
if (fewerThan24bits == EIGHTBIT)
|
||||
{
|
||||
b1 = binaryData[dataIndex];
|
||||
@@ -154,10 +154,10 @@ public final class Base64
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes Base64 data into octects
|
||||
* 将 Base64 数据解码为字节
|
||||
*
|
||||
* @param encoded string containing Base64 data
|
||||
* @return Array containind decoded data.
|
||||
* @param encoded 包含 Base64 数据的字符串
|
||||
* @return 包含解码后数据的数组。
|
||||
*/
|
||||
public static byte[] decode(String encoded)
|
||||
{
|
||||
@@ -167,12 +167,12 @@ public final class Base64
|
||||
}
|
||||
|
||||
char[] base64Data = encoded.toCharArray();
|
||||
// remove white spaces
|
||||
// 去除空白字符
|
||||
int len = removeWhiteSpace(base64Data);
|
||||
|
||||
if (len % FOURBYTE != 0)
|
||||
{
|
||||
return null;// should be divisible by four
|
||||
return null;// 应为 4 的倍数
|
||||
}
|
||||
|
||||
int numberQuadruple = (len / FOURBYTE);
|
||||
@@ -198,7 +198,7 @@ public final class Base64
|
||||
|| !isData((d3 = base64Data[dataIndex++])) || !isData((d4 = base64Data[dataIndex++])))
|
||||
{
|
||||
return null;
|
||||
} // if found "no data" just return null
|
||||
} // 如果未找到数据,直接返回 null
|
||||
|
||||
b1 = base64Alphabet[d1];
|
||||
b2 = base64Alphabet[d2];
|
||||
@@ -212,7 +212,7 @@ public final class Base64
|
||||
|
||||
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])))
|
||||
{
|
||||
return null;// if found "no data" just return null
|
||||
return null;// 如果未找到数据,直接返回 null
|
||||
}
|
||||
|
||||
b1 = base64Alphabet[d1];
|
||||
@@ -221,10 +221,10 @@ public final class Base64
|
||||
d3 = base64Data[dataIndex++];
|
||||
d4 = base64Data[dataIndex++];
|
||||
if (!isData((d3)) || !isData((d4)))
|
||||
{// Check if they are PAD characters
|
||||
{// 检查它们是否为 PAD 字符
|
||||
if (isPad(d3) && isPad(d4))
|
||||
{
|
||||
if ((b2 & 0xf) != 0)// last 4 bits should be zero
|
||||
if ((b2 & 0xf) != 0)// 最后 4 位应为零
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -236,7 +236,7 @@ public final class Base64
|
||||
else if (!isPad(d3) && isPad(d4))
|
||||
{
|
||||
b3 = base64Alphabet[d3];
|
||||
if ((b3 & 0x3) != 0)// last 2 bits should be zero
|
||||
if ((b3 & 0x3) != 0)// 最后 2 位应为零
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ public final class Base64
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // No PAD e.g 3cQl
|
||||
{ // 没有 PAD,例如 3cQl
|
||||
b3 = base64Alphabet[d3];
|
||||
b4 = base64Alphabet[d4];
|
||||
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
|
||||
@@ -264,10 +264,10 @@ public final class Base64
|
||||
}
|
||||
|
||||
/**
|
||||
* remove WhiteSpace from MIME containing encoded Base64 data.
|
||||
* 从包含已编码 Base64 数据的 MIME 中移除空白字符。
|
||||
*
|
||||
* @param data the byte array of base64 data (with WS)
|
||||
* @return the new length
|
||||
* @param data Base64 数据的字节数组(含空白字符)
|
||||
* @return 新的长度
|
||||
*/
|
||||
private static int removeWhiteSpace(char[] data)
|
||||
{
|
||||
@@ -276,7 +276,7 @@ public final class Base64
|
||||
return 0;
|
||||
}
|
||||
|
||||
// count characters that's not whitespace
|
||||
// 统计非空白字符的数量
|
||||
int newSize = 0;
|
||||
int len = data.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
|
||||
@@ -97,10 +97,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
|
||||
byte[] randomBytes = new byte[16];
|
||||
ng.nextBytes(randomBytes);
|
||||
randomBytes[6] &= 0x0f; /* clear version */
|
||||
randomBytes[6] |= 0x40; /* set to version 4 */
|
||||
randomBytes[8] &= 0x3f; /* clear variant */
|
||||
randomBytes[8] |= 0x80; /* set to IETF variant */
|
||||
randomBytes[6] &= 0x0f; /* 清除版本位 */
|
||||
randomBytes[6] |= 0x40; /* 设置为版本 4 */
|
||||
randomBytes[8] &= 0x3f; /* 清除变体位 */
|
||||
randomBytes[8] |= 0x80; /* 设置为 IETF 变体 */
|
||||
return new UUID(randomBytes);
|
||||
}
|
||||
|
||||
@@ -123,10 +123,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
throw new InternalError("MD5 not supported");
|
||||
}
|
||||
byte[] md5Bytes = md.digest(name);
|
||||
md5Bytes[6] &= 0x0f; /* clear version */
|
||||
md5Bytes[6] |= 0x30; /* set to version 3 */
|
||||
md5Bytes[8] &= 0x3f; /* clear variant */
|
||||
md5Bytes[8] |= 0x80; /* set to IETF variant */
|
||||
md5Bytes[6] &= 0x0f; /* 清除版本位 */
|
||||
md5Bytes[6] |= 0x30; /* 设置为版本 3 */
|
||||
md5Bytes[8] &= 0x3f; /* 清除变体位 */
|
||||
md5Bytes[8] |= 0x80; /* 设置为 IETF 变体 */
|
||||
return new UUID(md5Bytes);
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
*/
|
||||
public int version()
|
||||
{
|
||||
// Version is bits masked by 0x000000000000F000 in MS long
|
||||
// 版本号是最高有效长整型中被 0x000000000000F000 掩码的位
|
||||
return (int) ((mostSigBits >> 12) & 0x0f);
|
||||
}
|
||||
|
||||
@@ -217,11 +217,11 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
*/
|
||||
public int variant()
|
||||
{
|
||||
// This field is composed of a varying number of bits.
|
||||
// 0 - - Reserved for NCS backward compatibility
|
||||
// 1 0 - The IETF aka Leach-Salz variant (used by this class)
|
||||
// 1 1 0 Reserved, Microsoft backward compatibility
|
||||
// 1 1 1 Reserved for future definition.
|
||||
// 该字段由数量可变的位组成。
|
||||
// 0 - - 为 NCS 向后兼容保留
|
||||
// 1 0 - IETF 即 Leach-Salz 变体(本类使用)
|
||||
// 1 1 0 保留,微软向后兼容
|
||||
// 1 1 1 保留供以后定义使用。
|
||||
return (int) ((leastSigBits >>> (64 - (leastSigBits >>> 62))) & (leastSigBits >> 63));
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
return (mostSigBits == id.mostSigBits && leastSigBits == id.leastSigBits);
|
||||
}
|
||||
|
||||
// Comparison Operations
|
||||
// 比较操作
|
||||
|
||||
/**
|
||||
* 将此 UUID 与指定的 UUID 比较。
|
||||
@@ -419,8 +419,8 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
@Override
|
||||
public int compareTo(UUID val)
|
||||
{
|
||||
// The ordering is intentionally set up so that the UUIDs
|
||||
// can simply be numerically compared as two numbers
|
||||
// 此处有意这样设置比较顺序,使得 UUID
|
||||
// 可以简单地作为两个数字进行数值比较
|
||||
return (this.mostSigBits < val.mostSigBits ? -1 : //
|
||||
(this.mostSigBits > val.mostSigBits ? 1 : //
|
||||
(this.leastSigBits < val.leastSigBits ? -1 : //
|
||||
@@ -429,7 +429,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------
|
||||
// Private method start
|
||||
// 私有方法开始
|
||||
/**
|
||||
* 返回指定数字对应的hex值
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user