KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > webapp > admin > action > EditGroupAction


1 package org.nemesis.forum.webapp.admin.action;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletResponse JavaDoc;
5
6 import org.apache.commons.beanutils.PropertyUtils;
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.apache.struts.action.ActionError;
10 import org.apache.struts.action.ActionErrors;
11 import org.apache.struts.action.ActionForm;
12 import org.apache.struts.action.ActionForward;
13 import org.apache.struts.action.ActionMapping;
14 import org.nemesis.forum.ForumFactory;
15 import org.nemesis.forum.Group;
16 import org.nemesis.forum.ProfileManager;
17 import org.nemesis.forum.User;
18 import org.nemesis.forum.exception.UnauthorizedException;
19
20 public class EditGroupAction extends BaseAction {
21
22     static protected Log log = LogFactory.getLog(EditGroupAction.class);
23
24     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
25
26         //check logon
27
checkUser(request);
28         //check permission
29
checkPermission(request, OperationConstants.EDIT_GROUP);
30
31         ActionErrors errors = new ActionErrors();
32
33         //user need cancel
34
if (isCancelled(request)) {
35             return (mapping.findForward("cancel"));
36         }
37
38         try {
39
40             ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request));
41             ProfileManager manager = forumFactory.getProfileManager();
42             User user = manager.getUser(getAuthToken(request).getUserID());
43
44             //retrieve the group
45
Group group = manager.getGroup(Integer.parseInt(request.getParameter("id")));
46
47             //first, populate
48
if (request.getParameter("name") == null) {
49                 PropertyUtils.setSimpleProperty(form, "id", new Integer JavaDoc(group.getID()));
50                 PropertyUtils.setSimpleProperty(form, "name", group.getName());
51                 PropertyUtils.setSimpleProperty(form, "description", group.getDescription());
52                 return mapping.findForward("view");
53             }
54             //save
55
group.setName((String JavaDoc) PropertyUtils.getSimpleProperty(form, "name"));
56             group.setDescription((String JavaDoc) PropertyUtils.getSimpleProperty(form, "description"));
57
58         } catch (NumberFormatException JavaDoc aee) {
59             //errors.add("general", new ActionError("addGroup.alreadyExist"));
60
return mapping.findForward("success");
61         } catch (UnauthorizedException aee) {
62             errors.add("general", new ActionError("editGroup.unauthorized"));
63             return mapping.findForward("view");
64
65         } catch (Exception JavaDoc e) {
66             String JavaDoc eid = this.getClass().getName() + "_" + System.currentTimeMillis();
67             log.error("eid:" + eid + "\nsessionID" + request.getSession().getId(), e);
68             errors.add("general", new ActionError("error.general", "erreur id:" + eid));
69         }
70
71         if (!errors.isEmpty()) {
72             saveErrors(request, errors);
73             return mapping.findForward("view");
74         }
75
76         return mapping.findForward("success");
77     }
78
79 }
Popular Tags