KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: EditAttachmentInfoAction.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 import org.jresearch.gossip.forms.ProcessAttachForm;
53
54 /**
55  * @author Dmitry Belov
56  *
57  */

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

68     protected ActionForward process(ActionMapping mapping, ActionForm form,
69             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
70             throws JGossipException {
71         HttpSession JavaDoc 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             // check user access rights
83
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 JavaDoc forward = new StringBuffer JavaDoc();
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 JavaDoc e) {
112             throw new SystemException(e);
113         } catch (SQLException JavaDoc e) {
114             throw new SystemException(e);
115         } catch (IllegalAccessException JavaDoc e) {
116             throw new SystemException(e);
117         } catch (InvocationTargetException JavaDoc e) {
118             throw new SystemException(e);
119         }
120         return mapping.findForward(IConst.TOKEN.PAGE);
121
122     }
123
124 }
Popular Tags