1 package org.nextime.ion.admin.action.category; 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.*; 16 import org.nextime.ion.framework.business.User; 17 import org.nextime.ion.framework.business.impl.*; 18 import org.nextime.ion.framework.mapping.Mapping; 19 20 public class EditCategoryAction 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", "category"); 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 if (request.getParameter("editSubmit") == null) { 39 Mapping.begin(); 40 41 Category u = Category.getInstance(id); 43 CategoryForm f = (CategoryForm) form; 44 f.setId(u.getId()); 45 request.setAttribute("metaData", ((CategoryImpl) u).getMetaData()); 46 47 Mapping.commit(); 48 return new ActionForward( mapping.getInput() ); 49 } 50 51 Mapping.begin(); 53 CategoryForm f = (CategoryForm) form; 54 Category u = Category.getInstance(id); 55 56 57 67 Enumeration ps = request.getParameterNames(); 69 while (ps.hasMoreElements()) { 70 String name = ps.nextElement() + ""; 71 if (name.startsWith("META_")) { 72 name = name.substring(5); 73 u.setMetaData(name, request.getParameter("META_" + name)); 74 } 75 } 76 String mtd = request.getParameter("metaToDelete"); 78 if ((mtd + "").trim().equals("")) 79 mtd = null; 80 if (mtd != null) { 81 u.removeMetaData(mtd); 82 request.setAttribute("metaData", ((CategoryImpl) u).getMetaData()); 83 } 84 String mtd2 = request.getParameter("newMETA"); 86 if ((mtd2 + "").trim().equals("")) 87 mtd2 = null; 88 if (mtd2 != null) { 89 u.setMetaData(mtd2, ""); 90 request.setAttribute("metaData", ((CategoryImpl) u).getMetaData()); 91 } 92 Mapping.commit(); 93 94 if (mtd != null || mtd2 != null) { 96 return new ActionForward( mapping.getInput() ); 97 } 98 99 101 } catch (Exception e) { 102 Mapping.rollback(); 103 request.setAttribute("error", e.getMessage()); 104 return new ActionForward( mapping.getInput() ); 105 } 106 107 return mapping.findForward("success"); 108 } 109 110 } | Popular Tags |