cn.lkk.web.util.ext.XSSDefenseFormat Maven / Gradle / Ivy
The newest version!
package cn.lkk.web.util.ext;
import java.sql.Date;
import org.beetl.core.Format;
import cn.lkk.web.util.SqlUtil;
import lombok.extern.slf4j.Slf4j;
/**
* @author wangfujun
* @date 2019/06/12
*/
@Slf4j
public class XSSDefenseFormat implements Format {
/**
*
*/
public XSSDefenseFormat() {
// TODO Auto-generated constructor stub
}
@Override
public Object format(Object data, String pattern) {
if (null == data) {
return null;
} else {
int t = -1;
Object nV = null;
try {
if ("int".equals(pattern)) {
t = SqlUtil.TYPE_Integer;
nV = (Integer)SqlUtil.convertStandarValue(data, t);
} else if ("long".equals(pattern)) {
t = SqlUtil.TYPE_Long;
nV = (Long)SqlUtil.convertStandarValue(data, t);
} else if ("double".equals(pattern)) {
t = SqlUtil.TYPE_Double;
nV = (Double)SqlUtil.convertStandarValue(data, t);
} else if ("float".equals(pattern)) {
t = SqlUtil.TYPE_Double;
nV = (Float)SqlUtil.convertStandarValue(data, t);
} else if ("string".equals(pattern)) {
t = SqlUtil.TYPE_String;
nV = (String)SqlUtil.convertStandarValue(data, t);
} else if ("date".equals(pattern)) {
t = SqlUtil.TYPE_Date;
nV = (Date)SqlUtil.convertStandarValue(data, t);
} else if ("time".equals(pattern)) {
t = SqlUtil.TYPE_Timestamp;
nV = (Date)SqlUtil.convertStandarValue(data, t);
} else {
return null;
}
} catch (Exception ex) {
// ignore ex;
log.info("数据转换失败,原数据:" + data + "; 预转换类型 : " + pattern);
}
return nV;
}
}
}