| 1 23 27 package org.jresearch.gossip.actions.topic; 28 29 import java.lang.reflect.InvocationTargetException ; 30 import java.sql.SQLException ; 31 import java.util.Date ; 32 import java.util.HashMap ; 33 import java.util.Iterator ; 34 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import javax.servlet.http.HttpSession ; 38 39 import org.apache.struts.action.ActionForm; 40 import org.apache.struts.action.ActionForward; 41 import org.apache.struts.action.ActionMapping; 42 import org.jresearch.gossip.IConst; 43 import org.jresearch.gossip.actions.BaseAction; 44 import org.jresearch.gossip.beans.forum.Forum; 45 import org.jresearch.gossip.beans.forum.Message; 46 import org.jresearch.gossip.beans.forum.Topic; 47 import org.jresearch.gossip.beans.user.User; 48 import org.jresearch.gossip.configuration.Configurator; 49 import org.jresearch.gossip.dao.ForumDAO; 50 import org.jresearch.gossip.dao.UserDAO; 51 import org.jresearch.gossip.exception.SystemException; 52 import org.jresearch.gossip.forms.ProcessTopicForm; 53 import org.jresearch.gossip.list.RecordsData; 54 55 60 public class ShowTopicAction extends BaseAction { 61 75 public ActionForward process(ActionMapping mapping, ActionForm form, 76 HttpServletRequest request, HttpServletResponse response) 77 throws SystemException { 78 ProcessTopicForm ptForm = (ProcessTopicForm) form; 79 ForumDAO dao = ForumDAO.getInstance(); 80 UserDAO userdao = UserDAO.getInstance(); 81 HttpSession session = request.getSession(); 82 User user = (User) session.getAttribute(IConst.SESSION.USER_KEY); 83 int fid = Integer.parseInt(ptForm.getFid()); 84 int tid = Integer.parseInt(ptForm.getTid()); 85 try { 86 87 Forum currForum = dao.getForumInfo(fid); 88 if ((currForum.getLocked() == IConst.Forum.STATUS_INVISIBLE) 90 && (user.getStatus() < Integer.parseInt(Configurator 91 .getInstance().get(IConst.CONFIG.INVADER1)))) { 92 return (mapping.findForward(IConst.TOKEN.DENIED)); 93 } 94 request.setAttribute(IConst.REQUEST.CURR_FORUM, currForum); 95 session.setAttribute(IConst.SESSION.CURR_FORUM, currForum); 96 updateLastVisitTime((HashMap ) session 97 .getAttribute(IConst.SESSION.LAST_INTIME), ptForm.getTid(), 98 dao.now()); 99 RecordsData recordsData = new RecordsData(); 100 Topic currThread = dao.getThreadInfo(tid); 101 dao.fillMessagesList(user, recordsData, ptForm); 102 Iterator it = recordsData.getRecords().iterator(); 103 boolean attachEnabled = Configurator.getInstance().getBoolean( 104 IConst.CONFIG.ENABLE_FILE_UPLOAD); 105 if (it.hasNext()) { 106 Message mess = (Message) it.next(); 107 mess.setSenderInfo(userdao.getSenderInfo(mess.getSender())); 108 if (attachEnabled) { 109 mess.setAttachments(dao.getAttachmentsInfo(mess.getId())); 110 } 111 } else { 112 return (new ActionForward("/ShowForum.do?fid=" 113 + ptForm.getFid(), true)); 114 } 115 while (it.hasNext()) { 116 Message mess = (Message) it.next(); 117 mess.setSenderInfo(userdao.getSenderInfo(mess.getSender())); 118 if (attachEnabled) { 119 mess.setAttachments(dao.getAttachmentsInfo(mess.getId())); 120 } 121 } 122 123 request.setAttribute(IConst.REQUEST.RECORDS_DATA, recordsData); 124 request.setAttribute(IConst.REQUEST.CURR_THREAD, currThread); 125 if (dao.checkMod(fid, user)) { 126 request.setAttribute(IConst.REQUEST.MOD_FLAG, 127 IConst.VALUES.TRUE); 128 } 129 } catch (SQLException sqle) { 130 getServlet().log("Connection.process", sqle); 131 throw new SystemException(sqle); 132 } catch (InstantiationException e) { 133 throw new SystemException(e); 134 } catch (IllegalAccessException e) { 135 throw new SystemException(e); 136 } catch (InvocationTargetException e) { 137 throw new SystemException(e); 138 } catch (NoSuchMethodException e) { 139 throw new SystemException(e); 140 } 141 return (mapping.findForward("showThread")); 142 } 143 144 private void updateLastVisitTime(HashMap last_intime, String tid, Date now) { 146 if (last_intime.containsKey(tid)) { 147 last_intime.remove(tid); 148 } 149 last_intime.put(tid, now); 150 } 151 } | Popular Tags |