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: * StandardXYURLGenerator.java
029: * ---------------------------
030: * (C) Copyright 2002-2007, by Richard Atkinson and Contributors.
031: *
032: * Original Author: Richard Atkinson;
033: * Contributors: David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: StandardXYURLGenerator.java,v 1.6.2.3 2007/02/20 15:36:23 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 05-Aug-2002 : Version 1, contributed by Richard Atkinson;
040: * 29-Aug-2002 : New constructor and member variables to customise series and
041: * item parameter names (RA);
042: * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
043: * 23-Mar-2003 : Implemented Serializable (DG);
044: * 01-Mar-2004 : Added equals() method (DG);
045: * 13-Jan-2005 : Modified for XHTML 1.0 compliance (DG);
046: * ------------- JFREECHART 1.0.x ---------------------------------------------
047: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
048: *
049: */
050:
051: package org.jfree.chart.urls;
052:
053: import java.io.Serializable;
054:
055: import org.jfree.data.xy.XYDataset;
056: import org.jfree.util.ObjectUtilities;
057:
058: /**
059: * A URL generator.
060: */
061: public class StandardXYURLGenerator implements XYURLGenerator,
062: Serializable {
063:
064: /** For serialization. */
065: private static final long serialVersionUID = -1771624523496595382L;
066:
067: /** The default prefix. */
068: public static final String DEFAULT_PREFIX = "index.html";
069:
070: /** The default series parameter. */
071: public static final String DEFAULT_SERIES_PARAMETER = "series";
072:
073: /** The default item parameter. */
074: public static final String DEFAULT_ITEM_PARAMETER = "item";
075:
076: /** Prefix to the URL */
077: private String prefix;
078:
079: /** Series parameter name to go in each URL */
080: private String seriesParameterName;
081:
082: /** Item parameter name to go in each URL */
083: private String itemParameterName;
084:
085: /**
086: * Creates a new default generator. This constructor is equivalent to
087: * calling <code>StandardXYURLGenerator("index.html", "series", "item");
088: * </code>.
089: */
090: public StandardXYURLGenerator() {
091: this (DEFAULT_PREFIX, DEFAULT_SERIES_PARAMETER,
092: DEFAULT_ITEM_PARAMETER);
093: }
094:
095: /**
096: * Creates a new generator with the specified prefix. This constructor
097: * is equivalent to calling
098: * <code>StandardXYURLGenerator(prefix, "series", "item");</code>.
099: *
100: * @param prefix the prefix to the URL (<code>null</code> not permitted).
101: */
102: public StandardXYURLGenerator(String prefix) {
103: this (prefix, DEFAULT_SERIES_PARAMETER, DEFAULT_ITEM_PARAMETER);
104: }
105:
106: /**
107: * Constructor that overrides all the defaults
108: *
109: * @param prefix the prefix to the URL (<code>null</code> not permitted).
110: * @param seriesParameterName the name of the series parameter to go in
111: * each URL (<code>null</code> not permitted).
112: * @param itemParameterName the name of the item parameter to go in each
113: * URL (<code>null</code> not permitted).
114: */
115: public StandardXYURLGenerator(String prefix,
116: String seriesParameterName, String itemParameterName) {
117: if (prefix == null) {
118: throw new IllegalArgumentException(
119: "Null 'prefix' argument.");
120: }
121: if (seriesParameterName == null) {
122: throw new IllegalArgumentException(
123: "Null 'seriesParameterName' argument.");
124: }
125: if (itemParameterName == null) {
126: throw new IllegalArgumentException(
127: "Null 'itemParameterName' argument.");
128: }
129: this .prefix = prefix;
130: this .seriesParameterName = seriesParameterName;
131: this .itemParameterName = itemParameterName;
132: }
133:
134: /**
135: * Generates a URL for a particular item within a series.
136: *
137: * @param dataset the dataset.
138: * @param series the series number (zero-based index).
139: * @param item the item number (zero-based index).
140: *
141: * @return The generated URL.
142: */
143: public String generateURL(XYDataset dataset, int series, int item) {
144: String url = this .prefix;
145: boolean firstParameter = url.indexOf("?") == -1;
146: url += firstParameter ? "?" : "&";
147: url += this .seriesParameterName + "=" + series + "&"
148: + this .itemParameterName + "=" + item;
149: return url;
150: }
151:
152: /**
153: * Tests this generator for equality with an arbitrary object.
154: *
155: * @param obj the object (<code>null</code> permitted).
156: *
157: * @return A boolean.
158: */
159: public boolean equals(Object obj) {
160: if (obj == this ) {
161: return true;
162: }
163: if (!(obj instanceof StandardXYURLGenerator)) {
164: return false;
165: }
166: StandardXYURLGenerator that = (StandardXYURLGenerator) obj;
167: if (!ObjectUtilities.equal(that.prefix, this .prefix)) {
168: return false;
169: }
170: if (!ObjectUtilities.equal(that.seriesParameterName,
171: this .seriesParameterName)) {
172: return false;
173: }
174: if (!ObjectUtilities.equal(that.itemParameterName,
175: this .itemParameterName)) {
176: return false;
177: }
178: return true;
179: }
180:
181: }
|