1 package org.nextime.ion.admin.action.publi; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 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 request, 26 HttpServletResponse response) 27 throws IOException , ServletException { 28 29 request.setAttribute("view", "publi"); 31 32 String id = ""; 33 34 try { 35 36 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 if (request.getParameter("addSubmit") == null) { 47 return new ActionForward( mapping.getInput() ); 49 } 50 51 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 [] 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 e) { 72 Mapping.rollback(); 73 request.setAttribute("error", e.getMessage()); 74 return new ActionForward( mapping.getInput() ); 75 } 76 77 request.setAttribute("id", id); 80 81 return mapping.findForward("success"); 82 } 83 84 } | Popular Tags |