001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ----------------------------
028: * StandardPieURLGenerator.java
029: * ----------------------------
030: * (C) Copyright 2002-2006, by Richard Atkinson and Contributors.
031: *
032: * Original Author: Richard Atkinson;
033: * Contributors: David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: StandardPieURLGenerator.java,v 1.4.2.3 2007/04/17 16:05:27 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 05-Aug-2002 : Version 1, contributed by Richard Atkinson;
040: * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041: * 07-Mar-2003 : Modified to use KeyedValuesDataset and added pieIndex
042: * parameter (DG);
043: * 21-Mar-2003 : Implemented Serializable (DG);
044: * 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG);
045: * 31-Mar-2004 : Added an optional 'pieIndex' parameter (DG);
046: * 13-Jan-2005 : Fixed for compliance with XHTML 1.0 (DG);
047: * ------------- JFREECHART 1.0.x ---------------------------------------------
048: * 24-Nov-2006 : Fixed equals() method and added argument checks (DG);
049: * 17-Apr-2007 : Encode section key in generateURL() (DG);
050: *
051: */
052:
053: package org.jfree.chart.urls;
054:
055: import java.io.Serializable;
056:
057: import org.jfree.data.general.PieDataset;
058: import org.jfree.util.ObjectUtilities;
059:
060: /**
061: * A URL generator for pie charts. Instances of this class are immutable.
062: */
063: public class StandardPieURLGenerator implements PieURLGenerator,
064: Serializable {
065:
066: /** For serialization. */
067: private static final long serialVersionUID = 1626966402065883419L;
068:
069: /** The prefix. */
070: private String prefix = "index.html";
071:
072: /** The category parameter name. */
073: private String categoryParameterName = "category";
074:
075: /** The pie index parameter name. */
076: private String indexParameterName = "pieIndex";
077:
078: /**
079: * Default constructor.
080: */
081: public StandardPieURLGenerator() {
082: this ("index.html");
083: }
084:
085: /**
086: * Creates a new generator.
087: *
088: * @param prefix the prefix (<code>null</code> not permitted).
089: */
090: public StandardPieURLGenerator(String prefix) {
091: this (prefix, "category");
092: }
093:
094: /**
095: * Creates a new generator.
096: *
097: * @param prefix the prefix (<code>null</code> not permitted).
098: * @param categoryParameterName the category parameter name
099: * (<code>null</code> not permitted).
100: */
101: public StandardPieURLGenerator(String prefix,
102: String categoryParameterName) {
103: this (prefix, categoryParameterName, "pieIndex");
104: }
105:
106: /**
107: * Creates a new generator.
108: *
109: * @param prefix the prefix (<code>null</code> not permitted).
110: * @param categoryParameterName the category parameter name
111: * (<code>null</code> not permitted).
112: * @param indexParameterName the index parameter name (<code>null</code>
113: * permitted).
114: */
115: public StandardPieURLGenerator(String prefix,
116: String categoryParameterName, String indexParameterName) {
117: if (prefix == null) {
118: throw new IllegalArgumentException(
119: "Null 'prefix' argument.");
120: }
121: if (categoryParameterName == null) {
122: throw new IllegalArgumentException(
123: "Null 'categoryParameterName' argument.");
124: }
125: this .prefix = prefix;
126: this .categoryParameterName = categoryParameterName;
127: this .indexParameterName = indexParameterName;
128: }
129:
130: /**
131: * Generates a URL.
132: *
133: * @param dataset the dataset (ignored).
134: * @param key the item key (<code>null</code> not permitted).
135: * @param pieIndex the pie index.
136: *
137: * @return A string containing the generated URL.
138: */
139: public String generateURL(PieDataset dataset, Comparable key,
140: int pieIndex) {
141: String url = this .prefix;
142: if (url.indexOf("?") > -1) {
143: url += "&" + this .categoryParameterName + "="
144: + URLUtilities.encode(key.toString(), "UTF-8");
145: } else {
146: url += "?" + this .categoryParameterName + "="
147: + URLUtilities.encode(key.toString(), "UTF-8");
148: }
149: if (this .indexParameterName != null) {
150: url += "&" + this .indexParameterName + "="
151: + String.valueOf(pieIndex);
152: }
153: return url;
154: }
155:
156: /**
157: * Tests if this object is equal to another.
158: *
159: * @param obj the object (<code>null</code> permitted).
160: *
161: * @return A boolean.
162: */
163: public boolean equals(Object obj) {
164: if (obj == this ) {
165: return true;
166: }
167: if (!(obj instanceof StandardPieURLGenerator)) {
168: return false;
169: }
170: StandardPieURLGenerator that = (StandardPieURLGenerator) obj;
171: if (!this .prefix.equals(that.prefix)) {
172: return false;
173: }
174: if (!this .categoryParameterName
175: .equals(that.categoryParameterName)) {
176: return false;
177: }
178: if (!ObjectUtilities.equal(this .indexParameterName,
179: that.indexParameterName)) {
180: return false;
181: }
182: return true;
183: }
184: }
|