package pt.ist.renderers.plugin.upload; import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; /** * Renderers wrapper round the request. This wrapper allows all elements * of the framework to use {@link javax.servlet.ServletRequest#getParameter(java.lang.String)} * and the like regardlessly of the request nature. * * @author cfgi */ public class RenderersRequestWrapper extends HttpServletRequestWrapper { private Hashtable> parameters; public RenderersRequestWrapper(HttpServletRequest request) { super(request); this.parameters = new Hashtable>(); } public void addParameter(String name, String value) { ensureParameterPresent(name); addParameterValue(name, value); } private void ensureParameterPresent(String name) { if (! parameterExists(name)) { this.parameters.put(name, new ArrayList()); } } private boolean parameterExists(String name) { return this.parameters.containsKey(name); } private void addParameterValue(String name, String value) { this.parameters.get(name).add(value); } @Override public String getParameter(String name) { if (! parameterExists(name)) { return null; } return this.parameters.get(name).get(0); } @Override public Map getParameterMap() { Map resultMap = new Hashtable(); for (String parameter : this.parameters.keySet()) { resultMap.put(parameter, parameters.get(parameter).toArray(new String[0])); } return resultMap; } @Override public Enumeration getParameterNames() { return this.parameters.keys(); } @Override public String[] getParameterValues(String name) { return getParameterMap().get(name); } }