废话不多说,直接上代码。

验证类Validator

主要是空验证、数字、格式验证

调用的例子:

protected void validateEmailFrom(ActionRequest actionRequest){

    String emailFromName = getParameter(actionRequest, "emailFromName");
String emailFromAddress = getParameter(
actionRequest, "emailFromAddress"); if (Validator.isNull(emailFromName)) {
SessionErrors.add(actionRequest, "emailFromName");
}
else if (!Validator.isEmailAddress(emailFromAddress) &&
!Validator.isVariableTerm(emailFromAddress)) { SessionErrors.add(actionRequest, "emailFromAddress");
}
}

数组工具类,ArrayUtil

主要的操作是:

源代码实现分析1、去除重复值,如

    public static String[] distinct(String[] array) {
return distinct(array, null);
} public static String[] distinct(
String[] array, Comparator<String> comparator) { if ((array == null) || (array.length == )) {
return array;
} Set<String> set = null; if (comparator == null) {
set = new TreeSet<String>();
}
else {
set = new TreeSet<String>(comparator);
} for (int i = ; i < array.length; i++) {
String s = array[i]; if (!set.contains(s)) {
set.add(s);
}
} return set.toArray(new String[set.size()]);
}

源代码实现分析2、尾部增加项,比如:

public static Float[] append(Float[] array, Float obj) {
  Float[] newArray = new Float[array.length + ];   System.arraycopy(array, , newArray, , array.length);   newArray[newArray.length - ] = obj;   return newArray;
}

3、JSONArray、Object和Array转换,如:

static String[]    toStringArray(JSONArray array) 

static String[]    toStringArray(Object[] array)

字符串工具StringUtil

一个例子,用于字符替换,同时也使用了StringPool

protected Map<String, String> getJSONValues(
JSONArray data, String namespace, String id) { Map<String, String> values = new HashMap<String, String>(data.length()); for (int i = 0; i < data.length(); i++) {
JSONObject jsonObject = data.getJSONObject(i); String name = jsonObject.getString("name"); name = StringUtil.replace(
name, new String[] {namespace, id},
new String[] {StringPool.BLANK, StringPool.BLANK}); values.put(name, jsonObject.getString("value"));
} return values;
}

StringUtil源代码,有兴趣可以研究

