KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreechart > PentahoChartURLTagFragmentGenerator


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 Feb 13, 2006
14  * @author wseyler
15  */

16
17 package org.pentaho.plugin.jfreechart;
18
19 import org.jfree.chart.imagemap.StandardURLTagFragmentGenerator;
20 import org.jfree.data.general.Dataset;
21 import org.pentaho.core.system.PentahoSystem;
22 import org.pentaho.core.util.TemplateUtil;
23
24 public class PentahoChartURLTagFragmentGenerator extends StandardURLTagFragmentGenerator {
25     private static final String JavaDoc SERIES_TAG = "series="; //$NON-NLS-1$
26
private static final String JavaDoc CATEGORY_TAG = "category="; //$NON-NLS-1$
27

28     String JavaDoc urlFragment;
29     Dataset dataset;
30     String JavaDoc parameterName;
31     String JavaDoc outerParameterName;
32
33     public PentahoChartURLTagFragmentGenerator(String JavaDoc urlFragment, Dataset dataset, String JavaDoc parameterName, String JavaDoc outerParameterName) {
34         super();
35         
36         this.urlFragment = urlFragment;
37         this.dataset = dataset;
38         this.parameterName = parameterName;
39         this.outerParameterName = outerParameterName;
40     }
41
42     public PentahoChartURLTagFragmentGenerator(String JavaDoc urlTemplate, Dataset dataDefinition, String JavaDoc paramName) {
43         this(urlTemplate, dataDefinition, paramName, ""); //$NON-NLS-1$
44
}
45
46     public String JavaDoc generateURLFragment(String JavaDoc urlText) {
47         if (urlFragment != null) {
48             String JavaDoc urlTemplate = " HREF=\"" + PentahoSystem.getApplicationContext().getBaseUrl() + urlFragment + "\""; //$NON-NLS-1$ //$NON-NLS-2$
49

50             int startIdx = urlText.indexOf(CATEGORY_TAG) + CATEGORY_TAG.length();
51             int endIdx = urlText.indexOf('&', startIdx) != -1 ? urlText.indexOf('&', startIdx) : urlText.length();
52             String JavaDoc value = urlText.substring(startIdx, endIdx).trim();
53             urlTemplate = TemplateUtil.applyTemplate(urlTemplate, parameterName, value);
54
55             if (dataset instanceof CategoryDatasetChartDefinition){
56                 startIdx = urlText.indexOf(SERIES_TAG) + SERIES_TAG.length();
57                 endIdx = urlText.indexOf('&', startIdx) != -1 ? urlText.indexOf('&', startIdx) : urlText.length();
58                 value = urlText.substring(startIdx, endIdx).trim();
59                 urlTemplate = TemplateUtil.applyTemplate(urlTemplate, outerParameterName, value);
60             }
61             urlTemplate = urlTemplate + " target=\"pentaho-popup\""; //$NON-NLS-1$
62

63             return urlTemplate;
64         } else {
65             return super.generateURLFragment(urlText);
66         }
67     }
68 }
69
Popular Tags