01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: *
13: * @created Jul 11, 2005
14: * @author James Dixon
15: *
16: */
17:
18: package org.pentaho.core.solution;
19:
20: import java.util.Iterator;
21: import java.util.Map;
22:
23: import javax.servlet.http.HttpServletRequest;
24:
25: import org.pentaho.util.HttpUtil;
26:
27: public class HttpRequestParameterProvider extends
28: SimpleParameterProvider {
29:
30: public static final String SCOPE_REQUEST = "request"; //$NON-NLS-1$
31:
32: private HttpServletRequest request;
33:
34: public HttpRequestParameterProvider(HttpServletRequest request) {
35: this .request = request;
36: setServletRequestParameters(request.getParameterMap());
37:
38: if (request
39: .getParameter(SimpleParameterProvider.ADDITIONAL_PARAMS) != null) {
40: String additionalParameters = request
41: .getParameter(SimpleParameterProvider.ADDITIONAL_PARAMS);
42: int idx = additionalParameters.indexOf("?"); //$NON-NLS-1$
43: if (idx > 0) {
44: additionalParameters = additionalParameters
45: .substring(idx + 1);
46: }
47: Map additionalParms = HttpUtil
48: .parseQueryString(additionalParameters);
49: setServletRequestParameters(additionalParms);
50: }
51: }
52:
53: /**
54: * Converts single value arrays to String parameters
55: *
56: */
57: private void setServletRequestParameters(Map paramMap) {
58: for (Iterator it = paramMap.entrySet().iterator(); it.hasNext();) {
59: Map.Entry entry = (Map.Entry) it.next();
60: Object value = entry.getValue();
61: if (value != null) {
62: if ((value instanceof Object[])
63: && (((Object[]) value).length == 1)) {
64: setParameter((String) entry.getKey(), String
65: .valueOf(((Object[]) value)[0]));
66: } else {
67: setParameter((String) entry.getKey(), value);
68: }
69: }
70: }
71: }
72:
73: public HttpServletRequest getRequest() {
74: return request;
75: }
76:
77: }
|