package com.liferay.portal.kernel.util;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader; import java.net.URL; import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer; public class StringUtil { public static String add(String s, String add) {
return add(s, add, StringPool.COMMA);
} public static String add(String s, String add, String delimiter) {
return add(s, add, delimiter, false);
} public static String add(
String s, String add, String delimiter, boolean allowDuplicates) { if ((add == null) || (delimiter == null)) {
return null;
} if (s == null) {
s = StringPool.BLANK;
} if (allowDuplicates || !contains(s, add, delimiter)) {
StringBuilder sb = new StringBuilder(); sb.append(s); if (Validator.isNull(s) || s.endsWith(delimiter)) {
sb.append(add);
sb.append(delimiter);
}
else {
sb.append(delimiter);
sb.append(add);
sb.append(delimiter);
} s = sb.toString();
} return s;
} public static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * ); for (int i = ; i < bytes.length; i++) {
String hex = Integer.toHexString(
0x0100 + (bytes[i] & 0x00FF)).substring(); if (hex.length() < ) {
sb.append("");
} sb.append(hex);
} return sb.toString();
} public static boolean contains(String s, String text) {
return contains(s, text, StringPool.COMMA);
} public static boolean contains(String s, String text, String delimiter) {
if ((s == null) || (text == null) || (delimiter == null)) {
return false;
} StringBuilder sb = null; if (!s.endsWith(delimiter)) {
sb = new StringBuilder(); sb.append(s);
sb.append(delimiter); s = sb.toString();
} sb = new StringBuilder(); sb.append(delimiter);
sb.append(text);
sb.append(delimiter); String dtd = sb.toString(); int pos = s.indexOf(dtd); if (pos == -) {
sb = new StringBuilder(); sb.append(text);
sb.append(delimiter); String td = sb.toString(); if (s.startsWith(td)) {
return true;
} return false;
} return true;
} public static int count(String s, String text) {
if ((s == null) || (text == null)) {
return ;
} int count = ; int pos = s.indexOf(text); while (pos != -) {
pos = s.indexOf(text, pos + text.length()); count++;
} return count;
} public static boolean endsWith(String s, char end) {
return endsWith(s, (new Character(end)).toString());
} public static boolean endsWith(String s, String end) {
if ((s == null) || (end == null)) {
return false;
} if (end.length() > s.length()) {
return false;
} String temp = s.substring(s.length() - end.length(), s.length()); if (temp.equalsIgnoreCase(end)) {
return true;
}
else {
return false;
}
} public static String extractChars(String s) {
if (s == null) {
return StringPool.BLANK;
} StringBuilder sb = new StringBuilder(); char[] c = s.toCharArray(); for (int i = ; i < c.length; i++) {
if (Validator.isChar(c[i])) {
sb.append(c[i]);
}
} return sb.toString();
} public static String extractDigits(String s) {
if (s == null) {
return StringPool.BLANK;
} StringBuilder sb = new StringBuilder(); char[] c = s.toCharArray(); for (int i = ; i < c.length; i++) {
if (Validator.isDigit(c[i])) {
sb.append(c[i]);
}
} return sb.toString();
} public static String extractFirst(String s, String delimiter) {
if (s == null) {
return null;
}
else {
String[] array = split(s, delimiter); if (array.length > ) {
return array[];
}
else {
return null;
}
}
} public static String extractLast(String s, String delimiter) {
if (s == null) {
return null;
}
else {
String[] array = split(s, delimiter); if (array.length > ) {
return array[array.length - ];
}
else {
return null;
}
}
} public static String highlight(String s, String keywords) {
return highlight(s, keywords, "<span class=\"highlight\">", "</span>");
} public static String highlight(
String s, String keywords, String highlight1, String highlight2) { if (s == null) {
return null;
} // The problem with using a regexp is that it searches the text in a
// case insenstive manner but doens't replace the text in a case
// insenstive manner. So the search results actually get messed up. The
// best way is to actually parse the results. //return s.replaceAll(
// "(?i)" + keywords, highlight1 + keywords + highlight2); StringBuilder sb = new StringBuilder(StringPool.SPACE); StringTokenizer st = new StringTokenizer(s); while (st.hasMoreTokens()) {
String token = st.nextToken(); if (token.equalsIgnoreCase(keywords)) {
sb.append(highlight1);
sb.append(token);
sb.append(highlight2);
}
else {
sb.append(token);
} if (st.hasMoreTokens()) {
sb.append(StringPool.SPACE);
}
} return sb.toString();
} public static String lowerCase(String s) {
if (s == null) {
return null;
}
else {
return s.toLowerCase();
}
} public static String merge(boolean[] array) {
return merge(array, StringPool.COMMA);
} public static String merge(boolean[] array, String delimiter) {
if (array == null) {
return null;
} StringBuilder sb = new StringBuilder(); for (int i = ; i < array.length; i++) {
sb.append(String.valueOf(array[i]).trim()); if ((i + ) != array.length) {
sb.append(delimiter);
}
} return sb.toString();
} public static String merge(double[] array) {
return merge(array, StringPool.COMMA);
} public static String merge(double[] array, String delimiter) {
if (array == null) {
return null;
} StringBuilder sb = new StringBuilder(); for (int i = ; i < array.length; i++) {
sb.append(String.valueOf(array[i]).trim()); if ((i + ) != array.length) {
sb.append(delimiter);
}
} return sb.toString();
} public static String merge(float[] array) {
return merge(array, StringPool.COMMA);
} public static String merge(float[] array, String delimiter) {
if (array == null) {
return null;
} StringBuilder sb = new StringBuilder(); for (int i = ; i < array.length; i++) {
sb.append(String.valueOf(array[i]).trim()); if ((i + ) != array.length) {
sb.append(delimiter);
}
} return sb.toString();
} public static String merge(int[] array) {
return merge(array, StringPool.COMMA);
} public static String merge(int[] array, String delimiter) {
if (array == null) {
return null;
} StringBuilder sb = new StringBuilder(); for (int i = ; i < array.length; i++) {
sb.append(String.valueOf(array[i]).trim()); if ((i + ) != array.length) {
sb.append(delimiter);
}
} return sb.toString();
} public static String merge(long[] array) {
return merge(array, StringPool.COMMA);
} public static String merge(long[] array, String delimiter) {
if (array == null) {
return null;
} StringBuilder sb = new StringBuilder(); for (int i = ; i < array.length; i++) {
sb.append(String.valueOf(array[i]).trim()); if ((i + ) != array.length) {
sb.append(delimiter);
}
} return sb.toString();
} public static String merge(short[] array) {
return merge(array, StringPool.COMMA);
} public static String merge(short[] array, String delimiter) {
if (array == null) {
return null;
} StringBuilder sb = new StringBuilder(); for (int i = ; i < array.length; i++) {
sb.append(String.valueOf(array[i]).trim()); if ((i + ) != array.length) {
sb.append(delimiter);
}
} return sb.toString();
} public static String merge(Collection<?> col) {
return merge(col, StringPool.COMMA);
} public static String merge(Collection<?> col, String delimiter) {
return merge(col.toArray(new Object[col.size()]), delimiter);
} public static String merge(Object[] array) {
return merge(array, StringPool.COMMA);
} public static String merge(Object[] array, String delimiter) {
if (array == null) {
return null;
} StringBuilder sb = new StringBuilder(); for (int i = ; i < array.length; i++) {
sb.append(String.valueOf(array[i]).trim()); if ((i + ) != array.length) {
sb.append(delimiter);
}
} return sb.toString();
} public static String randomize(String s) {
return Randomizer.getInstance().randomize(s);
} public static String read(ClassLoader classLoader, String name)
throws IOException { return read(classLoader, name, false);
} public static String read(ClassLoader classLoader, String name, boolean all)
throws IOException { if (all) {
StringBuilder sb = new StringBuilder(); Enumeration<URL> enu = classLoader.getResources(name); while (enu.hasMoreElements()) {
URL url = enu.nextElement(); InputStream is = url.openStream(); String s = read(is); if (s != null) {
sb.append(s);
sb.append(StringPool.NEW_LINE);
} is.close();
} return sb.toString().trim();
}
else {
InputStream is = classLoader.getResourceAsStream(name); String s = read(is); is.close(); return s;
}
} public static String read(InputStream is) throws IOException {
StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while ((line = br.readLine()) != null) {
sb.append(line).append('\n');
} br.close(); return sb.toString().trim();
} public static String remove(String s, String remove) {
return remove(s, remove, StringPool.COMMA);
} public static String remove(String s, String remove, String delimiter) {
if ((s == null) || (remove == null) || (delimiter == null)) {
return null;
} if (Validator.isNotNull(s) && !s.endsWith(delimiter)) {
s += delimiter;
} StringBuilder sb = new StringBuilder(); sb.append(delimiter);
sb.append(remove);
sb.append(delimiter); String drd = sb.toString(); sb = new StringBuilder(); sb.append(remove);
sb.append(delimiter); String rd = sb.toString(); while (contains(s, remove, delimiter)) {
int pos = s.indexOf(drd); if (pos == -) {
if (s.startsWith(rd)) {
int x = remove.length() + delimiter.length();
int y = s.length(); s = s.substring(x, y);
}
}
else {
int x = pos + remove.length() + delimiter.length();
int y = s.length(); sb = new StringBuilder(); sb.append(s.substring(, pos));
sb.append(s.substring(x, y)); s = sb.toString();
}
} return s;
} public static String replace(String s, char oldSub, char newSub) {
if (s == null) {
return null;
} return s.replace(oldSub, newSub);
} public static String replace(String s, char oldSub, String newSub) {
if ((s == null) || (newSub == null)) {
return null;
} // The number 5 is arbitrary and is used as extra padding to reduce
// buffer expansion StringBuilder sb = new StringBuilder(s.length() + * newSub.length()); char[] charArray = s.toCharArray(); for (char c : charArray) {
if (c == oldSub) {
sb.append(newSub);
}
else {
sb.append(c);
}
} return sb.toString();
} public static String replace(String s, String oldSub, String newSub) {
if ((s == null) || (oldSub == null) || (newSub == null)) {
return null;
} int y = s.indexOf(oldSub); if (y >= ) { // The number 5 is arbitrary and is used as extra padding to reduce
// buffer expansion StringBuilder sb = new StringBuilder(
s.length() + * newSub.length()); int length = oldSub.length();
int x = ; while (x <= y) {
sb.append(s.substring(x, y));
sb.append(newSub); x = y + length;
y = s.indexOf(oldSub, x);
} sb.append(s.substring(x)); return sb.toString();
}
else {
return s;
}
} public static String replace(String s, String[] oldSubs, String[] newSubs) {
if ((s == null) || (oldSubs == null) || (newSubs == null)) {
return null;
} if (oldSubs.length != newSubs.length) {
return s;
} for (int i = ; i < oldSubs.length; i++) {
s = replace(s, oldSubs[i], newSubs[i]);
} return s;
} public static String replace(
String s, String[] oldSubs, String[] newSubs, boolean exactMatch) { if ((s == null) || (oldSubs == null) || (newSubs == null)) {
return null;
} if (oldSubs.length != newSubs.length) {
return s;
} if (!exactMatch) {
replace(s, oldSubs, newSubs);
}
else {
for (int i = ; i < oldSubs.length; i++) {
s = s.replaceAll("\\b" + oldSubs[i] + "\\b" , newSubs[i]);
}
} return s;
} /**
* Returns a string with replaced values. This method will replace all text
* in the given string, between the beginning and ending delimiter, with new
* values found in the given map. For example, if the string contained the
* text <code>[$HELLO$]</code>, and the beginning delimiter was
* <code>[$]</code>, and the ending delimiter was <code>$]</code>, and the
* values map had a key of <code>HELLO</code> that mapped to
* <code>WORLD</code>, then the replaced string will contain the text
* <code>[$WORLD$]</code>.
*
* @param s the original string
* @param begin the beginning delimiter
* @param end the ending delimiter
* @param values a map of old and new values
* @return a string with replaced values
*/
public static String replaceValues(
String s, String begin, String end, Map<String, String> values) { if ((s == null) || (begin == null) || (end == null) ||
(values == null) || (values.size() == )) { return s;
} StringBuilder sb = new StringBuilder(s.length()); int pos = ; while (true) {
int x = s.indexOf(begin, pos);
int y = s.indexOf(end, x + begin.length()); if ((x == -) || (y == -)) {
sb.append(s.substring(pos, s.length())); break;
}
else {
sb.append(s.substring(pos, x + begin.length())); String oldValue = s.substring(x + begin.length(), y); String newValue = values.get(oldValue); if (newValue == null) {
newValue = oldValue;
} sb.append(newValue); pos = y;
}
} return sb.toString();
} public static String reverse(String s) {
if (s == null) {
return null;
} char[] c = s.toCharArray();
char[] reverse = new char[c.length]; for (int i = ; i < c.length; i++) {
reverse[i] = c[c.length - i - ];
} return new String(reverse);
} public static String safePath(String path) {
return replace(path, StringPool.DOUBLE_SLASH, StringPool.SLASH);
} public static String shorten(String s) {
return shorten(s, );
} public static String shorten(String s, int length) {
return shorten(s, length, "...");
} public static String shorten(String s, String suffix) {
return shorten(s, , suffix);
} public static String shorten(String s, int length, String suffix) {
if ((s == null) || (suffix == null)) {
return null;
} if (s.length() > length) {
for (int j = length; j >= ; j--) {
if (Character.isWhitespace(s.charAt(j))) {
length = j; break;
}
} StringBuilder sb = new StringBuilder(); sb.append(s.substring(, length));
sb.append(suffix); s = sb.toString();
} return s;
} public static String[] split(String s) {
return split(s, StringPool.COMMA);
} public static String[] split(String s, String delimiter) {
if (s == null || delimiter == null) {
return new String[];
} s = s.trim(); if (!s.endsWith(delimiter)) {
StringBuilder sb = new StringBuilder(); sb.append(s);
sb.append(delimiter); s = sb.toString();
} if (s.equals(delimiter)) {
return new String[];
} List<String> nodeValues = new ArrayList<String>(); if (delimiter.equals("\n") || delimiter.equals("\r")) {
try {
BufferedReader br = new BufferedReader(new StringReader(s)); String line = null; while ((line = br.readLine()) != null) {
nodeValues.add(line);
} br.close();
}
catch (IOException ioe) {
_log.error(ioe.getMessage());
}
}
else {
int offset = ;
int pos = s.indexOf(delimiter, offset); while (pos != -) {
nodeValues.add(new String(s.substring(offset, pos))); offset = pos + delimiter.length();
pos = s.indexOf(delimiter, offset);
}
} return nodeValues.toArray(new String[nodeValues.size()]);
} public static boolean[] split(String s, boolean x) {
return split(s, StringPool.COMMA, x);
} public static boolean[] split(String s, String delimiter, boolean x) {
String[] array = split(s, delimiter);
boolean[] newArray = new boolean[array.length]; for (int i = ; i < array.length; i++) {
boolean value = x; try {
value = Boolean.valueOf(array[i]).booleanValue();
}
catch (Exception e) {
} newArray[i] = value;
} return newArray;
} public static double[] split(String s, double x) {
return split(s, StringPool.COMMA, x);
} public static double[] split(String s, String delimiter, double x) {
String[] array = split(s, delimiter);
double[] newArray = new double[array.length]; for (int i = ; i < array.length; i++) {
double value = x; try {
value = Double.parseDouble(array[i]);
}
catch (Exception e) {
} newArray[i] = value;
} return newArray;
} public static float[] split(String s, float x) {
return split(s, StringPool.COMMA, x);
} public static float[] split(String s, String delimiter, float x) {
String[] array = split(s, delimiter);
float[] newArray = new float[array.length]; for (int i = ; i < array.length; i++) {
float value = x; try {
value = Float.parseFloat(array[i]);
}
catch (Exception e) {
} newArray[i] = value;
} return newArray;
} public static int[] split(String s, int x) {
return split(s, StringPool.COMMA, x);
} public static int[] split(String s, String delimiter, int x) {
String[] array = split(s, delimiter);
int[] newArray = new int[array.length]; for (int i = ; i < array.length; i++) {
int value = x; try {
value = Integer.parseInt(array[i]);
}
catch (Exception e) {
} newArray[i] = value;
} return newArray;
} public static long[] split(String s, long x) {
return split(s, StringPool.COMMA, x);
} public static long[] split(String s, String delimiter, long x) {
String[] array = split(s, delimiter);
long[] newArray = new long[array.length]; for (int i = ; i < array.length; i++) {
long value = x; try {
value = Long.parseLong(array[i]);
}
catch (Exception e) {
} newArray[i] = value;
} return newArray;
} public static short[] split(String s, short x) {
return split(s, StringPool.COMMA, x);
} public static short[] split(String s, String delimiter, short x) {
String[] array = split(s, delimiter);
short[] newArray = new short[array.length]; for (int i = ; i < array.length; i++) {
short value = x; try {
value = Short.parseShort(array[i]);
}
catch (Exception e) {
} newArray[i] = value;
} return newArray;
} public static boolean startsWith(String s, char begin) {
return startsWith(s, (new Character(begin)).toString());
} public static boolean startsWith(String s, String start) {
if ((s == null) || (start == null)) {
return false;
} if (start.length() > s.length()) {
return false;
} String temp = s.substring(, start.length()); if (temp.equalsIgnoreCase(start)) {
return true;
}
else {
return false;
}
} /**
* Return the number of starting letters that s1 and s2 have in common
* before they deviate.
*
* @param s1 the first string
* @param s2 the second string
*
* @return the number of starting letters that s1 and s2 have in common
* before they deviate
*/
public static int startsWithWeight(String s1, String s2) {
if ((s1 == null) || (s2 == null)) {
return ;
} char[] charArray1 = s1.toCharArray();
char[] charArray2 = s2.toCharArray(); int i = ; for (; (i < charArray1.length) && (i < charArray2.length); i++) {
if (charArray1[i] != charArray2[i]) {
break;
}
} return i;
} public static String stripBetween(String s, String begin, String end) {
if ((s == null) || (begin == null) || (end == null)) {
return s;
} StringBuilder sb = new StringBuilder(s.length()); int pos = ; while (true) {
int x = s.indexOf(begin, pos);
int y = s.indexOf(end, x + begin.length()); if ((x == -) || (y == -)) {
sb.append(s.substring(pos, s.length())); break;
}
else {
sb.append(s.substring(pos, x)); pos = y + end.length();
}
} return sb.toString();
} public static String trim(String s) {
return trim(s, null);
} public static String trim(String s, char c) {
return trim(s, new char[] {c});
} public static String trim(String s, char[] exceptions) {
if (s == null) {
return null;
} char[] charArray = s.toCharArray(); int len = charArray.length; int x = ;
int y = charArray.length; for (int i = ; i < len; i++) {
char c = charArray[i]; if (_isTrimable(c, exceptions)) {
x = i + ;
}
else {
break;
}
} for (int i = len - ; i >= ; i--) {
char c = charArray[i]; if (_isTrimable(c, exceptions)) {
y = i;
}
else {
break;
}
} if ((x != ) || (y != len)) {
return s.substring(x, y);
}
else {
return s;
}
} public static String trimLeading(String s) {
return trimLeading(s, null);
} public static String trimLeading(String s, char c) {
return trimLeading(s, new char[] {c});
} public static String trimLeading(String s, char[] exceptions) {
if (s == null) {
return null;
} char[] charArray = s.toCharArray(); int len = charArray.length; int x = ;
int y = charArray.length; for (int i = ; i < len; i++) {
char c = charArray[i]; if (_isTrimable(c, exceptions)) {
x = i + ;
}
else {
break;
}
} if ((x != ) || (y != len)) {
return s.substring(x, y);
}
else {
return s;
}
} public static String trimTrailing(String s) {
return trimTrailing(s, null);
} public static String trimTrailing(String s, char c) {
return trimTrailing(s, new char[] {c});
} public static String trimTrailing(String s, char[] exceptions) {
if (s == null) {
return null;
} char[] charArray = s.toCharArray(); int len = charArray.length; int x = ;
int y = charArray.length; for (int i = len - ; i >= ; i--) {
char c = charArray[i]; if (_isTrimable(c, exceptions)) {
y = i;
}
else {
break;
}
} if ((x != ) || (y != len)) {
return s.substring(x, y);
}
else {
return s;
}
} public static String upperCase(String s) {
if (s == null) {
return null;
}
else {
return s.toUpperCase();
}
} public static String upperCaseFirstLetter(String s) {
char[] chars = s.toCharArray(); if ((chars[] >= ) && (chars[] <= )) {
chars[] = (char)(chars[] - );
} return new String(chars);
} public static String wrap(String text) {
return wrap(text, , StringPool.NEW_LINE);
} public static String wrap(String text, int width, String lineSeparator) {
if (text == null) {
return null;
} StringBuilder sb = new StringBuilder(); try {
BufferedReader br = new BufferedReader(new StringReader(text)); String s = StringPool.BLANK; while ((s = br.readLine()) != null) {
if (s.length() == ) {
sb.append(lineSeparator);
}
else {
String[] tokens = s.split(StringPool.SPACE);
boolean firstWord = true;
int curLineLength = ; for (int i = ; i < tokens.length; i++) {
if (!firstWord) {
sb.append(StringPool.SPACE);
curLineLength++;
} if (firstWord) {
sb.append(lineSeparator);
} sb.append(tokens[i]); curLineLength += tokens[i].length(); if (curLineLength >= width) {
firstWord = true;
curLineLength = ;
}
else {
firstWord = false;
}
}
}
}
}
catch (IOException ioe) {
_log.error(ioe.getMessage());
} return sb.toString();
} private static boolean _isTrimable(char c, char[] exceptions) {
if ((exceptions != null) && (exceptions.length > )) {
for (int i = ; i < exceptions.length; i++) {
if (c == exceptions[i]) {
return false;
}
}
} return Character.isWhitespace(c);
} private static Log _log = LogFactoryUtil.getLog(StringUtil.class); }

