com.centit.support.network.HtmlFormUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of centit-utils Show documentation
Show all versions of centit-utils Show documentation
java 常用工具类,作为 apache-commons的补充
package com.centit.support.network;
import java.util.Collection;
import org.apache.commons.lang3.StringEscapeUtils;
@SuppressWarnings("unused")
public abstract class HtmlFormUtils {
private HtmlFormUtils() {
throw new IllegalAccessError("Utility class");
}
/**
* 请调用直接 org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4
* 或者 org.springframework.web.util.HtmlUtils.htmlEscape
* @param value 文本
* @return html文本
*/
public static String htmlValue(String value) {
return StringEscapeUtils.escapeHtml4(value);
/* if (value == null) {
return null;
}
StringBuffer result = new StringBuffer(value.length());
for (int i=0; i':
result.append(">");
break;
case '"':
result.append(""");
break;
case '\'':
result.append("'");
break;
case '%':
result.append("%");
break;
case ';':
result.append(";");
break;
case '(':
result.append("(");
break;
case ')':
result.append(")");
break;
case '&':
result.append("&");
break;
case '+':
result.append("+");
break;
default:
result.append(value.charAt(i));
break;
}
}
return result.toString();
*/
}
/**
* 直接 org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4
* 或者调用 org.springframework.web.util.HtmlUtils.htmlUnescape
* @param value html文本
* @return 文本
*/
public static String htmlString(String value) {
return StringEscapeUtils.unescapeHtml4(value);
/*if (value == null) {
return null;
}
return value.replaceAll("<", "<").replaceAll(">", ">")
.replaceAll(""", "\"").replaceAll("'", "'")
.replaceAll("&", "&");*/
}
public static String[] htmlValue(String[] strArr) {
if(strArr==null || strArr.length==0)
return null;
String resStrArr[] = new String[strArr.length];
for(int i=0;i0){
for(int i=0;i0)
sb.append(',');
sb.append(strArr[i]);
}
return sb.toString();
}else{
return null;
}
}else if(v instanceof Collection>){
@SuppressWarnings("unchecked")
Collection