📄 sysutil.java
字号:
int num = Math.abs( (String.valueOf(bid)).hashCode());
String className = Constant.BEANPERFIX + "Forum" + (num % 20);
return className;
}
public static int getTableID(long userID, int num) {
return (int) (userID % num);
}
public static int getForumTableID(long bid) {
int num = Math.abs( (String.valueOf(bid)).hashCode());
return (int) (num % 20);
}
public static boolean isBadNickName(String nickName) {
if (SysInfo.getInstance().getForbidnickname() != null &&
SysInfo.getInstance().getForbidnickname().length() > 0) {
String[] badNickNames = SysInfo.getInstance().getForbidnickname().split(
",");
if (badNickNames != null) {
for (int i = 0; i < badNickNames.length; i++) {
if (nickName.indexOf(badNickNames[i]) != -1) {
return true;
}
}
}
}
return false;
}
public static String getBoardsSaveChecked(String userSave, long id) {
if (userSave == null || userSave.length() == 0) {
return "";
}
else {
String[] userSaves = userSave.split(",");
for (int i = 0; i < userSaves.length; i++) {
if (Long.parseLong(userSaves[i]) == id) {
return "checked";
}
}
return "";
}
}
public static List Objects2List(long[] os) {
List l = new ArrayList();
if (os != null) {
for (int i = 0; i < os.length; i++) {
l.add(new Long(os[i]));
}
}
return l;
}
public static boolean isAllowFile(String flag, String fileName) {
boolean isAllow = false;
if (flag.equals("pic")) {
fileName = fileName.toLowerCase();
if (fileName.endsWith(".jpg") || fileName.endsWith(".gif") ||
fileName.endsWith(".jpeg")) {
isAllow = true;
}
}
if (flag.equals("file")) {
fileName = fileName.toLowerCase();
if (SysInfo.getInstance().getUpfilename() != null) {
String[] fileext = SysInfo.getInstance().getUpfilename().split(",");
for (int i = 0; i < fileext.length; i++) {
if (fileName.endsWith(fileext[i])) {
return true;
}
}
}
else {
return false;
}
}
return isAllow;
}
public static String getFileExt(String fileName) {
if (fileName != null) {
String fileExt = "";
fileName = fileName.toLowerCase();
int index = fileName.lastIndexOf(".");
fileExt = fileName.substring(index, fileName.length());
return fileExt;
}
else {
return "";
}
}
public static boolean isNotAllowIP(String ip) {
HashMap iphm = Forbid.getInstance().getForbidipHm();
String badip = "";
Iterator it = iphm.values().iterator();
while (it.hasNext()) {
badip = (String) it.next();
if (ip.equals(badip)) {
return true;
}
}
return false;
}
public static boolean isNotAllowRegName(String username) {
if (Constant.NOTREGNAME != null) {
for (int i = 0; i < Constant.NOTREGNAME.length; i++) {
if (username.indexOf(Constant.NOTREGNAME[i]) != -1) {
return true;
}
}
}
return false;
}
public static Result getBadWordsInPost(String content) {
HashMap hm = Forbid.getInstance().getForbidwordsHm();
String badWords = "";
Iterator it = hm.values().iterator();
while (it.hasNext()) {
badWords = (String) it.next();
if (content.indexOf(badWords) != -1) {
//System.out.println(badWords);
return new Result(false, "", badWords);
}
}
return new Result(true, "");
}
public static String scriptEncode(String txt) {
if (txt != null) {
txt = Util.replaceIgnoreCase(txt, "script", "SCRIPT");
txt = Util.replaceIgnoreCase(txt, "<html", "<html");
txt = Util.replaceIgnoreCase(txt, "<title", "<title");
txt = Util.replaceIgnoreCase(txt, "<body", "<body");
txt = Util.replaceIgnoreCase(txt, "</body", "</body");
txt = Util.replaceIgnoreCase(txt, "</html", "</html");
txt = Util.replaceIgnoreCase(txt, "</title", "</title");
}
return txt;
}
public static String encodeURL(String url, String charset) {
if (url != null && url.length() > 0) {
try {
return URLEncoder.encode(url, charset);
}
catch (UnsupportedEncodingException ex) {
return url;
}
}
return url;
}
public static String getPostDetail(String detail) {
if (detail != null && detail.length() > 0) {
int start = detail.indexOf("<body>");
if (start != -1) {
detail = detail.substring(start + 6, detail.length());
}
int end = detail.lastIndexOf("</body>");
if (end != -1) {
detail = detail.substring(0, end);
}
}
return detail;
}
public static String getIndexPath() {
String filePath = Constant.ROOTPATH + "file/index/";
File ft = new File(filePath);
if (!ft.exists()) {
ft.mkdirs();
}
return filePath;
}
public static String getPostFilePath() {
String filePath = Constant.ROOTPATH + "file/postfile/";
File ft = new File(filePath);
if (!ft.exists()) {
ft.mkdirs();
}
return filePath;
}
public static String getPostPageBreakStr(String aJspFileName, int totalNum,
int perNum) {
StringBuffer sb = new StringBuffer();
if (totalNum > perNum) {
sb.append(" [<img src='images/multipage.gif' align='absmiddle'>");
int totalPages = (int) Math.ceil( (totalNum + perNum - 1) / perNum);
for (int i = 1; i <= totalPages; i++) {
sb.append(" <a href='");
sb.append(aJspFileName);
sb.append(i);
sb.append("'><b>");
sb.append(i);
sb.append("</b></a>");
}
sb.append("]");
}
return sb.toString();
}
public static void delFile(String filePath) {
File picFile = new File(filePath);
if (picFile.exists()) {
picFile.delete();
}
picFile = null;
}
public static String getUBB2HTML(String txt) {
if (txt != null) {
AutoFilter af = new AutoFilter(txt);
txt = af.getFilteredStr();
}
return txt;
}
public static String unBr(String string) {
if (string != null) {
string = string.replaceAll("<BR>", "\n");
}
return string;
}
public static void cpoyFile(String src, String to) {
File srcFile = new File(src);
if (srcFile.exists()) {
try {
FileInputStream bw = new FileInputStream(srcFile);
OutputStream bos = new FileOutputStream(to);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ( (bytesRead = bw.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
bw.close();
bos = null;
bw = null;
}
catch (FileNotFoundException ex) {
}
catch (IOException ex) {
}
}
}
public static int stringAppearTimes(String s, String reg) {
int times = 0;
int fromindex = 0;
int index = 0;
String content = s;
index = content.indexOf(reg, fromindex);
while (index != -1) {
times++;
fromindex = index + reg.length();
index = content.indexOf(reg, fromindex);
}
return times;
}
public static String getPostTitleMax(String title) {
if (title != null) {
if (title.length() > SysInfo.getInstance().getPosttitlemax()) {
title = title.substring(0, SysInfo.getInstance().getPosttitlemax()) +
"...";
}
}
return title;
}
public static String getWebRealPath(HttpServletRequest request) {
StringBuffer sb = new StringBuffer();
sb.append("http://");
sb.append(request.getServerName());
if (request.getServerPort() != 80) {
sb.append(":");
sb.append(request.getServerPort());
}
sb.append(request.getContextPath());
sb.append("/");
return sb.toString();
}
public static String getToURL(HttpServletRequest request, String fileName) {
StringBuffer url = new StringBuffer();
if (fileName != null) {
fileName = encodeURL(fileName, Constant.CHARSET);
}
if (SysInfo.getInstance().getUsepass().equals("y")) {
url.append(getWebRealPath(request));
url.append("passLogin");
url.append(Constant.FILEPREFIX);
url.append("?action=passlogin&tourl=");
url.append(fileName);
}
else {
url.append(fileName);
}
return url.toString();
}
public static ActionForward getPassLogin(ActionMapping actionMapping) {
if (SysInfo.getInstance().getUsepass().equals("y")) {
return actionMapping.findForward("passlogin");
}
else {
return actionMapping.findForward("login");
}
}
public static String getSearchURL(String url) {
url = url.substring(url.lastIndexOf("/"), url.length());
String[] urls = url.split("_");
StringBuffer sb = new StringBuffer();
sb.append("read");
sb.append(Constant.FILEPREFIX);
sb.append("?bid=");
sb.append(urls[2]);
sb.append("&id=");
sb.append(urls[1]);
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -