1 package org.nextime.ion.backoffice.action.content; 2 3 import java.io.IOException ; 4 import java.util.Enumeration ; 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 import org.apache.struts.action.ActionErrors; 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionForward; 11 import org.apache.struts.action.ActionMapping; 12 import org.nextime.ion.backoffice.action.BaseAction; 13 import org.nextime.ion.backoffice.bean.SectionTypes; 14 import org.nextime.ion.backoffice.form.EditSectionForm; 15 import org.nextime.ion.backoffice.tree.TreeControl; 16 import org.nextime.ion.backoffice.tree.TreeControlNode; 17 import org.nextime.ion.backoffice.exception.BackofficeSecurityException; 18 import org.nextime.ion.backoffice.security.SecurityManagerImpl; 19 20 import org.nextime.ion.framework.business.Section; 21 import org.nextime.ion.framework.business.User; 22 import org.nextime.ion.framework.locale.Locale; 23 import org.nextime.ion.framework.locale.LocaleList; 24 import org.nextime.ion.framework.mapping.Mapping; 25 import org.nextime.ion.framework.workflow.Workflow; 26 27 public class EditSectionAction extends BaseAction { 28 29 public ActionForward perform( 30 ActionMapping mapping, 31 ActionForm form, 32 HttpServletRequest request, 33 HttpServletResponse response) 34 throws IOException , ServletException { 35 36 checkUser(request); 38 39 request.setAttribute("locales", LocaleList.getInstance().getLocales()); 41 42 String id = 44 (request.getAttribute("id") != null) 45 ? request.getAttribute("id").toString() 46 : request.getParameter("id").toString(); 47 48 if (request.getParameter("cancel") != null) { 50 try { 52 Mapping.begin(); 53 Section section = Section.getInstance(id); 54 if (section.getMetaData("name") == null) { 55 section.remove(); 56 } 57 TreeControl tree = 59 (TreeControl) request.getSession().getAttribute( 60 "treeControlTest"); 61 TreeControlNode node = tree.findNode(id); 62 node.remove(); 63 Mapping.commit(); 64 } catch (Exception e) { 65 e.printStackTrace(); 66 Mapping.rollback(); 67 } 68 return (mapping.findForward("cancel")); 70 } 71 72 try { 74 Mapping.begin(); 75 if (!new SecurityManagerImpl() 76 .canEditSection( 77 Section.getInstance(id), 78 User.getInstance( 79 request.getSession().getAttribute("userLogin") 80 + ""))) { 81 throw new Exception (); 82 } 83 } catch (Exception e) { 84 throw new BackofficeSecurityException(); 85 } finally { 86 Mapping.rollback(); 87 } 88 89 EditSectionForm sform = (EditSectionForm) form; 91 ActionErrors errors = sform.myValidate(request); 92 93 if (sform.getStatus() == null) { 95 try { 96 Mapping.begin(); 97 Section section = Section.getInstance(id); 98 Mapping.rollback(); 99 100 request.setAttribute("section", section); 101 102 Enumeration keys = section.getMetaData().keys(); 104 while (keys.hasMoreElements()) { 105 String key = keys.nextElement() + ""; 106 if (key.startsWith("name_")) { 107 request.setAttribute(key, section.getMetaData(key)); 108 } 109 } 110 111 sform.setTemplate(section.getMetaData("template") + ""); 112 sform.setStatus(section.getMetaData("status") + ""); 113 sform.setWorkflow(section.getMetaData("workflow") + ""); 114 request.setAttribute( 115 "types", 116 SectionTypes.getSectionsBeans(servlet, request)); 117 request.setAttribute( 118 "type", 119 SectionTypes.getSectionBean( 120 servlet, 121 section.getMetaData("template") + "", 122 request)); 123 request.setAttribute("workflows", Workflow.listTypes()); 124 } catch (Exception e) { 125 Mapping.rollback(); 126 throw new ServletException (e); 127 } 128 129 return (mapping.findForward("view")); 131 } 132 133 if (request.getParameter("ok") == null) { 135 try { 136 Mapping.begin(); 137 Section section = Section.getInstance(id); 138 Mapping.rollback(); 139 140 Enumeration keys = section.getMetaData().keys(); 142 while (keys.hasMoreElements()) { 143 String key = keys.nextElement() + ""; 144 if (key.startsWith("name_")) { 145 request.setAttribute(key, request.getParameter(key)); 146 } 147 } 148 keys = request.getParameterNames(); 149 while (keys.hasMoreElements()) { 150 String key = keys.nextElement() + ""; 151 if (key.startsWith("name_")) { 152 request.setAttribute(key, request.getParameter(key)); 153 } 154 } 155 156 request.setAttribute("section", section); 157 request.setAttribute( 158 "types", 159 SectionTypes.getSectionsBeans(servlet, request)); 160 request.setAttribute( 161 "type", 162 SectionTypes.getSectionBean(servlet, sform.getTemplate(), request)); 163 request.setAttribute("workflows", Workflow.listTypes()); 164 request.setAttribute(ERROR_KEY, errors); 165 } catch (Exception e) { 166 Mapping.rollback(); 167 throw new ServletException (e); 168 } 169 170 return (mapping.findForward("view")); 172 } 173 174 if (errors.size() > 0) { 176 try { 177 Mapping.begin(); 178 Section section = Section.getInstance(id); 179 Mapping.rollback(); 180 181 Enumeration keys = section.getMetaData().keys(); 183 while (keys.hasMoreElements()) { 184 String key = keys.nextElement() + ""; 185 if (key.startsWith("name_")) { 186 request.setAttribute(key, request.getParameter(key)); 187 } 188 } 189 keys = request.getParameterNames(); 190 while (keys.hasMoreElements()) { 191 String key = keys.nextElement() + ""; 192 if (key.startsWith("name_")) { 193 request.setAttribute(key, request.getParameter(key)); 194 } 195 } 196 197 request.setAttribute("section", section); 198 request.setAttribute( 199 "types", 200 SectionTypes.getSectionsBeans(servlet, request)); 201 request.setAttribute( 202 "type", 203 SectionTypes.getSectionBean(servlet, sform.getTemplate(), request)); 204 request.setAttribute(ERROR_KEY, errors); 205 request.setAttribute("workflows", Workflow.listTypes()); 206 Enumeration names = request.getParameterNames(); 208 request.setAttribute("copyMeta", "true"); 209 while (names.hasMoreElements()) { 210 String name = names.nextElement() + ""; 211 if (name.startsWith("META_")) { 212 request.setAttribute(name, request.getParameter(name)); 213 } 214 } 215 } catch (Exception e) { 216 Mapping.rollback(); 217 throw new ServletException (e); 218 } 219 220 return (mapping.findForward("view")); 222 } 223 224 try { 226 Mapping.begin(); 227 228 Section section = Section.getInstance(id); 229 230 Enumeration keys = request.getParameterNames(); 232 while (keys.hasMoreElements()) { 233 String key = keys.nextElement() + ""; 234 if (key.startsWith("name_")) { 235 section.setMetaData(key, request.getParameter(key)); 236 } 237 } 238 String sDl = 240 ((Locale) LocaleList 241 .getInstance() 242 .getLocales() 243 .iterator() 244 .next()) 245 .getLocale(); 246 section.setMetaData("name", section.getMetaData("name_" + sDl)); 247 248 section.setMetaData("template", sform.getTemplate()); 249 section.setMetaData("status", sform.getStatus()); 250 section.setMetaData("workflow", sform.getWorkflow()); 251 Enumeration names = request.getParameterNames(); 253 while (names.hasMoreElements()) { 254 String name = names.nextElement() + ""; 255 if (name.startsWith("META_")) { 256 section.setMetaData( 257 name.substring(5), 258 request.getParameter(name)); 259 } 260 } 261 TreeControlNode node = 263 ( 264 (TreeControl) request.getSession().getAttribute( 265 "treeControlTest")).findNode( 266 request.getParameter("id")); 267 node.setLabel(section.getMetaData("name") + ""); 268 String img = "section.gif"; 269 if ("offline".equals(section.getMetaData("status"))) { 270 img = "section-offline.gif"; 271 } 272 node.setIcon(img); 273 274 Mapping.commit(); 275 } catch (Exception e) { 276 Mapping.rollback(); 277 throw new ServletException (e); 278 } 279 280 return (mapping.findForward("ok")); 282 } 283 284 } 285 | Popular Tags |