📄 forumfactory.java
字号:
package com.bcxy.bbs.forum;
/**
* Title:
* Description:
* Copyright:
* Company: www.liyunet.com
*
* @author lishujiang
* @version 1.0
*/
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bcxy.bbs.database.DBConnect;
import com.bcxy.bbs.util.Format;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.cache.CacheManager;
import com.bcxy.conf.ENV;
import com.bcxy.db.SqlQuery;
import com.bcxy.util.SysUtil;
public class ForumFactory {
/**
* 取得论坛信息------缓存
* @param gateWayID
* @return
* @throws ForumNotFoundException
*/
public static Vector getForums(int gateWayID) throws ForumNotFoundException {
SqlQuery rs = new SqlQuery();
Vector forumVector = new Vector();
try {
rs.doQuery("select boardid from board where class='"+gateWayID+"'");
//
while (rs.next()) {
int forumID = rs.getInt(1);
Forum theForum = (Forum)CacheManager.getCache(ENV.FORUM).get(String.valueOf(forumID));
if(theForum==null){
theForum = new Forum(forumID);
CacheManager.getCache(ENV.FORUM).put(String.valueOf(forumID),theForum);
}
forumVector.add(theForum);
}
return forumVector;
} catch (Exception e) {
throw new ForumNotFoundException("字符出错");
}
}
/**
* 取得论坛信息------缓存
* @param forumID
* @return
* @throws ForumNotFoundException
*/
public static Forum getForum(int forumID) throws ForumNotFoundException {
try {
Forum theForum = (Forum)CacheManager.getCache(ENV.FORUM).get(String.valueOf(forumID));
if(theForum==null){
theForum = new Forum(forumID);
CacheManager.getCache(ENV.FORUM).put(String.valueOf(forumID),theForum);
}
return theForum;
} catch (Exception e) {
e.printStackTrace();
throw new ForumNotFoundException();
}
}
public static Forum getForum(HttpServletRequest request,
HttpServletResponse response, HttpSession session, int forumID)
throws ForumNotFoundException {
Forum theForum = new Forum(request, response, forumID);
return theForum;
}
public static Vector getOLUsers(String sign) {
try {
SqlQuery rs = new SqlQuery("select * from online order by id");
Vector forumOLUsers = new Vector();
while (rs.next()) {
if (sign.equals("guest") && rs.getString(2).equals("guest")) {
OLUser tempOLUser = new OLUser();
tempOLUser.setUserID(rs.getString(1));
tempOLUser.setUserName(rs.getString(2));
tempOLUser.setUserClass(rs.getString(3));
tempOLUser.setStats(rs.getString(4));
tempOLUser.setUserIP(rs.getString(5));
tempOLUser.setStartTime(rs.getString(6));
tempOLUser.setLastTimeBK(rs.getString(7));
tempOLUser.setLastTime(rs.getString(8));
tempOLUser.setBrowser(rs.getString(9));
tempOLUser.setActForIP(rs.getString(10));
tempOLUser.setComeFrom(rs.getString(11));
tempOLUser.setActCome(rs.getString(12));
forumOLUsers.add(tempOLUser);
} else if (sign.equals("member")
&& !rs.getString(2).equals("guest")) {
OLUser tempOLUser = new OLUser();
tempOLUser.setUserID(rs.getString(1));
tempOLUser.setUserName(rs.getString(2));
tempOLUser.setUserClass(rs.getString(3));
tempOLUser.setStats(rs.getString(4));
tempOLUser.setUserIP(rs.getString(5));
tempOLUser.setStartTime(rs.getString(6));
tempOLUser.setLastTimeBK(rs.getString(7));
tempOLUser.setLastTime(rs.getString(8));
tempOLUser.setBrowser(rs.getString(9));
tempOLUser.setActForIP(rs.getString(10));
tempOLUser.setComeFrom(rs.getString(11));
tempOLUser.setActCome(rs.getString(12));
forumOLUsers.add(tempOLUser);
} else if (sign.equals("total")) {
OLUser tempOLUser = new OLUser();
tempOLUser.setUserID(rs.getString(1));
tempOLUser.setUserName(rs.getString(2));
tempOLUser.setUserClass(rs.getString(3));
tempOLUser.setStats(rs.getString(4));
tempOLUser.setUserIP(rs.getString(5));
tempOLUser.setStartTime(rs.getString(6));
tempOLUser.setLastTimeBK(rs.getString(7));
tempOLUser.setLastTime(rs.getString(8));
tempOLUser.setBrowser(rs.getString(9));
tempOLUser.setActForIP(rs.getString(10));
tempOLUser.setComeFrom(rs.getString(11));
tempOLUser.setActCome(rs.getString(12));
forumOLUsers.add(tempOLUser);
}
}
return forumOLUsers;
} catch (Exception e) {
e.printStackTrace();
return null;
// throw new ForumNotFoundException("字符出错");
}
}
public static Vector getOLGuestUsers() {
return getOLUsers("guest");
}
public static int getOLGuestUsersNum() {
return getOLGuestUsers().size();
}
public static Vector getOLMemberUsers() {
return getOLUsers("member");
}
public static int getOLMemberUsersNum() {
return getOLMemberUsers().size();
}
public static int getOLUsersNum() {
return getOLUsers("total").size();
}
public static void addUser(HttpServletRequest request, int wealthReg,
int epReg, int cpReg) throws Exception {
String userName = ParamUtil.getString(request, "userName", "");
String psw = ParamUtil.getString(request, "psw", "");
String userPassword = "";
String pswc = ParamUtil.getString(request, "pswc", "");
String userEmail = ParamUtil.getString(request, "userEmail", "");
String face = ParamUtil.getString(request, "face", "");
int width = ParamUtil.getInt(request, "width", 0);
int height = ParamUtil.getInt(request, "height", 0);
String oicq = ParamUtil.getString(request, "oicq", "");
String sign = ParamUtil.getString(request, "sign", "");
String myFace = ParamUtil.getString(request, "myface", "");
boolean foundErr = false;
String errMSG = "";
int sex = 0;
int showRe = 0;
if ("".equals(userName) || userName.length() > 20) {
errMSG = errMSG + "<br>" + "<li>请输入您的用户名(长度不能大于20)。";
foundErr = true;
}
if (userName.indexOf('=') > -1 || userName.indexOf('%') > -1
|| userName.indexOf('?') > -1 || userName.indexOf('&') > -1
|| userName.indexOf(';') > -1 || userName.indexOf(',') > 0
|| userName.indexOf('\'') > -1 || userName.indexOf('+') > -1) {
errMSG = errMSG + "<br>" + "<li>用户名中含有非法字符。";
foundErr = true;
}
try {
sex = ParamUtil.getInt(request, "sex");
} catch (NumberFormatException e) {
errMSG = errMSG + "<br>" + "<li>请选择您的性别。";
foundErr = true;
}
try {
showRe = ParamUtil.getInt(request, "showRe");
} catch (NumberFormatException e) {
errMSG = errMSG + "<br>" + "<li>请选择您的帖子有回复时是否要提示您。";
foundErr = true;
}
if ("".equals(psw) || psw.length() > 10) {
errMSG = errMSG + "<br>" + "<li>请输入您的密码(长度不能大于10)。";
foundErr = true;
}
if (!pswc.equals(psw)) {
errMSG = errMSG + "<br>" + "<li>您输入的密码和确认密码不一致。";
foundErr = true;
} else
userPassword = psw;
if (userEmail.indexOf('@') < 0 || userEmail.indexOf('.') < 0) {
errMSG = errMSG + "<br>" + "<li>您的Email有错误。";
foundErr = true;
}
if (!"".equals(myFace)) {
if (width == 0 || height == 0) {
errMSG = errMSG + "<br>" + "<li>请输入图片的宽度和高度。";
foundErr = true;
} else if (width < 20 || width > 80) {
errMSG = errMSG + "<br>" + "<li>您输入的图片宽度不符合标准。";
foundErr = true;
} else if (height < 20 || height > 80) {
errMSG = errMSG + "<br>" + "<li>您输入的图片高度不符合标准。";
foundErr = true;
} else
face = myFace;
} else if ("".equals(face)) {
errMSG = errMSG + "<br>" + "<li>请选择您的个性头像。";
foundErr = true;
} else if (face.endsWith(".gif")) {
width = 32;
height = 32;
} else {
errMSG = errMSG + "<br>" + "<li>您选择了错误的头像。";
foundErr = true;
}
if (!"".equals(oicq)){
try {
Integer.parseInt(oicq);
} catch (NumberFormatException e) {
errMSG = errMSG + "<br>" + "<li>Oicq号码只能是4-10位数字,您可以选择不输入。";
foundErr = true;
}
}
if (!foundErr) {
DBConnect dbc = new DBConnect();
try {
SqlQuery rs = new SqlQuery("select UserPassword from user where username='" + userName + "'");
if (rs.next()) {
throw new UserAlreadyExistException();
}
dbc.prepareStatement("insert into user ( userName,userPassword,userEmail,userClass,sign,oicq,article,lockuser,sex,showRe,addDate,face,width,height,logins,lastlogin,userWealth,userEP,userCP) values( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
dbc.setString(1, userName);
dbc.setString(2, (userPassword));
dbc.setString(3, userEmail);
dbc.setInt(4, 1);
dbc.setString(5, sign);
dbc.setString(6, oicq);
dbc.setInt(7, 0);
dbc.setInt(8, 0);
dbc.setInt(9, sex);
dbc.setInt(10, showRe);
dbc.setString(11, Format.getDateTime());
dbc.setString(12, face);
dbc.setInt(13, width);
dbc.setInt(14, height);
dbc.setInt(15, 1);
dbc.setString(16, Format.getDateTime());
dbc.setInt(17, wealthReg);
dbc.setInt(18, epReg);
dbc.setInt(19, cpReg);
dbc.executeUpdate();
dbc.clearParameters();
dbc.prepareStatement("update config set usernum=usernum+1,lastUser=?");
dbc.setString(1, userName);
dbc.executeUpdate();
String forumName = ForumPropertiesManager
.getString("ForumName");
String sender = forumName;
String title = forumName + "欢迎您的到来";
String body = forumName
+ "全体管理人员欢迎您的到来\n如有任何疑问请及时联系系统管理员。\n如有任何使用上的问题请查看论坛帮助。\n感谢您注册本系统,让我们一起来建设这个网上家园!";
//
String sql = "insert into message(incept,sender,title,content,sendtime,flag,issend) values(?,?,?,?,now(),0,1)";
dbc.prepareStatement(sql);
dbc.setString(1, SysUtil.encodeInDB(userName));
dbc.setString(2, SysUtil.encodeInDB(sender));
dbc.setString(3, SysUtil.encodeInDB(title));
dbc.setString(4, SysUtil.encodeInDB(body));
dbc.executeUpdate();
dbc.close();
ForumPropertiesManager.resetManager();
} catch (UserAlreadyExistException e) {
errMSG = errMSG + "<br>" + "<li>对不起,您输入的用户名已经被注册,请重新输入。";
throw new Exception(errMSG);
} catch (Exception e) {
e.printStackTrace();
throw new Exception("用户注册出错。");
}finally{
dbc.close();
}
}else{
throw new Exception(errMSG);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -