1 package org.nextime.ion.backoffice.action.content; 2 3 import java.io.IOException ; 4 import java.util.Vector ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 10 import org.apache.struts.action.ActionErrors; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.nextime.ion.backoffice.action.BaseAction; 15 import org.nextime.ion.backoffice.bean.SectionTypes; 16 import org.nextime.ion.backoffice.bean.TypeBean; 17 import org.nextime.ion.backoffice.exception.BackofficeSecurityException; 18 import org.nextime.ion.backoffice.form.CreatePublicationForm; 19 import org.nextime.ion.backoffice.security.SecurityManagerImpl; 20 import org.nextime.ion.commons.PublicationSorter; 21 import org.nextime.ion.framework.business.Publication; 22 import org.nextime.ion.framework.business.Section; 23 import org.nextime.ion.framework.business.TypePublication; 24 import org.nextime.ion.framework.business.User; 25 import org.nextime.ion.framework.helper.IdGenerator; 26 import org.nextime.ion.framework.mapping.Mapping; 27 import org.nextime.ion.framework.workflow.Workflow; 28 29 public class CreatePublicationAction extends BaseAction { 30 31 public ActionForward perform( 32 ActionMapping mapping, 33 ActionForm form, 34 HttpServletRequest request, 35 HttpServletResponse response) 36 throws IOException , ServletException { 37 38 checkUser(request); 40 41 try { 43 Mapping.begin(); 44 if (!new SecurityManagerImpl() 45 .canCreatePublication( 46 Section.getInstance(request.getParameter("id").toString()), 47 User.getInstance( 48 request.getSession().getAttribute("userLogin") 49 + ""))) { 50 throw new Exception (); 51 } 52 } catch (Exception e) { 53 throw new BackofficeSecurityException(); 54 } finally { 55 Mapping.rollback(); 56 } 57 58 CreatePublicationForm sform = (CreatePublicationForm) form; 60 ActionErrors errors = sform.myValidate(request); 61 62 if (request.getParameter("cancel") != null) { 64 return (mapping.findForward("cancel")); 66 } 67 68 String id = request.getParameter("id").toString(); 70 71 if (sform.getName() == null) { 73 try { 74 Mapping.begin(); 75 76 Section section = Section.getInstance(id); 77 String template = section.getMetaData("template") + ""; 78 TypeBean type = SectionTypes.getSectionBean(servlet, template, request); 79 80 Vector types = new Vector (); 81 for (int t = 0; t < type.getPublicationTypes().size(); t++) { 82 try { 83 types.add( 84 TypePublication.getInstance( 85 type.getPublicationTypes().get(t) + "")); 86 } catch (Exception e) { 87 e.printStackTrace(); 88 } 89 } 90 91 request.setAttribute("types", types); 92 request.setAttribute("workflows", Workflow.listTypes()); 93 94 Mapping.rollback(); 95 } catch (Exception e) { 96 Mapping.rollback(); 97 throw new ServletException (e); 98 } 99 100 return (mapping.findForward("view")); 102 } 103 104 if (errors.size() > 0) { 106 try { 107 Mapping.begin(); 108 109 Section section = Section.getInstance(id); 110 String template = section.getMetaData("template") + ""; 111 TypeBean type = SectionTypes.getSectionBean(servlet, template, request); 112 113 Vector types = new Vector (); 114 for (int t = 0; t < type.getPublicationTypes().size(); t++) { 115 try { 116 types.add( 117 TypePublication.getInstance( 118 type.getPublicationTypes().get(t) + "")); 119 } catch (Exception e) { 120 e.printStackTrace(); 121 } 122 } 123 124 request.setAttribute("types", types); 125 126 request.setAttribute(ERROR_KEY, errors); 127 128 Mapping.rollback(); 129 } catch (Exception e) { 130 Mapping.rollback(); 131 throw new ServletException (e); 132 } 133 134 return (mapping.findForward("view")); 136 } 137 138 try { 140 Mapping.begin(); 141 142 Section section = Section.getInstance(id); 143 String newId = IdGenerator.nextPublicationId(); 144 TypePublication type = TypePublication.getInstance(sform.getType()); 145 Publication publi = 146 Publication.create( 147 User.getInstance( 148 request.getSession().getAttribute("userLogin") + ""), 149 newId, 150 type, 151 section.getMetaData("workflow") + ""); 152 section.addPublication(publi); 153 publi.setMetaData("name", sform.getName()); 154 PublicationSorter.initPublication(publi, section); 155 request.setAttribute("id", newId); 156 request.setAttribute( 157 "version", 158 publi.getLastVersion().getVersion() + ""); 159 160 Mapping.commit(); 161 } catch (Exception e) { 162 Mapping.rollback(); 163 throw new ServletException (e); 164 } 165 166 return (mapping.findForward("ok")); 168 } 169 170 } 171 | Popular Tags |