KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > admin > action > publi > AddPubliAction


1 package org.nextime.ion.admin.action.publi;
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.Action;
9 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionForward;
11 import org.apache.struts.action.ActionMapping;
12
13 import org.nextime.ion.admin.form.*;
14 import org.nextime.ion.framework.business.*;
15 import org.nextime.ion.framework.helper.*;
16 import org.nextime.ion.framework.business.User;
17 import org.nextime.ion.framework.mapping.Mapping;
18 import org.nextime.ion.framework.workflow.Workflow;
19
20 public class AddPubliAction extends Action {
21
22     public ActionForward perform(
23         ActionMapping mapping,
24         ActionForm form,
25         HttpServletRequest JavaDoc request,
26         HttpServletResponse JavaDoc response)
27         throws IOException JavaDoc, ServletException JavaDoc {
28
29         // pour situer la vue
30
request.setAttribute("view", "publi");
31
32         String JavaDoc id = "";
33
34         try {
35
36             // pour remplir les listes select
37
Mapping.begin();
38             request.setAttribute("sectionList", Section.listAll());
39             request.setAttribute("categoryList", Category.listAll());
40             request.setAttribute("workflowList", Workflow.listTypes());
41             request.setAttribute("userList", User.listAll());
42             request.setAttribute("typeList", TypePublication.listAll());
43             Mapping.rollback();
44
45             // si on a pas soumis le formulaire
46
if (request.getParameter("addSubmit") == null) {
47                 //request.setAttribute( "pid", IdGenerator.nextPublicationId());
48
return new ActionForward( mapping.getInput() );
49             }
50
51             // creation de l'objet
52
PubliForm f = (PubliForm) form;
53             Mapping.begin();
54             id = f.getId();
55             Publication p = Publication.create(User.getInstance(f.getAuthor()), f.getId(), TypePublication.getInstance(f.getType()), f.getWorkflow());
56             
57             String JavaDoc[] g = f.getSections();
58             if (g != null) {
59                 for (int i = 0; i < g.length; i++) {
60                     p.addSection(Section.getInstance(g[i]));
61                 }
62             }
63             g = f.getCategories();
64             if (g != null) {
65                 for (int i = 0; i < g.length; i++) {
66                     p.addCategory(Category.getInstance(g[i]));
67                 }
68             }
69             Mapping.commit();
70
71         } catch (Exception JavaDoc e) {
72             Mapping.rollback();
73             request.setAttribute("error", e.getMessage());
74             return new ActionForward( mapping.getInput() );
75         }
76         
77         // on va passer l'id en request pour aller directement à
78
// la page d'edition
79
request.setAttribute("id", id);
80         
81         return mapping.findForward("success");
82     }
83
84 }
Popular Tags