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 Aug 2, 2005
14: * @author James Dixon
15: */
16:
17: package org.pentaho.ui.portlet;
18:
19: import java.util.Iterator;
20: import java.util.Map;
21:
22: import javax.portlet.PortletRequest;
23:
24: import org.pentaho.core.solution.IParameterSetter;
25: import org.pentaho.core.solution.SimpleParameterProvider;
26: import org.pentaho.util.HttpUtil;
27:
28: public class PortletRequestParameterProvider extends
29: SimpleParameterProvider implements IParameterSetter {
30:
31: public static final String SCOPE_PORTLET_REQUEST = "portletRequest"; //$NON-NLS-1$
32:
33: private PortletRequest portletRequest;
34:
35: public PortletRequestParameterProvider(PortletRequest portletRequest) {
36: this .portletRequest = portletRequest;
37: setPortletRequestParameters(portletRequest.getParameterMap());
38:
39: if (portletRequest
40: .getParameter(SimpleParameterProvider.ADDITIONAL_PARAMS) != null) {
41: String additionalParameters = portletRequest
42: .getParameter(SimpleParameterProvider.ADDITIONAL_PARAMS);
43: int idx = additionalParameters.indexOf("?"); //$NON-NLS-1$
44: if (idx > 0) {
45: additionalParameters = additionalParameters
46: .substring(idx + 1);
47: }
48: Map additionalParms = HttpUtil
49: .parseQueryString(additionalParameters);
50: setPortletRequestParameters(additionalParms);
51: }
52: }
53:
54: /**
55: * Converts single value arrays to String parameters
56: *
57: */
58: private void setPortletRequestParameters(Map paramMap) {
59: for (Iterator it = paramMap.entrySet().iterator(); it.hasNext();) {
60: Map.Entry entry = (Map.Entry) it.next();
61: Object value = entry.getValue();
62: if (value != null) {
63: if ((value instanceof Object[])
64: && (((Object[]) value).length == 1)) {
65: setParameter((String) entry.getKey(), String
66: .valueOf(((Object[]) value)[0]));
67: } else {
68: setParameter((String) entry.getKey(), value);
69: }
70: }
71: }
72: }
73:
74: public PortletRequest getRequest() {
75: return portletRequest;
76: }
77: }
|