KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > message > attachment > UpdateAttachmentInfoAction


1 /*
2  * $Id: UpdateAttachmentInfoAction.java,v 1.4 2005/06/07 12:32:28 bel70 Exp $
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitriy Belov <bel@jresearch.org>
23  * .
24  * * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 04.07.2004
27  *
28  */

29 package org.jresearch.gossip.actions.message.attachment;
30
31 import java.lang.reflect.InvocationTargetException JavaDoc;
32 import java.sql.SQLException JavaDoc;
33
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import javax.servlet.http.HttpSession JavaDoc;
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
53 /**
54  * @author Dmitry Belov
55  *
56  */

57 public class UpdateAttachmentInfoAction extends BaseAction {
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see org.jresearch.gossip.actions.BaseAction#process(org.apache.struts.action.ActionMapping,
63      * org.apache.struts.action.ActionForm,
64      * javax.servlet.http.HttpServletRequest,
65      * javax.servlet.http.HttpServletResponse)
66      */

67     protected ActionForward process(ActionMapping mapping, ActionForm form,
68             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
69             throws JGossipException {
70         HttpSession JavaDoc session = request.getSession();
71         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
72         ForumDAO dao = ForumDAO.getInstance();
73         AttachmentInfoForm aiForm = (AttachmentInfoForm) form;
74
75         try {
76             boolean isUserMod = dao.checkMod(Integer.parseInt(aiForm.getFid()),
77                     user);
78             Topic currThread = dao.getThreadInfo(Integer.parseInt(aiForm
79                     .getTid()));
80             Message mess = dao.getMessage(aiForm.getMid());
81             // check user access rights
82
getServlet().log("check user access rights ");
83             if (isUserMod
84                     || (user.getName().equals(mess.getSender()) && (currThread
85                             .getLocked() == IConst.Topic.STATUS_UNLOCKED))) {
86                 FileDataInfo fInfo = new FileDataInfo();
87                 BeanUtils.copyProperties(fInfo, aiForm);
88                 dao.updateAttachmentInfo(fInfo);
89             } else {
90                 return (mapping.findForward(IConst.TOKEN.DENIED));
91             }
92
93         } catch (NumberFormatException JavaDoc e) {
94             throw new SystemException(e);
95         } catch (SQLException JavaDoc e) {
96             throw new SystemException(e);
97         } catch (IllegalAccessException JavaDoc e) {
98             throw new SystemException(e);
99         } catch (InvocationTargetException JavaDoc e) {
100             throw new SystemException(e);
101         }
102         StringBuffer JavaDoc forward = new StringBuffer JavaDoc();
103         forward.append("/ShowMessage.do?fid=");
104         forward.append(aiForm.getFid());
105         forward.append("&tid=");
106         forward.append(aiForm.getTid());
107         forward.append("&mid=");
108         forward.append(aiForm.getMid());
109         return (new ActionForward(forward.toString(), true));
110
111     }
112
113 }
Popular Tags