其他工具类

  • 集合的泛型帮助类:MapUtil、ListUtil
  • Base64的转换:Base64
  • http参数帮助,编解码工具:HttpUtil
  • 文件操作:FileUtil
  • 类型工具:ClassUtil:
  • 常用字符串静态类:StringPool

其中StringPool定义了一些final值,可以利用起来:

package com.liferay.portal.kernel.util;

public class StringPool {

public static final String AMPERSAND = "&";

public static final String AMPERSAND_ENCODED = "&amp;";

public static final String APOSTROPHE = "'";

public static final String AT = "@";

public static final String BACK_SLASH = "\\";

public static final String BETWEEN = "BETWEEN";

public static final String BLANK = "";

public static final String CDATA_OPEN = "<![CDATA[";

public static final String CDATA_CLOSE = "]]>";

public static final String CLOSE_BRACKET = "]";

public static final String CLOSE_CURLY_BRACE = "}";

public static final String CLOSE_PARENTHESIS = ")";

public static final String COLON = ":";

public static final String COMMA = ",";

public static final String COMMA_AND_SPACE = ", ";

public static final String DASH = "-";

public static final String DOUBLE_APOSTROPHE = "''";

public static final String DOUBLE_CLOSE_BRACKET = "]]";

public static final String DOUBLE_OPEN_BRACKET = "[[";

public static final String DOUBLE_SLASH = "//";

public static final String EQUAL = "=";

public static final String GREATER_THAN = ">";

public static final String GREATER_THAN_OR_EQUAL = ">=";

public static final String FALSE = "false";

public static final String FORWARD_SLASH = "/";

public static final String FOUR_SPACES = " ";

public static final String IS_NOT_NULL = "IS NOT NULL";

public static final String IS_NULL = "IS NULL";

public static final String LESS_THAN = "<";

public static final String LESS_THAN_OR_EQUAL = "<=";

public static final String LIKE = "LIKE";

public static final String MINUS = "-";

public static final String NBSP = "&nbsp;";

public static final String NEW_LINE = "\n";

public static final String NOT_EQUAL = "!=";

public static final String NOT_LIKE = "NOT LIKE";

public static final String NULL = "null";

public static final String OPEN_BRACKET = "[";

public static final String OPEN_CURLY_BRACE = "{";

public static final String OPEN_PARENTHESIS = "(";

public static final String PERCENT = "%";

public static final String PERIOD = ".";

public static final String PIPE = "|";

public static final String PLUS = "+";

public static final String POUND = "#";

public static final String QUESTION = "?";

public static final String QUOTE = "\"";

public static final String RETURN = "\r";

public static final String RETURN_NEW_LINE = "\r\n";

public static final String SEMICOLON = ";";

public static final String SLASH = FORWARD_SLASH;

public static final String SPACE = " ";

public static final String STAR = "*";

public static final String TILDE = "~";

public static final String TRUE = "true";

public static final String UNDERLINE = "_";

public static final String UTF8 = "UTF-8";

}

