1 20 package org.enhydra.barracuda.core.helper.state; 21 22 import java.util.*; 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 26 import org.enhydra.barracuda.core.helper.servlet.*; 27 import org.enhydra.barracuda.plankton.data.*; 28 import org.enhydra.barracuda.core.util.http.*; 29 30 39 public class ParamPersister { 40 41 static final String PARAM_LIST = "ParamPersister.PARAM_LIST"; 42 43 49 public static void persistReqParamState(HttpServletRequest req) { 50 if (req==null) return; 52 53 HttpSession session = null; 56 List paramList = null; 57 58 Enumeration enum = req.getParameterNames(); 60 while (enum.hasMoreElements()) { 61 if (session==null) { 63 session = SessionServices.getSession(req); 64 paramList = new ArrayList(); 65 session.setAttribute(PARAM_LIST, paramList); 66 } 67 68 String key = (String) enum.nextElement(); 71 String[] values = req.getParameterValues(key); 72 for (int i=0, max=values.length; i<max; i++) { 73 paramList.add(new Param(key, values[i])); 74 } 75 } 76 } 77 78 83 public static void reconstituteReqParamState(BarracudaServletRequestWrapper req) { 84 if (req==null) return; 86 87 HttpSession session = SessionServices.getSession(req, false); 89 if (session==null) return; 90 91 List paramList = (List) session.getAttribute(PARAM_LIST); 93 if (paramList!=null) { 94 Iterator it = paramList.iterator(); 96 while (it.hasNext()) { 97 Param p = (Param) it.next(); 98 req.addParameter(p.getKey(), p.getValue()); 99 } 100 101 session.removeAttribute(PARAM_LIST); 103 } 104 } 105 } 106 | Popular Tags |