1 package org.nextime.ion.admin.action.section; 2 3 import java.io.IOException ; 4 import java.util.Enumeration ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 import org.apache.struts.action.Action; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionForward; 12 import org.apache.struts.action.ActionMapping; 13 14 import org.nextime.ion.admin.form.*; 15 import org.nextime.ion.framework.business.Group; 16 import org.nextime.ion.framework.business.*; 17 import org.nextime.ion.framework.business.impl.*; 18 import org.nextime.ion.framework.mapping.Mapping; 19 20 public class EditSectionAction 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", "section"); 31 32 if( request.getParameter("id") != null ) 33 request.setAttribute("id", request.getParameter("id")); 34 String id = request.getAttribute("id")+""; 35 36 try { 37 38 Mapping.begin(); 40 request.setAttribute("sectionList", Section.listAll()); 41 Mapping.commit(); 42 43 if (request.getParameter("editSubmit") == null) { 44 Mapping.begin(); 45 46 Section u = Section.getInstance(id); 48 SectionForm f = (SectionForm) form; 49 f.setId(u.getId()); 50 f.setParent(u.getParent().getId()); 51 request.setAttribute("metaData", ((SectionImpl) u).getMetaData()); 52 53 Mapping.commit(); 54 return new ActionForward( mapping.getInput() ); 55 } 56 57 Mapping.begin(); 59 SectionForm f = (SectionForm) form; 60 Section u = Section.getInstance(id); 61 Section parent = null; 62 if( !f.getParent().equals("_NULL_") ) { 63 parent = Section.getInstance(f.getParent()); 64 } 65 if( parent != u.getParent() ) { 66 u.changeParent(parent); 67 } 68 69 79 Enumeration ps = request.getParameterNames(); 81 while (ps.hasMoreElements()) { 82 String name = ps.nextElement() + ""; 83 if (name.startsWith("META_")) { 84 name = name.substring(5); 85 u.setMetaData(name, request.getParameter("META_" + name)); 86 } 87 } 88 String mtd = request.getParameter("metaToDelete"); 90 if ((mtd + "").trim().equals("")) 91 mtd = null; 92 if (mtd != null) { 93 u.removeMetaData(mtd); 94 request.setAttribute("metaData", ((SectionImpl) u).getMetaData()); 95 } 96 String mtd2 = request.getParameter("newMETA"); 98 if ((mtd2 + "").trim().equals("")) 99 mtd2 = null; 100 if (mtd2 != null) { 101 u.setMetaData(mtd2, ""); 102 request.setAttribute("metaData", ((SectionImpl) u).getMetaData()); 103 } 104 Mapping.commit(); 105 106 if (mtd != null || mtd2 != null) { 108 return new ActionForward( mapping.getInput() ); 109 } 110 111 113 } catch (Exception e) { 114 Mapping.rollback(); 115 request.setAttribute("error", e.getMessage()); 116 return new ActionForward( mapping.getInput() ); 117 } 118 119 return mapping.findForward("success"); 120 } 121 122 } | Popular Tags |