简单、优雅、有序才是真的美。

Liferay7 BPM门户开发之30: 通用帮助类Validator、ArrayUtil、StringUtil等使用的更多相关文章

  1. Liferay7 BPM门户开发之10: 通用流程实现从Servlet到Portlet(Part1)

    开发目的: 实现通用流程自动化处理(即实现不需要hardcode代码的bpm统一处理后台,仅需要写少量前端html form代码和拖拽设计BPM定义) 既可独立运行或可依托于Liferay或依托其它门 ...

  2. Liferay7 BPM门户开发之37: Liferay7下的OSGi Hook集成开发

    hook开发是Liferay客制扩展的一种方式,比插件灵活,即可以扩展liferay门户,也能对原有特性进行更改,Liferay有许多内置的服务,比如用hook甚至可以覆盖Liferay服务. 可作为 ...

  3. Liferay7 BPM门户开发之17: Portlet 生命周期

    Portlet 生命周期 init() =〉 render() =〉 processAction() =〉 processEvent() =〉 serveResource() =〉destroy() ...

  4. Liferay7 BPM门户开发之12:acitiviti和liferay用户权限体系集成

    写到第12章才出现Liferay的内容,希望可以厚积薄发. 我们的目标是不使用不维护Activiti的用户组织架构,只维护Liferay的体系,这样的好处是非常明显的,即不用做组织架构的同步工作. 原 ...

  5. Liferay7 BPM门户开发之29: 核心kernel.util包下面的通用帮助类ParamUtil、GetterUtil使用

    与其闭门造车,不如直接开动原装.进口.免费的法拉利. -- 作者说 不多说废话,直接上代码. ParamUtil ParamUtil.GetterUtil是Liferay最重要的帮助类 ParamUt ...

  6. Liferay7 BPM门户开发之44: 集成Activiti展示流程列表

    处理依赖关系 集成Activiti之前,必须搞清楚其中的依赖关系,才能在Gradle里进行配置. 依赖关系: 例如,其中activiti-engine依赖于activiti-bpmn-converte ...

  7. Liferay7 BPM门户开发之32: 实现自定义认证登陆(定制Authentication Hook)

    第一步:修改liferay-hook.xml <?xml version="1.0"?> <!DOCTYPE hook PUBLIC "-//Lifer ...

  8. Liferay7 BPM门户开发之20: 理解Asset Framework

    Asset框架用于将您开发的门户内容添加Liferay的核心系统功能.打个比方,你开发了一个事件TodoList管理的插件,在列表显示的时候,你可以集成Asset框架,让你的自定义内容支持Tag标签. ...

  9. Liferay7 BPM门户开发之15: Liferay开发体系简介

    Liferay SDK 开发体系 主要分6种: Portlet Hook Theme Layout Templates Web Modules Ext Portlet :类似于servlet的web组 ...

