KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > solution > HttpRequestParameterProvider


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * 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 JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 import org.pentaho.util.HttpUtil;
26
27 public class HttpRequestParameterProvider extends SimpleParameterProvider {
28
29     private HttpServletRequest JavaDoc request;
30
31     public HttpRequestParameterProvider(HttpServletRequest JavaDoc request) {
32         this.request = request;
33         setServletRequestParameters(request.getParameterMap());
34
35         if (request.getParameter("_PENTAHO_ADDITIONAL_PARAMS_") != null) { //$NON-NLS-1$
36
String JavaDoc additionalParameters = request.getParameter("_PENTAHO_ADDITIONAL_PARAMS_"); //$NON-NLS-1$
37
int idx = additionalParameters.indexOf("?"); //$NON-NLS-1$
38
if (idx > 0) {
39                 additionalParameters = additionalParameters.substring(idx + 1);
40             }
41             Map JavaDoc additionalParms = HttpUtil.parseQueryString(additionalParameters);
42             setServletRequestParameters(additionalParms);
43         }
44     }
45     
46     /**
47      * Converts single value arrays to String parameters
48      *
49      */

50     private void setServletRequestParameters( Map JavaDoc paramMap ) {
51         for ( Iterator JavaDoc it = paramMap.entrySet().iterator(); it.hasNext(); ) {
52             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)it.next();
53             Object JavaDoc value = entry.getValue();
54             if (value != null) {
55                 if ( (value instanceof Object JavaDoc[]) && ( ((Object JavaDoc[])value).length == 1 ) ) {
56                     setParameter( (String JavaDoc)entry.getKey(), String.valueOf( ((Object JavaDoc[])value)[0] ) );
57                 }
58                 else {
59                     setParameter( (String JavaDoc)entry.getKey(), value );
60                 }
61             }
62         }
63     }
64
65     public HttpServletRequest JavaDoc getRequest() {
66         return request;
67     }
68     
69 }
70
Popular Tags