ForumFactory.java
上传用户:yuyunping
上传日期:2013-03-21
资源大小:1844k
文件大小:10k
源码类别:

Java书籍

开发平台:

Java

  1. package net.acai.forum;
  2. /**
  3.  * Title:        清清网络
  4.  * Description:
  5.  * Copyright:    Copyright (c) 2002
  6.  * Company:      www.SuperSpace.com
  7.  * @author:       SuperSpace
  8.  * @version 1.0
  9.  */
  10. import net.acai.forum.*;
  11. import net.acai.database.DBConnect;
  12. import net.acai.util.*;
  13. import java.util.Vector;
  14. import java.sql.ResultSet;
  15. import javax.servlet.http.*;
  16. public class ForumFactory{
  17. public static Vector getForums(int gateWayID)
  18. throws ForumNotFoundException{
  19. try{
  20. DBConnect dbc=new DBConnect("select * from bbs.board where class=?");
  21. dbc.setInt(1,gateWayID);
  22. Vector forumVector=new Vector();
  23. ResultSet rs=dbc.executeQuery();
  24. while(rs.next()){
  25. int forumID=rs.getInt(1);
  26. Forum theForum=new Forum(forumID);
  27. forumVector.add(theForum);
  28. }
  29. dbc.close();
  30. return forumVector;
  31. }
  32. catch(Exception e){
  33. throw new ForumNotFoundException("字符出错");
  34. }
  35. }
  36. public static Forum getForum(int forumID) throws ForumNotFoundException{
  37. try{
  38. Forum theForum=new Forum(forumID);
  39. return theForum;
  40. }
  41. catch(Exception e){
  42. e.printStackTrace();
  43. throw new ForumNotFoundException();
  44. }
  45. }
  46. public static Forum getForum(HttpServletRequest request,HttpServletResponse response,HttpSession session,int forumID) throws ForumNotFoundException{
  47. Forum theForum=new Forum(request,response,forumID);
  48. return theForum;
  49. }
  50. public static Vector getOLUsers(String sign){
  51. try{
  52. DBConnect dbc=new DBConnect("select * from bbs.online order by id");
  53. Vector forumOLUsers=null;
  54. forumOLUsers=new Vector();
  55. ResultSet rs;
  56. rs=dbc.executeQuery();
  57. while(rs.next()){
  58. if(sign.equals("guest")&&rs.getString(2).equals("guest")){
  59. OLUser tempOLUser=new OLUser();
  60. tempOLUser.setUserID(rs.getInt(1));
  61. tempOLUser.setUserName(rs.getString(2));
  62. tempOLUser.setUserClass(rs.getString(3));
  63. tempOLUser.setStats(rs.getString(4));
  64. tempOLUser.setUserIP(rs.getString(5));
  65. tempOLUser.setStartTime(rs.getString(6));
  66. tempOLUser.setLastTimeBK(rs.getString(7));
  67. tempOLUser.setLastTime(rs.getString(8));
  68. tempOLUser.setBrowser(rs.getString(9));
  69. tempOLUser.setActForIP(rs.getString(10));
  70. tempOLUser.setComeFrom(rs.getString(11));
  71. tempOLUser.setActCome(rs.getString(12));
  72. forumOLUsers.add(tempOLUser);
  73. }
  74. else if(sign.equals("member")&&!rs.getString(2).equals("guest")){
  75. OLUser tempOLUser=new OLUser();
  76. tempOLUser.setUserID(rs.getInt(1));
  77. tempOLUser.setUserName(rs.getString(2));
  78. tempOLUser.setUserClass(rs.getString(3));
  79. tempOLUser.setStats(rs.getString(4));
  80. tempOLUser.setUserIP(rs.getString(5));
  81. tempOLUser.setStartTime(rs.getString(6));
  82. tempOLUser.setLastTimeBK(rs.getString(7));
  83. tempOLUser.setLastTime(rs.getString(8));
  84. tempOLUser.setBrowser(rs.getString(9));
  85. tempOLUser.setActForIP(rs.getString(10));
  86. tempOLUser.setComeFrom(rs.getString(11));
  87. tempOLUser.setActCome(rs.getString(12));
  88. forumOLUsers.add(tempOLUser);
  89. }
  90. else if(sign.equals("total")){
  91. OLUser tempOLUser=new OLUser();
  92. tempOLUser.setUserID(rs.getInt(1));
  93. tempOLUser.setUserName(rs.getString(2));
  94. tempOLUser.setUserClass(rs.getString(3));
  95. tempOLUser.setStats(rs.getString(4));
  96. tempOLUser.setUserIP(rs.getString(5));
  97. tempOLUser.setStartTime(rs.getString(6));
  98. tempOLUser.setLastTimeBK(rs.getString(7));
  99. tempOLUser.setLastTime(rs.getString(8));
  100. tempOLUser.setBrowser(rs.getString(9));
  101. tempOLUser.setActForIP(rs.getString(10));
  102. tempOLUser.setComeFrom(rs.getString(11));
  103. tempOLUser.setActCome(rs.getString(12));
  104. forumOLUsers.add(tempOLUser);
  105. }
  106. }
  107. dbc.close();
  108. return forumOLUsers;
  109. }
  110. catch(Exception e){
  111. e.printStackTrace();
  112. return null;
  113. //throw new ForumNotFoundException("字符出错");
  114. }
  115. }
  116. public static Vector getOLGuestUsers(){
  117. return getOLUsers("guest");
  118. }
  119. public static int getOLGuestUsersNum(){
  120. return getOLGuestUsers().size();
  121. }
  122. public static Vector getOLMemberUsers(){
  123. return getOLUsers("member");
  124. }
  125. public static int getOLMemberUsersNum(){
  126. return getOLMemberUsers().size();
  127. }
  128. public static int getOLUsersNum(){
  129. return getOLUsers("total").size();
  130. }
  131. public static void addUser(HttpServletRequest request,int wealthReg,int epReg,int cpReg) throws Exception{
  132. String userName=ParamUtil.getString(request,"userName","");
  133. String psw=ParamUtil.getString(request,"psw","");
  134. String userPassword="";
  135. String pswc=ParamUtil.getString(request,"pswc","");
  136. String userEmail=ParamUtil.getString(request,"userEmail","");
  137. String face=ParamUtil.getString(request,"face","");
  138. int width=ParamUtil.getInt(request,"width",0);
  139. int height=ParamUtil.getInt(request,"height",0);
  140. String oicq=ParamUtil.getString(request,"oicq");
  141. String sign=ParamUtil.getString(request,"sign","");
  142. String myFace=ParamUtil.getString(request,"myface","");
  143. boolean foundErr=false;
  144. String errMSG="";
  145. int sex=0;
  146. int showRe=0;
  147. if("".equals(userName)||userName.length()>20)
  148. {
  149. errMSG=errMSG+"<br>"+"<li>请输入您的用户名(长度不能大于20)。";
  150. foundErr=true;
  151. }
  152. 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){
  153. errMSG=errMSG+"<br>"+"<li>用户名中含有非法字符。";
  154. foundErr=true;
  155. }
  156. try{
  157. sex=ParamUtil.getInt(request,"sex");
  158. }
  159. catch(NumberFormatException e)
  160. {
  161. errMSG=errMSG+"<br>"+"<li>请选择您的性别。";
  162. foundErr=true;
  163. }
  164. try{
  165. showRe=ParamUtil.getInt(request,"showRe");
  166. }
  167. catch(NumberFormatException e){
  168. errMSG=errMSG+"<br>"+"<li>请选择您的帖子有回复时是否要提示您。";
  169. foundErr=true;
  170. }
  171. if("".equals(psw) || psw.length()>10){
  172. errMSG=errMSG+"<br>"+"<li>请输入您的密码(长度不能大于10)。";
  173. foundErr=true;
  174. }
  175. if (!pswc.equals(psw)){
  176. errMSG=errMSG+"<br>"+"<li>您输入的密码和确认密码不一致。";
  177. foundErr=true;
  178. }
  179. else
  180. userPassword=psw;
  181. if (userEmail.indexOf('@')<0||userEmail.indexOf('.')<0){
  182. errMSG=errMSG+"<br>"+"<li>您的Email有错误。";
  183.     foundErr=true;
  184.     }
  185.     if (!"".equals(myFace)){
  186.     if (width==0 || height==0){
  187. errMSG=errMSG+"<br>"+"<li>请输入图片的宽度和高度。";
  188. foundErr=true;
  189. }
  190. else if (width<20|| width>80){
  191. errMSG=errMSG+"<br>"+"<li>您输入的图片宽度不符合标准。";
  192. foundErr=true;
  193. }
  194. else if (height<20 || height>80){
  195. errMSG=errMSG+"<br>"+"<li>您输入的图片高度不符合标准。";
  196. foundErr=true;
  197. }
  198. else face=myFace;
  199. }
  200. else
  201. if ("".equals(face)){
  202. errMSG=errMSG+"<br>"+"<li>请选择您的个性头像。";
  203. foundErr=true;
  204. }
  205. else if (face.endsWith(".gif")){
  206. width=32;
  207. height=32;
  208. }
  209. else{
  210. errMSG=errMSG+"<br>"+"<li>您选择了错误的头像。";
  211. foundErr=true;
  212. }
  213. if(oicq==null)
  214. oicq="";
  215. else
  216. try{
  217. Integer.parseInt(oicq);
  218. }
  219. catch(NumberFormatException e)
  220. {
  221. errMSG=errMSG+"<br>"+"<li>Oicq号码只能是4-10位数字,您可以选择不输入。";
  222. foundErr=true;
  223. }
  224. if(!foundErr)
  225. {
  226. try{
  227. DBConnect dbc=new DBConnect("select * from bbs.myuser where username=?");
  228. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  229. ResultSet rs=dbc.executeQuery();
  230. if(rs.next()){
  231. dbc.close();
  232. throw new UserAlreadyExistException();
  233. }
  234. MD5 md5=new MD5();
  235. dbc.clearParameters();
  236. dbc.prepareStatement("insert into bbs.myuser ( userName,userPassword,userEmail,userClass,sign,oicq,article,lockuser,sex,showRe,addDate,face,width,height,logins,lastlogin,userWealth,userEP,userCP) values( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  237. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  238. dbc.setBytes(2,(new String(md5.getMD5ofStr(userPassword).getBytes("ISO-8859-1"),"GBK")).getBytes());
  239. dbc.setBytes(3,(new String(userEmail.getBytes("ISO-8859-1"),"GBK")).getBytes());
  240. dbc.setInt(4,1);
  241. dbc.setBytes(5,(new String(sign.getBytes("ISO-8859-1"),"GBK")).getBytes());
  242. dbc.setBytes(6,(new String(oicq.getBytes("ISO-8859-1"),"GBK")).getBytes());
  243. dbc.setInt(7,0);
  244. dbc.setInt(8,0);
  245. dbc.setInt(9,sex);
  246. dbc.setInt(10,showRe);
  247. dbc.setString(11,Format.getDateTime());
  248. dbc.setBytes(12,(new String(face.getBytes("ISO-8859-1"),"GBK")).getBytes());
  249. dbc.setInt(13,width);
  250. dbc.setInt(14,height);
  251. dbc.setInt(15,1);
  252. dbc.setString(16,Format.getDateTime());
  253. dbc.setInt(17,wealthReg);
  254. dbc.setInt(18,epReg);
  255. dbc.setInt(19,cpReg);
  256. dbc.executeUpdate();
  257. dbc.clearParameters();
  258. dbc.prepareStatement("update bbs.config set usernum=usernum+1,lastUser=?");
  259. dbc.setBytes(1,userName.getBytes());
  260. dbc.executeUpdate();
  261. String forumName=ForumPropertiesManager.getString("ForumName");
  262. String sender=forumName;
  263. String title=forumName+"欢迎您的到来";
  264. String body=forumName+"全体管理人员欢迎您的到来n如有任何疑问请及时联系系统管理员。n如有任何使用上的问题请查看论坛帮助。n感谢您注册本系统,让我们一起来建设这个网上家园!";
  265. String sql="insert into bbs.message(incept,sender,title,content,sendtime,flag,issend) values(?,?,?,?,getdate(),0,1)";
  266. dbc.prepareStatement(sql);
  267. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  268. dbc.setBytes(2,(new String(sender.getBytes("ISO-8859-1"),"GBK")).getBytes());
  269. dbc.setBytes(3,(new String(title.getBytes("ISO-8859-1"),"GBK")).getBytes());
  270. dbc.setBytes(4,(new String(body.getBytes("ISO-8859-1"),"GBK")).getBytes());
  271. dbc.executeUpdate();
  272. dbc.close();
  273. ForumPropertiesManager.resetManager();
  274. }
  275. catch(UserAlreadyExistException e){
  276. errMSG=errMSG+"<br>"+"<li>对不起,您输入的用户名已经被注册,请重新输入。";
  277. throw new Exception(errMSG);
  278. }
  279. catch(Exception e){
  280. e.printStackTrace();
  281. throw e;
  282. }
  283. }
  284. if(foundErr)
  285. throw new Exception(errMSG);
  286. }
  287. }