随机推荐

  1. Python全栈之路4--内置函数--文件操作

    上节重点回顾: 判断对象是否属于某个类,例如: 列表中有个数字,但是循环列表判断长度,用len会报错;因为int不支持len,所以要先判断属于某个类,然后再进行if判断. # isinstance(对 ...

  2. BIEE 11g 安装

    1.安装oracle 创建字符集为AL32UTF8的实力MERIT  sys密码merit 创建biee用户 create tablespace biee datafile 'D:\ORADATA\M ...

  3. [Office][C#] NPOI、OpenXML SDK、OpenOffice.org SDK 写入资料到 EXCEL 档案[转]

    原文地址:http://www.dotblogs.com.tw/chou/archive/2010/04/29/14912.aspx 一.簡介 要將資料寫入 EXCEL 檔案有許多的方法,但假如電腦不 ...

  4. zendstudio 声明变量类型,让变量自动方法提示

    zendstudio 行内注释, 显式声明变量类型,让变量自动方法提示 $out = []; /* @var $row \xxyy\SizeEntity */ foreach ($rows[ 'lis ...

  5. Cacti的基本使用

    对于Cacti是通过snmpget来获取数据,使用 RRDtool绘画图形,用snmp服务获取数据,然后用rrdtool储存和更新数据,那么就可以简单理解为Cacti就是RRDTool的一个web图形 ...

  6. XE3随笔10:TSuperType

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  7. jquery load 加载改造,只加载body

    背景: 项目中大量用到了jquery和easyui组件,原生load经常出现主页面异常,原因是组件被重复初始化.也考虑过用iframe,但是在实际项目中的效果,最终取消了iframe方案,也尝试了其他 ...

  8. 学习python之练习(三)

    python排序算法 1.冒泡排序: import math def BubbleSort(list): lengthOfList = len(list) for i in range(0,lengt ...

  9. MySQL双机热备份

    系统: CentOS release 6.6 (Final) MySQL: mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) ...

  10. FastReport代码计算高度

    Dim iHeight As Double        Dim columnData_form As DataSourceBase             iHeight=Page1.TopMarg ...