001: /*
002: * Copyright 2006 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 Feb 13, 2006
014: * @author wseyler
015: */
016:
017: package org.pentaho.plugin.jfreechart;
018:
019: import org.jfree.chart.imagemap.StandardURLTagFragmentGenerator;
020: import org.jfree.data.general.Dataset;
021: import org.pentaho.core.system.PentahoSystem;
022: import org.pentaho.core.util.TemplateUtil;
023:
024: public class PentahoChartURLTagFragmentGenerator extends
025: StandardURLTagFragmentGenerator {
026: private static final String SERIES_TAG = "series="; //$NON-NLS-1$
027:
028: private static final String CATEGORY_TAG = "category="; //$NON-NLS-1$
029:
030: String urlFragment;
031:
032: Dataset dataset;
033:
034: String parameterName;
035:
036: String outerParameterName;
037:
038: String urlTarget;
039:
040: boolean useBaseUrl;
041:
042: public PentahoChartURLTagFragmentGenerator(String urlFragment,
043: Dataset dataset, String parameterName,
044: String outerParameterName) {
045: super ();
046:
047: this .urlFragment = urlFragment;
048: this .dataset = dataset;
049: this .parameterName = parameterName;
050: this .outerParameterName = outerParameterName;
051: this .urlTarget = "pentaho_popup";//$NON-NLS-1$
052: this .useBaseUrl = true;
053: }
054:
055: public PentahoChartURLTagFragmentGenerator(String urlFragment,
056: String urlTarget, boolean useBaseUrl, Dataset dataset,
057: String parameterName, String outerParameterName) {
058: super ();
059: this .urlFragment = urlFragment;
060: this .dataset = dataset;
061: this .parameterName = parameterName;
062: this .outerParameterName = outerParameterName;
063: this .urlTarget = urlTarget;
064: this .useBaseUrl = useBaseUrl;
065: }
066:
067: public PentahoChartURLTagFragmentGenerator(String urlTemplate,
068: Dataset dataDefinition, String paramName) {
069: this (urlTemplate, dataDefinition, paramName, ""); //$NON-NLS-1$
070: }
071:
072: public String generateURLFragment(String urlText) {
073: if (urlFragment != null) {
074:
075: String urlTemplate = " href=\""; //$NON-NLS-1$
076:
077: // do not add ase URL if script
078: boolean isScript = urlFragment.startsWith("javascript:"); //$NON-NLS-1$
079:
080: // If isScript is true, ignore useBaseURL parameter...
081: if (!isScript) {
082: if (useBaseUrl) {
083: urlTemplate += PentahoSystem
084: .getApplicationContext().getBaseUrl();
085:
086: }
087: }
088:
089: urlTemplate += urlFragment + "\""; //$NON-NLS-1$
090:
091: int startIdx;
092: if (urlText.indexOf(CATEGORY_TAG) != -1)
093: startIdx = urlText.indexOf(CATEGORY_TAG)
094: + CATEGORY_TAG.length();
095: else
096: startIdx = 0;
097:
098: int endIdx;
099: if (urlText.indexOf('&', startIdx) != -1)
100: endIdx = urlText.indexOf('&', startIdx);
101: else
102: endIdx = urlText.length();
103:
104: String value = urlText.substring(startIdx, endIdx).trim();
105: urlTemplate = TemplateUtil.applyTemplate(urlTemplate,
106: parameterName, value);
107:
108: if (dataset instanceof CategoryDatasetChartDefinition
109: || dataset instanceof XYZSeriesCollectionChartDefinition) {
110:
111: if (urlText.indexOf(SERIES_TAG) != -1)
112: startIdx = urlText.indexOf(SERIES_TAG)
113: + SERIES_TAG.length();
114: else
115: startIdx = 0;
116:
117: if (urlText.indexOf('&', startIdx) != -1)
118: endIdx = urlText.indexOf('&', startIdx);
119: else
120: endIdx = urlText.length();
121:
122: value = urlText.substring(startIdx, endIdx).trim();
123: urlTemplate = TemplateUtil.applyTemplate(urlTemplate,
124: outerParameterName, value);
125:
126: }
127:
128: if (!isScript) {
129: urlTemplate = urlTemplate
130: + " target=\"" + urlTarget + "\""; //$NON-NLS-1$//$NON-NLS-2$
131: }
132:
133: return urlTemplate;
134:
135: } else {
136: return super.generateURLFragment(urlText);
137: }
138: }
139: }
|