KickJava   Java API By Example, From Geeks To Geeks.

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


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