KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > action > content > DeleteSectionAction


1 package org.nextime.ion.backoffice.action.content;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8 import org.apache.struts.action.ActionForm;
9 import org.apache.struts.action.ActionForward;
10 import org.apache.struts.action.ActionMapping;
11 import org.nextime.ion.backoffice.action.BaseAction;
12 import org.nextime.ion.backoffice.tree.TreeControl;
13 import org.nextime.ion.backoffice.tree.TreeControlNode;
14 import org.nextime.ion.backoffice.exception.BackofficeSecurityException;
15 import org.nextime.ion.backoffice.security.SecurityManagerImpl;
16
17 import org.nextime.ion.framework.business.Section;
18 import org.nextime.ion.framework.business.User;
19 import org.nextime.ion.framework.mapping.Mapping;
20
21 public class DeleteSectionAction extends BaseAction {
22
23     public ActionForward perform(
24         ActionMapping mapping,
25         ActionForm form,
26         HttpServletRequest JavaDoc request,
27         HttpServletResponse JavaDoc response)
28         throws IOException JavaDoc, ServletException JavaDoc {
29
30         // check if user is correctly logged
31
checkUser(request);
32
33         // check if this action is allowed
34
try {
35             Mapping.begin();
36             if (!new SecurityManagerImpl().canDeleteSection(Section.getInstance(request.getParameter("id").toString()), User.getInstance(request.getSession().getAttribute("userLogin")+""))) {
37                 throw new Exception JavaDoc();
38             }
39         } catch (Exception JavaDoc e) {
40             throw new BackofficeSecurityException();
41         } finally {
42             Mapping.rollback();
43         }
44
45         // retrieve selected section
46
TreeControl tree =
47             (TreeControl) request.getSession().getAttribute("treeControlTest");
48         String JavaDoc selectedId = request.getParameter("id");
49         TreeControlNode node = tree.findNode(selectedId);
50
51         try {
52             Mapping.begin();
53
54             Section section = Section.getInstance(selectedId);
55             section.remove();
56             // update tree
57
try {
58                 TreeControlNode parent = node.getParent();
59                 node.remove();
60                 if (parent != null) {
61                     parent.rebuildLastChildren();
62                 }
63             } catch (Exception JavaDoc e) {
64             }
65
66             Mapping.commit();
67         } catch (Exception JavaDoc e) {
68             Mapping.rollback();
69             throw new ServletException JavaDoc(e);
70         }
71
72         // Forward to the next page
73
return (mapping.findForward("ok"));
74
75     }
76
77 }
78
Popular Tags