- 浏览: 212190 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (131)
- Spring (5)
- Struts (3)
- IO (4)
- RMI (1)
- Foundation (10)
- JS (13)
- WAS (2)
- Intergration (2)
- Oracle (20)
- Plug-in (3)
- Hibernate (3)
- OpenSource (3)
- JSP (9)
- WebService (5)
- Linux (7)
- Thread (3)
- Link (3)
- Ext (6)
- Detail (5)
- Servlet (2)
- Mysql (1)
- tomcat (2)
- JavaUtil (4)
- life (1)
- LINUX_C (3)
- EJB2.0 (0)
- EJB3.0 (0)
- ss (0)
- test (3)
- fasfdasd (1)
最新评论
-
xiaokang1582830:
这种方式是可行的,我们之前也是把一周前的数据通过这样的方式找回 ...
oracle误删除数据恢复 -
zhonglinjun:
完全不能用,还写出来搞什么?
js验证ip和子网掩码 -
还有也许:
老兄,今天试了一下,你这个方法好像只能把刚刚误删的数据给弄回来 ...
oracle误删除数据恢复 -
dcljava:
写的不错,顶你下
javax.servlet.Filter -
beee:
呵呵,不错,谢谢分享
oracle误删除数据恢复
escape
package com.samsung.foundation.util;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
public class CommonUtil {
/**
* String ? ??? XML ???? ?? ?? ??(<,>,",',&)? ??<br>
* <input type="text"> 'tag'? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscInput(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '|':
out.append("|");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
case '*':
out.append("*");
break;
case '/':
out.append("/");
break;
case '\t':
out.append("   ");
break;
case ' ':
out.append(" ");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* value ? null ?? ???? null? ?? 0? return
*
* @param oVal ??? Integer obj
* @return null ? ?? 0, null ? ?? ?? Integer? int value
*/
public static int checkNull(Integer oVal) {
return checkNull(oVal, 0);
}
/**
* value ? null ?? ???? null? ?? 0? return
*
* @param oVal ??? Integer obj
* @param iDefaultValue oVal null ? ?? default ? ???? ?
* @return null ? ?? 0, null ? ?? ?? Integer? int value
*/
public static int checkNull(Integer oVal, int iDefaultValue) {
int iResult = iDefaultValue;
if (oVal != null) {
iResult = oVal.intValue();
}
return iResult;
}
/**
* value ? null ?? ???? ??? ???? return
*
* @param sVal ??? String
* @return null ? ?? "", null ? ?? ?? ??? ??? String
*/
public static String checkNull(String sVal) {
String sResult = "";
if (sVal != null) {
sResult = sVal.trim();
}
return sResult;
}
/**
* value ? null ? ?? defaultValue? return, null ? ?? ?? ??? ???? return
*
* @param sVal ??? String
* @param sDefaultValue sVal? null ? ?? default ? ???? ? (sDefaultValue? null ? ??? ""?? ???)
* @return null ? ?? defaultValue, null ? ?? ?? ??? ??? String
*/
public static String checkNull(String sVal, String sDefaultValue) {
String sResult = "";
if (sDefaultValue != null) {
sResult = sDefaultValue;
}
if (sVal != null && !"".equals(sVal.trim())) {
sResult = sVal.trim();
}
return sResult;
}
/**
* SQL Injection ? ???? Database ? ?? ??? ?? ????.<br>
* "'" ==> "''" ?? ??
* --, ;, % ?? ??
*
* @param sValue ?? ??? ??? ?
* @return SQL Injection ? ??? String
*/
public static String safeSqlInput(String sValue) {
String retValue;
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
if (sValue.charAt(iCount) == '\'') {
sbConvertedValue.append("'");
} else if (sValue.charAt(iCount) == ';' || sValue.charAt(iCount) == '%') {
continue;
}
sbConvertedValue.append(sValue.charAt(iCount));
}
retValue = sbConvertedValue.toString().replaceAll("--", "");
return retValue;
}
/**
* collection ? null ?? ?? ??? true return
*
* @param collection ??? Collection<?> ??? ????
* @return collection? null ?? ???? ??
*/
public static boolean isEmpty(Collection<?> collection) {
if (collection == null || collection.isEmpty()) {
return true;
}
return false;
}
/**
* String ? null ?? ?????? true return
*
* @param sVal ??? String
* @return value? null ?? ???? ??
*/
public static boolean isEmpty(String sVal) {
if (CommonUtil.checkNull(sVal).equals("")) {
return true;
}
return false;
}
/**
* Returns true if this map is <code>null</code> or contains no key-value mappings.
*
* @param map
* @return true if this map is <code>null</code> or contains no key-value mappings
* @since 1.5
*/
public static boolean isEmpty(Map<?, ?> map) {
return (map == null || map.isEmpty()) ? true : false;
}
/**
* Returns true if this array is <code>null</code> or contains no objects.
*
* @param array
* @return true if this array is <code>null</code> or contains no objects.
* @since 1.5
*/
public static boolean isEmpty(Object[] array) {
return (array == null || array.length == 0) ? true : false;
}
/**
* String ? ??? XML ???? ?? ?? ??(<,>,",',&)? ??<br>
* <input type="hidden"> 'tag'? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscHidden(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '|':
out.append("|");
break;
case '\n':
out.append("<BR>");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
case '*':
out.append("*");
break;
case '/':
out.append("/");
break;
case '\t':
out.append("   ");
break;
case ' ':
out.append(" ");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* String ? ??? XML ???? ?? ?? ??(",')? ????.<br>
* <td title='data'> ?? html ? quotation ?? ???? ???? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscInQuot(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* String ? ??? JavaScript? ?? ?? ??(',",\r,\n,\t)? ????.<br>
*
* @param src ??? String
* @param isDoubleQuot ???? ?? 'quotation'? " ?? '??(true ? ")
* @return javaScript? ?? String
*/
public static String safeHtmlEscJavaScript(String src, boolean isDoubleQuot) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '"':
if (isDoubleQuot) {
out.append("\\").append(src.charAt(i));
} else {
out.append(src.charAt(i));
}
break;
case '\'':
if (isDoubleQuot) {
out.append(src.charAt(i));
} else {
out.append("\\").append(src.charAt(i));
}
break;
case '\r':
out.append("\\r");
break;
case '\n':
out.append("\\n");
break;
case '\t':
out.append("\\t");
break;
case '\\':
out.append("\\\\");
break;
case '<':
out.append("\\074");
break;
case '>':
out.append("\\076");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* 'Quotation'?? Javascript ? ????.<br>
* safeHtmlEscJavaScript ???? " -> \042, ' -> \047 ? ????.<br>
* onclick ="javascript:alert('xxx')" ? ?? ??? ' ? " ? ??? ???? ?? ??? ????? ? ???? ????.
*
* @param src ??? String
* @return javaScript? ?? String
*/
public static String safeHtmlEscJavaScriptInQuot(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '"':
out.append("\\042");
break;
case '\'':
out.append("\\047");
break;
case '\r':
out.append("\\r");
break;
case '\n':
out.append("\\n");
break;
case '\t':
out.append("\\t");
break;
case '\\':
out.append("\\\\");
break;
case '<':
out.append("\\074");
break;
case '>':
out.append("\\076");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* Escapes '%', '_' and '\' characters. Default ESCAPE character is '\'.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue) {
return safeLikeSearchEscape(sValue, '\\');
}
/**
* Escapes '%', '_' and '\' characters.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @param escapeChar
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue, char escapeChar) {
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
char cValue = sValue.charAt(iCount);
if (cValue == '_' || cValue == '%' || cValue == escapeChar) {
sbConvertedValue.append(escapeChar);
}
sbConvertedValue.append(cValue);
}
return sbConvertedValue.toString();
}
/**
* Like ??? ??? ???? ????? Like ??? ?? ??<br>
* "'" ==> "''" ?? ??<br>
* --, ; ?? ??<br>
*
* @param sValue ?? ??? ??? ?
* @return String ??? ? (???? null ?? null ??)
*/
public static String safeLikeSearchInput(String sValue) {
return safeLikeSearchInput(sValue, false);
}
/**
* Like ??? ??? ???? ????? Like ??? ?? ??<br>
* "'" ==> "''" ?? ??<br>
* --, ; ?? ??<br>
* <br>
* ?, ???? useEscape? true ?? ??? like ?? ?? <span color="red">"escape '\'"</span>? ?????.<br>
* "%" ==> "\%" ?? ??<br>
* "_" ==> "\_" ?? ??<br>
* "`" ==> "\`" ?? ??
*
* @param sValue ?? ??? ??? ?
* @param useEscape escape ?? ????
* @return String ??? ? (???? null ?? null ??)
*/
public static String safeLikeSearchInput(String sValue, boolean useEscape) {
String retValue;
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
char cValue = sValue.charAt(iCount);
// SQL-Injection ??
if (cValue == '\'') {
sbConvertedValue.append("'");
} else if (cValue == ';') {
continue;
}
// Escape ??
else if (useEscape) {
if (cValue == '_' || cValue == '%' || cValue == '\\') {
sbConvertedValue.append("\\");
}
}
sbConvertedValue.append(cValue);
}
retValue = sbConvertedValue.toString().replaceAll("--", "");
return retValue;
}
/**
* String ? ??? XML ???? ?? ?? ??(<,>,",',&)? ????.<br>
* <td>data</td> ?? display ?? tag ? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscDisplay(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '|':
out.append("|");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
case '*':
out.append("*");
break;
case '/':
out.append("/");
break;
case '\n':
out.append("<BR>");
break;
case '\t':
out.append(" ");
break;
case ' ':
out.append(" ");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* @param src
* @return
*/
public static String safeHtmlEscDisplayForKindeditor(String src) {
if (src == null) {
return "";
}
src = src.replaceAll("&", "&");
src = src.replaceAll("<", "<");
src = src.replaceAll(">", ">");
src = src.replaceAll("\"", """);
return src;
}
/**
* get uuid for table data id
* @return
* @since 1.0
*/
public static String getUUID(){
String s = UUID.randomUUID().toString();
return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
}
/**
* get random number -zq.wu
* @param nRandomCount
* @param isNumber
* @return
* @since 1.0
*/
public static String getRandomString(int nRandomCount, boolean isNumber) {
char[] a = null;
if (isNumber) {
a = new char[10];
for (int i = 48, j = 0; i <= 57; i++, j++) {
a[j] = (char) i;
}
} else {
// ASCII 48~57,String 0~9;
// ASCII 65~90,String A-Z;
// ASCII 97~122,String a-z;
a = new char[62];
for (int i = 48, j = 0; i <= 122; i++) {
if ((i > 57 && i < 65) || (i > 90 && i < 97)) {
continue;
} else {
a[j] = (char) i;
j++;
}
}
}
String strRand = "";
int LengthOfRandom = a.length;
Random random = new Random();
for (int i = 0; i < nRandomCount; i++) {
int nRand = random.nextInt(LengthOfRandom);
strRand += a[nRand];
}
return strRand;
}
public static String getEncryptPassword(String str) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
}catch (Exception e) {
e.printStackTrace();
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
else
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
}
return md5StrBuff.toString();
}
/**
* 将驼峰式命名的字符串转换为下划线大写方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。</br>
* 例如:HelloWorld->HELLO_WORLD
* @param name 转换前的驼峰式命名的字符串
* @return 转换后下划线大写方式命名的字符串
*/
public static String underscoreName(String name) {
StringBuilder result = new StringBuilder();
if (name != null && name.length() > 0) {
// 将第一个字符处理成大写
result.append(name.substring(0, 1).toUpperCase());
// 循环处理其余字符
for (int i = 1; i < name.length(); i++) {
String s = name.substring(i, i + 1);
// 在大写字母前添加下划线
if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
result.append("_");
}
// 其他字符直接转成大写
result.append(s.toUpperCase());
}
}
return result.toString();
}
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
* 例如:HELLO_WORLD->HelloWorld
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String camelName(String name) {
StringBuilder result = new StringBuilder();
// 快速检查
if (name == null || name.isEmpty()) {
// 没必要转换
return "";
} else if (!name.contains("_")) {
// 不含下划线,仅将首字母小写
return name.substring(0, 1).toLowerCase() + name.substring(1);
}
// 用下划线将原始字符串分割
String camels[] = name.split("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (camel.isEmpty()) {
continue;
}
// 处理真正的驼峰片段
if (result.length() == 0) {
// 第一个驼峰片段,全部字母都小写
result.append(camel.toLowerCase());
} else {
// 其他的驼峰片段,首字母大写
result.append(camel.substring(0, 1).toUpperCase());
result.append(camel.substring(1).toLowerCase());
}
}
return result.toString();
}
public static void main(String arg[]){
String randStr = getRandomString(32,false);
System.out.println(randStr + " \n"+randStr.length());
String pass = "111111"+randStr;
String enPass = getEncryptPassword(pass);
System.out.println( enPass+ " \n"+enPass.length());
}
}
package com.samsung.foundation.util;
public class FoundationUtil {
/**
* Escapes '%', '_' and '\' characters. Default ESCAPE character is '\'.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue) {
return safeLikeSearchEscape(sValue, '\\');
}
/**
* Escapes '%', '_' and the <code>escapeChar</code> characters.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @param escapeChar
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue, char escapeChar) {
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
char cValue = sValue.charAt(iCount);
if (cValue == '_' || cValue == '%' || cValue == escapeChar) {
sbConvertedValue.append(escapeChar);
}
sbConvertedValue.append(cValue);
}
return sbConvertedValue.toString();
}
}
package com.samsung.foundation.tag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import com.samsung.foundation.util.CommonUtil;
/**
* Cross-Site Scripting(XSS) ??? ?? EscapeTag.<br>
* value ? display ? ?? ????.<br>
* value ? <input type="text"/> ? value ?? ? ??
* <textarea/> ? text ? ?? input ??? 'true' ? ????
* ????('\n')? <br> ? ???? ??? ??.
*
* @since 0.5
*/
public class EscapeTag extends SimpleTagSupport {
private String value; // display ? ?
private String input; // text or textarea ? ?? input ??? 'true'
/**
* ???? &nbsp; ? ???? ???? ?? ?, ???? true.
* @since 1.5
*/
private boolean nbspEscape = true;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public void setNbspEscape(boolean nbspEscape) {
this.nbspEscape = nbspEscape;
}
@Override
public void doTag() throws IOException, JspException {
String outputText = null;
if ("true".equals(input)) {
outputText = CommonUtil.safeHtmlEscInput(value);
} else if ("hidden".equals(input)) {
outputText = CommonUtil.safeHtmlEscHidden(value);
} else {
outputText = CommonUtil.safeHtmlEscDisplay(value);
}
if (!nbspEscape) {
outputText = outputText.replace(" ", " ");
}
getJspContext().getOut().print(outputText);
}
}
<tag>
<name>escape</name>
<tag-class>com.samsung.foundation.tag.EscapeTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>input</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>Since v1.0</description>
<name>nbspEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
import java.security.MessageDigest;
import java.util.Collection;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
public class CommonUtil {
/**
* String ? ??? XML ???? ?? ?? ??(<,>,",',&)? ??<br>
* <input type="text"> 'tag'? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscInput(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '|':
out.append("|");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
case '*':
out.append("*");
break;
case '/':
out.append("/");
break;
case '\t':
out.append("   ");
break;
case ' ':
out.append(" ");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* value ? null ?? ???? null? ?? 0? return
*
* @param oVal ??? Integer obj
* @return null ? ?? 0, null ? ?? ?? Integer? int value
*/
public static int checkNull(Integer oVal) {
return checkNull(oVal, 0);
}
/**
* value ? null ?? ???? null? ?? 0? return
*
* @param oVal ??? Integer obj
* @param iDefaultValue oVal null ? ?? default ? ???? ?
* @return null ? ?? 0, null ? ?? ?? Integer? int value
*/
public static int checkNull(Integer oVal, int iDefaultValue) {
int iResult = iDefaultValue;
if (oVal != null) {
iResult = oVal.intValue();
}
return iResult;
}
/**
* value ? null ?? ???? ??? ???? return
*
* @param sVal ??? String
* @return null ? ?? "", null ? ?? ?? ??? ??? String
*/
public static String checkNull(String sVal) {
String sResult = "";
if (sVal != null) {
sResult = sVal.trim();
}
return sResult;
}
/**
* value ? null ? ?? defaultValue? return, null ? ?? ?? ??? ???? return
*
* @param sVal ??? String
* @param sDefaultValue sVal? null ? ?? default ? ???? ? (sDefaultValue? null ? ??? ""?? ???)
* @return null ? ?? defaultValue, null ? ?? ?? ??? ??? String
*/
public static String checkNull(String sVal, String sDefaultValue) {
String sResult = "";
if (sDefaultValue != null) {
sResult = sDefaultValue;
}
if (sVal != null && !"".equals(sVal.trim())) {
sResult = sVal.trim();
}
return sResult;
}
/**
* SQL Injection ? ???? Database ? ?? ??? ?? ????.<br>
* "'" ==> "''" ?? ??
* --, ;, % ?? ??
*
* @param sValue ?? ??? ??? ?
* @return SQL Injection ? ??? String
*/
public static String safeSqlInput(String sValue) {
String retValue;
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
if (sValue.charAt(iCount) == '\'') {
sbConvertedValue.append("'");
} else if (sValue.charAt(iCount) == ';' || sValue.charAt(iCount) == '%') {
continue;
}
sbConvertedValue.append(sValue.charAt(iCount));
}
retValue = sbConvertedValue.toString().replaceAll("--", "");
return retValue;
}
/**
* collection ? null ?? ?? ??? true return
*
* @param collection ??? Collection<?> ??? ????
* @return collection? null ?? ???? ??
*/
public static boolean isEmpty(Collection<?> collection) {
if (collection == null || collection.isEmpty()) {
return true;
}
return false;
}
/**
* String ? null ?? ?????? true return
*
* @param sVal ??? String
* @return value? null ?? ???? ??
*/
public static boolean isEmpty(String sVal) {
if (CommonUtil.checkNull(sVal).equals("")) {
return true;
}
return false;
}
/**
* Returns true if this map is <code>null</code> or contains no key-value mappings.
*
* @param map
* @return true if this map is <code>null</code> or contains no key-value mappings
* @since 1.5
*/
public static boolean isEmpty(Map<?, ?> map) {
return (map == null || map.isEmpty()) ? true : false;
}
/**
* Returns true if this array is <code>null</code> or contains no objects.
*
* @param array
* @return true if this array is <code>null</code> or contains no objects.
* @since 1.5
*/
public static boolean isEmpty(Object[] array) {
return (array == null || array.length == 0) ? true : false;
}
/**
* String ? ??? XML ???? ?? ?? ??(<,>,",',&)? ??<br>
* <input type="hidden"> 'tag'? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscHidden(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '|':
out.append("|");
break;
case '\n':
out.append("<BR>");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
case '*':
out.append("*");
break;
case '/':
out.append("/");
break;
case '\t':
out.append("   ");
break;
case ' ':
out.append(" ");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* String ? ??? XML ???? ?? ?? ??(",')? ????.<br>
* <td title='data'> ?? html ? quotation ?? ???? ???? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscInQuot(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* String ? ??? JavaScript? ?? ?? ??(',",\r,\n,\t)? ????.<br>
*
* @param src ??? String
* @param isDoubleQuot ???? ?? 'quotation'? " ?? '??(true ? ")
* @return javaScript? ?? String
*/
public static String safeHtmlEscJavaScript(String src, boolean isDoubleQuot) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '"':
if (isDoubleQuot) {
out.append("\\").append(src.charAt(i));
} else {
out.append(src.charAt(i));
}
break;
case '\'':
if (isDoubleQuot) {
out.append(src.charAt(i));
} else {
out.append("\\").append(src.charAt(i));
}
break;
case '\r':
out.append("\\r");
break;
case '\n':
out.append("\\n");
break;
case '\t':
out.append("\\t");
break;
case '\\':
out.append("\\\\");
break;
case '<':
out.append("\\074");
break;
case '>':
out.append("\\076");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* 'Quotation'?? Javascript ? ????.<br>
* safeHtmlEscJavaScript ???? " -> \042, ' -> \047 ? ????.<br>
* onclick ="javascript:alert('xxx')" ? ?? ??? ' ? " ? ??? ???? ?? ??? ????? ? ???? ????.
*
* @param src ??? String
* @return javaScript? ?? String
*/
public static String safeHtmlEscJavaScriptInQuot(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '"':
out.append("\\042");
break;
case '\'':
out.append("\\047");
break;
case '\r':
out.append("\\r");
break;
case '\n':
out.append("\\n");
break;
case '\t':
out.append("\\t");
break;
case '\\':
out.append("\\\\");
break;
case '<':
out.append("\\074");
break;
case '>':
out.append("\\076");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* Escapes '%', '_' and '\' characters. Default ESCAPE character is '\'.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue) {
return safeLikeSearchEscape(sValue, '\\');
}
/**
* Escapes '%', '_' and '\' characters.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @param escapeChar
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue, char escapeChar) {
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
char cValue = sValue.charAt(iCount);
if (cValue == '_' || cValue == '%' || cValue == escapeChar) {
sbConvertedValue.append(escapeChar);
}
sbConvertedValue.append(cValue);
}
return sbConvertedValue.toString();
}
/**
* Like ??? ??? ???? ????? Like ??? ?? ??<br>
* "'" ==> "''" ?? ??<br>
* --, ; ?? ??<br>
*
* @param sValue ?? ??? ??? ?
* @return String ??? ? (???? null ?? null ??)
*/
public static String safeLikeSearchInput(String sValue) {
return safeLikeSearchInput(sValue, false);
}
/**
* Like ??? ??? ???? ????? Like ??? ?? ??<br>
* "'" ==> "''" ?? ??<br>
* --, ; ?? ??<br>
* <br>
* ?, ???? useEscape? true ?? ??? like ?? ?? <span color="red">"escape '\'"</span>? ?????.<br>
* "%" ==> "\%" ?? ??<br>
* "_" ==> "\_" ?? ??<br>
* "`" ==> "\`" ?? ??
*
* @param sValue ?? ??? ??? ?
* @param useEscape escape ?? ????
* @return String ??? ? (???? null ?? null ??)
*/
public static String safeLikeSearchInput(String sValue, boolean useEscape) {
String retValue;
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
char cValue = sValue.charAt(iCount);
// SQL-Injection ??
if (cValue == '\'') {
sbConvertedValue.append("'");
} else if (cValue == ';') {
continue;
}
// Escape ??
else if (useEscape) {
if (cValue == '_' || cValue == '%' || cValue == '\\') {
sbConvertedValue.append("\\");
}
}
sbConvertedValue.append(cValue);
}
retValue = sbConvertedValue.toString().replaceAll("--", "");
return retValue;
}
/**
* String ? ??? XML ???? ?? ?? ??(<,>,",',&)? ????.<br>
* <td>data</td> ?? display ?? tag ? ?? ??
*
* @param src
* @return
*/
public static String safeHtmlEscDisplay(String src) {
if (src == null) {
return "";
}
StringBuilder out = new StringBuilder();
int len = src.length();
for (int i = 0; i < len; i++) {
switch (src.charAt(i)) {
case '<':
out.append("<");
break;
case '>':
out.append(">");
break;
case '"':
out.append(""");
break;
case '\'':
out.append("'");
break;
case '|':
out.append("|");
break;
case '&':
if (i + 1 < len && src.charAt(i + 1) == '#') {
out.append(src.charAt(i));
} else {
out.append("&");
}
break;
case '*':
out.append("*");
break;
case '/':
out.append("/");
break;
case '\n':
out.append("<BR>");
break;
case '\t':
out.append(" ");
break;
case ' ':
out.append(" ");
break;
default:
out.append(src.charAt(i));
}
}
return out.toString();
}
/**
* @param src
* @return
*/
public static String safeHtmlEscDisplayForKindeditor(String src) {
if (src == null) {
return "";
}
src = src.replaceAll("&", "&");
src = src.replaceAll("<", "<");
src = src.replaceAll(">", ">");
src = src.replaceAll("\"", """);
return src;
}
/**
* get uuid for table data id
* @return
* @since 1.0
*/
public static String getUUID(){
String s = UUID.randomUUID().toString();
return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
}
/**
* get random number -zq.wu
* @param nRandomCount
* @param isNumber
* @return
* @since 1.0
*/
public static String getRandomString(int nRandomCount, boolean isNumber) {
char[] a = null;
if (isNumber) {
a = new char[10];
for (int i = 48, j = 0; i <= 57; i++, j++) {
a[j] = (char) i;
}
} else {
// ASCII 48~57,String 0~9;
// ASCII 65~90,String A-Z;
// ASCII 97~122,String a-z;
a = new char[62];
for (int i = 48, j = 0; i <= 122; i++) {
if ((i > 57 && i < 65) || (i > 90 && i < 97)) {
continue;
} else {
a[j] = (char) i;
j++;
}
}
}
String strRand = "";
int LengthOfRandom = a.length;
Random random = new Random();
for (int i = 0; i < nRandomCount; i++) {
int nRand = random.nextInt(LengthOfRandom);
strRand += a[nRand];
}
return strRand;
}
public static String getEncryptPassword(String str) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
}catch (Exception e) {
e.printStackTrace();
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
else
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
}
return md5StrBuff.toString();
}
/**
* 将驼峰式命名的字符串转换为下划线大写方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。</br>
* 例如:HelloWorld->HELLO_WORLD
* @param name 转换前的驼峰式命名的字符串
* @return 转换后下划线大写方式命名的字符串
*/
public static String underscoreName(String name) {
StringBuilder result = new StringBuilder();
if (name != null && name.length() > 0) {
// 将第一个字符处理成大写
result.append(name.substring(0, 1).toUpperCase());
// 循环处理其余字符
for (int i = 1; i < name.length(); i++) {
String s = name.substring(i, i + 1);
// 在大写字母前添加下划线
if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
result.append("_");
}
// 其他字符直接转成大写
result.append(s.toUpperCase());
}
}
return result.toString();
}
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
* 例如:HELLO_WORLD->HelloWorld
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String camelName(String name) {
StringBuilder result = new StringBuilder();
// 快速检查
if (name == null || name.isEmpty()) {
// 没必要转换
return "";
} else if (!name.contains("_")) {
// 不含下划线,仅将首字母小写
return name.substring(0, 1).toLowerCase() + name.substring(1);
}
// 用下划线将原始字符串分割
String camels[] = name.split("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (camel.isEmpty()) {
continue;
}
// 处理真正的驼峰片段
if (result.length() == 0) {
// 第一个驼峰片段,全部字母都小写
result.append(camel.toLowerCase());
} else {
// 其他的驼峰片段,首字母大写
result.append(camel.substring(0, 1).toUpperCase());
result.append(camel.substring(1).toLowerCase());
}
}
return result.toString();
}
public static void main(String arg[]){
String randStr = getRandomString(32,false);
System.out.println(randStr + " \n"+randStr.length());
String pass = "111111"+randStr;
String enPass = getEncryptPassword(pass);
System.out.println( enPass+ " \n"+enPass.length());
}
}
package com.samsung.foundation.util;
public class FoundationUtil {
/**
* Escapes '%', '_' and '\' characters. Default ESCAPE character is '\'.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue) {
return safeLikeSearchEscape(sValue, '\\');
}
/**
* Escapes '%', '_' and the <code>escapeChar</code> characters.
* ESCAPE clause is required in the SQL statement.
*
* @param sValue
* @param escapeChar
* @return
* @since 1.5
*/
public static String safeLikeSearchEscape(String sValue, char escapeChar) {
if (sValue == null) {
return null;
}
StringBuilder sbConvertedValue = new StringBuilder();
int iValueLen = sValue.length();
for (int iCount = 0; iCount < iValueLen; iCount++) {
char cValue = sValue.charAt(iCount);
if (cValue == '_' || cValue == '%' || cValue == escapeChar) {
sbConvertedValue.append(escapeChar);
}
sbConvertedValue.append(cValue);
}
return sbConvertedValue.toString();
}
}
package com.samsung.foundation.tag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import com.samsung.foundation.util.CommonUtil;
/**
* Cross-Site Scripting(XSS) ??? ?? EscapeTag.<br>
* value ? display ? ?? ????.<br>
* value ? <input type="text"/> ? value ?? ? ??
* <textarea/> ? text ? ?? input ??? 'true' ? ????
* ????('\n')? <br> ? ???? ??? ??.
*
* @since 0.5
*/
public class EscapeTag extends SimpleTagSupport {
private String value; // display ? ?
private String input; // text or textarea ? ?? input ??? 'true'
/**
* ???? &nbsp; ? ???? ???? ?? ?, ???? true.
* @since 1.5
*/
private boolean nbspEscape = true;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public void setNbspEscape(boolean nbspEscape) {
this.nbspEscape = nbspEscape;
}
@Override
public void doTag() throws IOException, JspException {
String outputText = null;
if ("true".equals(input)) {
outputText = CommonUtil.safeHtmlEscInput(value);
} else if ("hidden".equals(input)) {
outputText = CommonUtil.safeHtmlEscHidden(value);
} else {
outputText = CommonUtil.safeHtmlEscDisplay(value);
}
if (!nbspEscape) {
outputText = outputText.replace(" ", " ");
}
getJspContext().getOut().print(outputText);
}
}
<tag>
<name>escape</name>
<tag-class>com.samsung.foundation.tag.EscapeTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>input</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>Since v1.0</description>
<name>nbspEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
相关推荐
编译 apr 1.7.0 需要的头文件 apr_escape_test_char.h --------------------- /* this file is automatically generated by gen_test_char, do not edit. "make include/private/apr_escape_test_char.h" to ...
JavaScript中的`escape()`和`unescape()`函数就是用于对URL进行编码和解码的经典方法。然而,在不同的编程环境下,比如Java,实现这些功能就显得尤为重要。下面,我们将深入探讨如何在Java中实现JavaScript的`escape...
在SQL Server环境中,有时我们需要处理含有特殊字符的字符串,这些字符串可能是通过JavaScript的`escape`函数编码过的。JavaScript的`escape`函数用于编码URL、非ASCII字符和其他特殊字符,以便在网络上传输。当我们...
在易语言中,"Escape加解密"是一个重要的主题,涉及到字符串处理和数据安全。 Escape 加解密是网络编程中常见的字符串编码方法。在JavaScript或者其他编程语言中,Escape函数用于将特定的字符转换为它们的Unicode...
在易语言中,"取Escape编码"是指将特定格式的数据转换为适合在网络中传输的形式,如URL编码或者Unicode编码。这些编码方式是为了确保数据在不同系统间传递时的准确性和兼容性。 首先,我们来谈谈Escape编码。在...
《ESCAPE 模拟器:洞察处理器内部运作的利器》 ESCAPE,全称为"Enhanced SPARC Architecture for Teaching and Education Processor",是一款基于SPARC(SUN公司的Simple Parallel Architecture for RISC Computers...
Error: Plugin load for plugin 'decodeutfkeys' failed with return code: Error: Can't locate URI/Escape.pm in @INC (@INC contains: /usr/lib/perl5/5.8.7/i686-linux /usr/lib/perl5/5.8.7 /usr/lib/perl...
在易语言中,"取Escape编码"通常是指将字符串转化为Escape序列的过程。Escape编码在计算机科学中是一个常见概念,特别是在处理字符串时,它用于表示那些不能直接在文本中使用的特殊字符。比如,反斜杠(\)在很多...
`Escape.java` 源代码可能是一个工具类,专门用于处理文本中的特殊字符,这些字符可能需要转义以便正确地存储、显示或传输。让我们深入探讨Java中的字符编码和解码以及可能在`Escape.java`中涉及的相关概念。 1. **...
在IT领域,"Escape"可能指的是多种含义,但在这个场景中,它似乎与“字体”这一标签相关。我们可以将“Escape”理解为一种特定的字体或者与字体设计、排版有关的技术。字体是计算机视觉呈现文字的重要元素,它影响着...
System.out.println(escape(stest)); System.out.println(unescape(escape(stest))); 输出结果: 中文1234 abcd[](),.~\ %u4E2D%u65871234+abcd%5B%5D()%3C%2B%3E%2C.~%5C 中文1234 abcd[](),.~\
### ASP函数实现JavaScript里的escape与unescape函数功能 在Web开发中,经常需要对字符串进行编码和解码处理,以确保它们能够在不同环境之间安全地传输。JavaScript 中提供了 `escape` 和 `unescape` 函数来实现这...
**增强型SCAP编辑器(eSCAPe)** eSCAPe是一款专为SCAP(Security Content Automation Protocol)内容创建和编辑设计的工具。SCAP是信息安全领域的一个开放标准,旨在自动化安全配置评估、漏洞管理和合规性检查。通过...
本篇文章将深入探讨如何利用Bootstrap实现响应式弹出层,并介绍如何通过`escape`键来关闭它们。 首先,让我们了解Bootstrap的弹出层是如何工作的。在Bootstrap中,弹出层是由`.modal`类控制的。创建一个基础的弹出...
"xe5 android Escape UnicodeString to String" 这个主题涉及到的是如何将包含Unicode转义序列的字符串转换为可读的UTF-8编码的字符串。Unicode是一种广泛使用的字符集,它包含了世界上大部分语言的字符。然而,当...
### escape、encodeURI、encodeURIComponent 区别详解 在前端开发中,经常需要用到字符串编码与解码的方法来确保数据在网络传输中的正确性与安全性。本文将详细介绍 `escape()`、`encodeURI()` 和 `...
本文将深入探讨在Java中使用MySQL的`escape`功能时可能出现的陷阱。 首先,我们需要理解MySQL的`LIKE`语句中的转义规则。在`LIKE`语句中,`%`和`_`是特殊字符,它们分别代表任意数量的字符和单个字符。为了在字符串...
当我们遇到标题中提到的"编译 apr 1.6.5 需要的头文件 apr_escape_test_char.h"的情况,这意味着在使用Apache Portable Runtime (APR)库的版本1.6.5时,编译过程中缺少了一个特定的头文件。Apache Portable Runtime ...
`encode` 和 `escape` 是处理字符串时经常遇到的两个概念,尤其在处理字符编码和网络传输时更为关键。在这篇博文中,我们将深入探讨这两个概念,以及它们在Java中的具体实现。 首先,让我们了解`encode`。字符串`...
"escape"函数在JavaScript中扮演着重要的角色,它可以帮助我们解决这类问题。本文将深入探讨如何使用"escape"函数以及相关的编码策略来解决AJAX和JS传中文乱码的问题。 首先,我们需要理解AJAX(异步JavaScript和...