KickJava   Java API By Example, From Geeks To Geeks.

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


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.commons.PublicationSorter;
13 import org.nextime.ion.backoffice.exception.BackofficeSecurityException;
14 import org.nextime.ion.backoffice.security.SecurityManagerImpl;
15
16 import org.nextime.ion.framework.business.Publication;
17 import org.nextime.ion.framework.business.User;
18 import org.nextime.ion.framework.business.Section;
19 import org.nextime.ion.framework.mapping.Mapping;
20
21 public class DeletePublicationAction 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         // retrieve selected publication
34
String JavaDoc selectedId = request.getParameter("id");
35         
36         // check if this action is allowed
37
try {
38             Mapping.begin();
39             if (!new SecurityManagerImpl().canDeletePublication(Publication.getInstance(selectedId), User.getInstance(request.getSession().getAttribute("userLogin")+""))) {
40                 throw new Exception JavaDoc();
41             }
42         } catch (Exception JavaDoc e) {
43             throw new BackofficeSecurityException();
44         } finally {
45             Mapping.rollback();
46         }
47
48         try {
49             Mapping.begin();
50
51             Publication publication = Publication.getInstance(selectedId);
52             Section section = Section.getInstance(request.getParameter("sectionId"));
53             PublicationSorter.removePublication(publication,section);
54             publication.remove();
55
56             Mapping.commit();
57         } catch (Exception JavaDoc e) {
58             Mapping.rollback();
59             throw new ServletException JavaDoc(e);
60         }
61
62         // Forward to the next page
63
return (mapping.findForward("ok"));
64
65     }
66
67 }
68
Popular Tags