1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jfreechart/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  17. * License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  24. * in the United States and other countries.]
  25. *
  26. * ---------------------------
  27. * StandardXYURLGenerator.java
  28. * ---------------------------
  29. * (C) Copyright 2002-2005, by Richard Atkinson and Contributors.
  30. *
  31. * Original Author: Richard Atkinson;
  32. * Contributors: David Gilbert (for Object Refinery Limited);
  33. *
  34. * $Id: StandardXYURLGenerator.java,v 1.5 2005/03/09 13:45:32 mungady Exp $
  35. *
  36. * Changes:
  37. * --------
  38. * 05-Aug-2002 : Version 1, contributed by Richard Atkinson;
  39. * 29-Aug-2002 : New constructor and member variables to customise series and
  40. * item parameter names (RA);
  41. * 09-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  42. * 23-Mar-2003 : Implemented Serializable (DG);
  43. * 01-Mar-2004 : Added equals() method (DG);
  44. * 13-Jan-2005 : Modified for XHTML 1.0 compliance (DG);
  45. *
  46. */
  47. package org.jfree.chart.urls;
  48. import java.io.Serializable;
  49. import org.jfree.data.xy.XYDataset;
  50. import org.jfree.util.ObjectUtilities;
  51. /**
  52. * A URL generator.
  53. *
  54. * @author Richard Atkinson
  55. */
  56. public class StandardXYURLGenerator implements XYURLGenerator, Serializable {
  57. /** The default prefix. */
  58. public static final String DEFAULT_PREFIX = "index.html";
  59. /** The default series parameter. */
  60. public static final String DEFAULT_SERIES_PARAMETER = "series";
  61. /** The default item parameter. */
  62. public static final String DEFAULT_ITEM_PARAMETER = "item";
  63. /** Prefix to the URL */
  64. private String prefix;
  65. /** Series parameter name to go in each URL */
  66. private String seriesParameterName;
  67. /** Item parameter name to go in each URL */
  68. private String itemParameterName;
  69. /**
  70. * Creates a new default generator. This constructor is equivalent to
  71. * calling <code>StandardXYURLGenerator("index.html", "series", "item");
  72. * </code>.
  73. */
  74. public StandardXYURLGenerator() {
  75. this(DEFAULT_PREFIX, DEFAULT_SERIES_PARAMETER, DEFAULT_ITEM_PARAMETER);
  76. }
  77. /**
  78. * Creates a new generator with the specified prefix. This constructor
  79. * is equivalent to calling
  80. * <code>StandardXYURLGenerator(prefix, "series", "item");</code>.
  81. *
  82. * @param prefix the prefix to the URL (<code>null</code> not permitted).
  83. */
  84. public StandardXYURLGenerator(String prefix) {
  85. this(prefix, DEFAULT_SERIES_PARAMETER, DEFAULT_ITEM_PARAMETER);
  86. }
  87. /**
  88. * Constructor that overrides all the defaults
  89. *
  90. * @param prefix the prefix to the URL (<code>null</code> not permitted).
  91. * @param seriesParameterName the name of the series parameter to go in
  92. * each URL (<code>null</code> not permitted).
  93. * @param itemParameterName the name of the item parameter to go in each
  94. * URL (<code>null</code> not permitted).
  95. */
  96. public StandardXYURLGenerator(String prefix,
  97. String seriesParameterName,
  98. String itemParameterName) {
  99. if (prefix == null) {
  100. throw new IllegalArgumentException("Null 'prefix' argument.");
  101. }
  102. if (seriesParameterName == null) {
  103. throw new IllegalArgumentException(
  104. "Null 'seriesParameterName' argument."
  105. );
  106. }
  107. if (itemParameterName == null) {
  108. throw new IllegalArgumentException(
  109. "Null 'itemParameterName' argument."
  110. );
  111. }
  112. this.prefix = prefix;
  113. this.seriesParameterName = seriesParameterName;
  114. this.itemParameterName = itemParameterName;
  115. }
  116. /**
  117. * Generates a URL for a particular item within a series.
  118. *
  119. * @param dataset the dataset.
  120. * @param series the series number (zero-based index).
  121. * @param item the item number (zero-based index).
  122. *
  123. * @return The generated URL.
  124. */
  125. public String generateURL(XYDataset dataset, int series, int item) {
  126. String url = this.prefix;
  127. boolean firstParameter = url.indexOf("?") == -1;
  128. url += firstParameter ? "?" : "&";
  129. url += this.seriesParameterName + "=" + series
  130. + "&" + this.itemParameterName + "=" + item;
  131. return url;
  132. }
  133. /**
  134. * Tests this generator for equality with an arbitrary object.
  135. *
  136. * @param obj the object (<code>null</code> permitted).
  137. *
  138. * @return A boolean.
  139. */
  140. public boolean equals(Object obj) {
  141. if (obj == this) {
  142. return true;
  143. }
  144. if (!(obj instanceof StandardXYURLGenerator)) {
  145. return false;
  146. }
  147. StandardXYURLGenerator that = (StandardXYURLGenerator) obj;
  148. if (!ObjectUtilities.equal(that.prefix, this.prefix)) {
  149. return false;
  150. }
  151. if (!ObjectUtilities.equal(that.seriesParameterName,
  152. this.seriesParameterName)) {
  153. return false;
  154. }
  155. if (!ObjectUtilities.equal(that.itemParameterName,
  156. this.itemParameterName)) {
  157. return false;
  158. }
  159. return true;
  160. }
  161. }