1 25 29 package org.jresearch.gossip.actions.message.attachment; 30 31 import java.lang.reflect.InvocationTargetException ; 32 import java.sql.SQLException ; 33 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 36 import javax.servlet.http.HttpSession ; 37 38 import org.apache.commons.beanutils.BeanUtils; 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.Message; 45 import org.jresearch.gossip.beans.forum.Topic; 46 import org.jresearch.gossip.beans.forum.attachment.FileDataInfo; 47 import org.jresearch.gossip.beans.user.User; 48 import org.jresearch.gossip.dao.ForumDAO; 49 import org.jresearch.gossip.exception.JGossipException; 50 import org.jresearch.gossip.exception.SystemException; 51 import org.jresearch.gossip.forms.AttachmentInfoForm; 52 import org.jresearch.gossip.forms.ProcessAttachForm; 53 54 58 public class EditAttachmentInfoAction extends BaseAction { 59 60 68 protected ActionForward process(ActionMapping mapping, ActionForm form, 69 HttpServletRequest request, HttpServletResponse response) 70 throws JGossipException { 71 HttpSession session = request.getSession(); 72 User user = (User) session.getAttribute(IConst.SESSION.USER_KEY); 73 ForumDAO dao = ForumDAO.getInstance(); 74 ProcessAttachForm paForm = (ProcessAttachForm) form; 75 76 try { 77 boolean isUserMod = dao.checkMod(Integer.parseInt(paForm.getFid()), 78 user); 79 Topic currThread = dao.getThreadInfo(Integer.parseInt(paForm 80 .getTid())); 81 Message mess = dao.getMessage(paForm.getMid()); 82 getServlet().log("check user access rights "); 84 if (isUserMod 85 || (user.getName().equals(mess.getSender()) && (currThread 86 .getLocked() == IConst.Topic.STATUS_UNLOCKED))) { 87 if (request.getAttribute("attachmentInfoForm") != null) { 88 return mapping.findForward(IConst.TOKEN.PAGE); 89 } 90 FileDataInfo fInfo = dao.getAttachmentInfo(Integer 91 .parseInt(paForm.getId())); 92 if (fInfo == null) { 93 StringBuffer forward = new StringBuffer (); 94 forward.append("/ShowMessage.do?fid="); 95 forward.append(paForm.getFid()); 96 forward.append("&tid="); 97 forward.append(paForm.getTid()); 98 forward.append("&mid="); 99 forward.append(paForm.getMid()); 100 return (new ActionForward(forward.toString(), true)); 101 } 102 103 AttachmentInfoForm aiForm = new AttachmentInfoForm(); 104 BeanUtils.copyProperties(aiForm, paForm); 105 BeanUtils.copyProperties(aiForm, fInfo); 106 request.setAttribute("attachmentInfoForm", aiForm); 107 } else { 108 return (mapping.findForward(IConst.TOKEN.DENIED)); 109 } 110 111 } catch (NumberFormatException e) { 112 throw new SystemException(e); 113 } catch (SQLException e) { 114 throw new SystemException(e); 115 } catch (IllegalAccessException e) { 116 throw new SystemException(e); 117 } catch (InvocationTargetException e) { 118 throw new SystemException(e); 119 } 120 return mapping.findForward(IConst.TOKEN.PAGE); 121 122 } 123 124 } | Popular Tags |