001: /*
002: * Copyright 2005 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created May 31, 2006
014: * @author James Dixon
015: */
016:
017: package org.pentaho.ui.component.charting;
018:
019: import java.math.BigDecimal;
020: import java.util.Date;
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.HashSet;
024: import java.util.Set;
025:
026: import org.pentaho.core.solution.IParameterProvider;
027: import org.pentaho.core.solution.SimpleParameterProvider;
028: import org.pentaho.util.ParameterHelper;
029:
030: public class FlashChartRequestMapper extends SimpleParameterProvider {
031:
032: private IParameterProvider request;
033:
034: private HashMap chartParams = new HashMap();
035:
036: private Set keySet = new HashSet();
037:
038: public FlashChartRequestMapper(IParameterProvider request) {
039: this .request = request;
040: Iterator it = request.getParameterNames();
041: while (it.hasNext()) {
042: keySet.add(it.next());
043: }
044: boolean isChart = "prochart".equals(request.getStringParameter("client", null)); //$NON-NLS-1$ //$NON-NLS-2$
045: if (isChart) {
046: String catName = request.getStringParameter(
047: "categoryName", null); //$NON-NLS-1$
048: if (catName != null) {
049: String value = request.getStringParameter(
050: "category", null); //$NON-NLS-1$
051: if (value != null) {
052: chartParams.put(catName, value);
053: keySet.add(catName);
054: keySet.remove("category"); //$NON-NLS-1$
055: keySet.remove("categoryName"); //$NON-NLS-1$
056: }
057: }
058: String seriesName = request.getStringParameter(
059: "seriesName", null); //$NON-NLS-1$
060: if (seriesName != null) {
061: String value = request.getStringParameter(
062: "series", null); //$NON-NLS-1$
063: if (value != null) {
064: chartParams.put(seriesName, value);
065: keySet.add(seriesName);
066: keySet.remove("series"); //$NON-NLS-1$
067: keySet.remove("seriesName"); //$NON-NLS-1$
068: }
069: }
070: }
071: }
072:
073: public String getStringParameter(String name, String defaultValue) {
074: Object value = chartParams.get(name);
075: if (value != null) {
076: return value.toString();
077: } else {
078: return request.getStringParameter(name, defaultValue);
079: }
080: }
081:
082: public long getLongParameter(String name, long defaultValue) {
083: String value = (String) chartParams.get(name);
084: if (value != null) {
085: return ParameterHelper.parameterToLong(value, defaultValue);
086: } else {
087: return request.getLongParameter(name, defaultValue);
088: }
089: }
090:
091: public Date getDateParameter(String name, Date defaultValue) {
092: String value = (String) chartParams.get(name);
093: if (value != null) {
094: return ParameterHelper.parameterToDate(value, defaultValue);
095: } else {
096: return request.getDateParameter(name, defaultValue);
097: }
098: }
099:
100: public Object getDecimalParameter(String name,
101: BigDecimal defaultValue) {
102: String value = (String) chartParams.get(name);
103: if (value != null) {
104: return ParameterHelper.parameterToDecimal(value,
105: defaultValue);
106: } else {
107: return request.getDecimalParameter(name, defaultValue);
108: }
109: }
110:
111: public Iterator getParameterNames() {
112: return keySet.iterator();
113: }
114:
115: public Object getParameter(String name) {
116: Object value = chartParams.get(name);
117: if (value != null) {
118: return value;
119: } else {
120: return request.getParameter(name);
121: }
122: }
123:
124: }
|