1 package org.nextime.ion.backoffice.action.content; 2 3 import java.io.IOException ; 4 import java.text.SimpleDateFormat ; 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 import org.apache.struts.action.ActionErrors; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionForward; 12 import org.apache.struts.action.ActionMapping; 13 import org.nextime.ion.backoffice.action.BaseAction; 14 import org.nextime.ion.backoffice.form.EditPublicationForm; 15 import org.nextime.ion.backoffice.exception.BackofficeSecurityException; 16 import org.nextime.ion.backoffice.security.SecurityManagerImpl; 17 18 import org.nextime.ion.framework.business.Publication; 19 import org.nextime.ion.framework.business.User; 20 import org.nextime.ion.framework.locale.LocaleList; 21 import org.nextime.ion.framework.mapping.Mapping; 22 23 public class EditPublicationAction extends BaseAction { 24 25 public ActionForward perform( 26 ActionMapping mapping, 27 ActionForm form, 28 HttpServletRequest request, 29 HttpServletResponse response) 30 throws IOException , ServletException { 31 32 checkUser(request); 34 35 EditPublicationForm sform = (EditPublicationForm) form; 37 ActionErrors errors = sform.myValidate(request); 38 39 request.setAttribute("locales", LocaleList.getInstance().getLocales() ); 41 request.setAttribute("defaultLocale", LocaleList.getInstance().getLocales().iterator().next() ); 42 43 String id = 45 (request.getAttribute("id") != null) 46 ? request.getAttribute("id").toString() 47 : request.getParameter("id").toString(); 48 49 int version = 51 Integer.parseInt( 52 (request.getAttribute("version") != null) 53 ? request.getAttribute("version").toString() 54 : request.getParameter("version").toString()); 55 request.setAttribute("version", version + ""); 56 57 try { 59 Mapping.begin(); 60 if (!new SecurityManagerImpl() 61 .canEditPublication( 62 Publication.getInstance(id), 63 version, 64 User.getInstance( 65 request.getSession().getAttribute("userLogin") 66 + ""))) { 67 throw new Exception (); 68 } 69 } catch (Exception e) { 70 throw new BackofficeSecurityException(); 71 } finally { 72 Mapping.rollback(); 73 } 74 75 if (request.getParameter("cancel") != null) { 77 return (mapping.findForward("cancel")); 79 } 80 81 if (request.getParameter("itsOk") == null) { 83 try { 84 Mapping.begin(); 85 Publication publication = Publication.getInstance(id); 86 Mapping.rollback(); 87 88 request.setAttribute("publication", publication); 89 90 SimpleDateFormat formatter = new SimpleDateFormat ("dd/MM/yyyy"); 91 sform.setDate(formatter.format(publication.getDate())); 92 sform.setData( 93 publication.getVersion(version).getDataAsString()); 94 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 Publication publication = Publication.getInstance(id); 109 request.setAttribute("publication", publication); 110 request.setAttribute(ERROR_KEY, errors); 111 Mapping.rollback(); 112 } catch (Exception e) { 113 Mapping.rollback(); 114 throw new ServletException (e); 115 } 116 117 return (mapping.findForward("view")); 119 } 120 121 try { 123 Mapping.begin(); 124 Publication publication = Publication.getInstance(id); 125 publication.getVersion(version).setDataAsString(sform.getData()); 126 Mapping.commit(); 127 } catch (Exception e) { 128 Mapping.rollback(); 129 throw new ServletException (e); 130 } 131 132 return (mapping.findForward("ok")); 134 } 135 136 } 137 | Popular Tags |