01: ///////////////////////////////
02: // Makumba, Makumba tag library
03: // Copyright (C) 2000-2003 http://www.makumba.org
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU Lesser General Public
07: // License as published by the Free Software Foundation; either
08: // version 2.1 of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: // Lesser General Public License for more details.
14: //
15: // You should have received a copy of the GNU Lesser General Public
16: // License along with this library; if not, write to the Free Software
17: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: //
19: // -------------
20: // $Id: HttpParameters.java 1402 2007-07-25 11:52:28Z manuel_gay $
21: // $Name$
22: /////////////////////////////////////
23:
24: package org.makumba.commons.attributes;
25:
26: import java.util.Enumeration;
27: import java.util.Hashtable;
28: import java.util.Vector;
29:
30: import javax.servlet.http.HttpServletRequest;
31:
32: /**
33: * Helper class to work with http parameters
34: *
35: * @author Cristian Bogdan
36: * @version $Id: HttpParameters.java 1402 2007-07-25 11:52:28Z manuel_gay $
37: */
38: public class HttpParameters {
39: HttpServletRequest request;
40:
41: Hashtable<Object, Object> atStart;
42:
43: public boolean knownAtStart(String s) {
44: return atStart.get(s) != null;
45: }
46:
47: public HttpParameters(HttpServletRequest req) {
48: request = req;
49: computeAtStart();
50: }
51:
52: void computeAtStart() {
53: atStart = new Hashtable<Object, Object>();
54: Object dummy = new Object();
55: for (Enumeration e = request.getParameterNames(); e
56: .hasMoreElements();)
57: atStart.put(e.nextElement(), dummy);
58: }
59:
60: /**
61: * Gets a http parameter. If there are more values for the parameter, places them into a Vector
62: *
63: * @param s
64: * the name of the parameter
65: * @return A String containing the value of the parameter in case of a unique value, a Vector otherwise
66: */
67: public Object getParameter(String s) {
68: Object value = null;
69: String[] param = request.getParameterValues(s);
70: if (param == null)
71: return null;
72:
73: if (param.length == 1)
74: value = param[0];
75: else {
76: Vector<String> v = new java.util.Vector<String>();
77: value = v;
78: for (int i = 0; i < param.length; i++)
79: v.addElement(param[i]);
80: }
81: // request.setAttribute(s, value);
82:
83: return value;
84: }
85:
86: public String toString() {
87: return request.getParameterMap().toString();
88: }
89:
90: }
|