import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.*;import cn.com.database.sql.SqlCall_Query_t_Policy;
public class Helper {
public static Date getSysDateFromDB() {
Date dt = new Date();
ResultSet rs = null;
SqlCall_Query_t_Policy call = new SqlCall_Query_t_Policy("select getdate()");
try {
rs = call.executeQuery();
if (rs.next()) {
dt = rs.getDate(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null)
try {
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
}
if (call != null)
call.close();
}
return dt;
}public static Date getDatePartOnly() {
Calendar c = Calendar.getInstance();
c.setTime(getSysDateFromDB());
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0); return c.getTime();
}public static String getStringDatePartOnly() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
return format.format(getSysDateFromDB());
}
public static String makeSafe(String str) {
if (str == null)
return str;
String regEx_script = "<[//s]*?script[^>]*?>[//s//S]*?<[//s]*?///[//s]*?script[//s]*?>"; // 定义script的正则表达式{或<script[^>]*?>[//s//S]*?<///script>
String regEx_style = "<[//s]*?style[^>]*?>[//s//S]*?<[//s]*?///[//s]*?style[//s]*?>"; // 定义style的正则表达式{或<style[^>]*?>[//s//S]*?<///style>
String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
String regEx_html1 = "<[^>]+";
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(str);
str = m_script.replaceAll(""); // 过滤script标签
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(str);
str = m_style.replaceAll(""); // 过滤style标签
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(str);
str = m_html.replaceAll(""); // 过滤html标签
Pattern p_html1 = Pattern.compile(regEx_html1, Pattern.CASE_INSENSITIVE);
Matcher m_html1 = p_html1.matcher(str);
str = m_html1.replaceAll(""); // 过滤html标签
return str;
}
}