KickJava   Java API By Example, From Geeks To Geeks.

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


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 MoveSectionAction 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().canCreateSection(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         // get section
46
try {
47             Mapping.begin();
48             
49             Section section = Section.getInstance(request.getParameter("id"));
50             TreeControlNode node = ((TreeControl)(request.getSession().getAttribute("treeControlTest"))).findNode(request.getParameter("id"));
51             // up or down ?
52
if( request.getParameter("type").equals("up") ) {
53                 section.up();
54                 node.up();
55             } else {
56                 section.down();
57                 node.down();
58             }
59             
60             Mapping.commit();
61         } catch (Exception JavaDoc e) {
62             Mapping.rollback();
63             throw new ServletException JavaDoc(e);
64         }
65
66         // Forward to the next page
67
return (mapping.findForward("ok"));
68
69     }
70
71 }
72
Popular Tags