1 52 53 package org.jfree.chart.urls; 54 55 import java.io.Serializable ; 56 import java.net.URLEncoder ; 57 58 import org.jfree.data.category.CategoryDataset; 59 import org.jfree.util.ObjectUtilities; 60 61 67 public class StandardCategoryURLGenerator implements CategoryURLGenerator, 68 Cloneable , Serializable { 69 70 71 private static final long serialVersionUID = 2276668053074881909L; 72 73 74 private String prefix = "index.html"; 75 76 77 private String seriesParameterName = "series"; 78 79 80 private String categoryParameterName = "category"; 81 82 85 public StandardCategoryURLGenerator() { 86 super(); 87 } 88 89 94 public StandardCategoryURLGenerator(String prefix) { 95 if (prefix == null) { 96 throw new IllegalArgumentException ("Null 'prefix' argument."); 97 } 98 this.prefix = prefix; 99 } 100 101 110 public StandardCategoryURLGenerator(String prefix, 111 String seriesParameterName, 112 String categoryParameterName) { 113 114 if (prefix == null) { 115 throw new IllegalArgumentException ("Null 'prefix' argument."); 116 } 117 if (seriesParameterName == null) { 118 throw new IllegalArgumentException ( 119 "Null 'seriesParameterName' argument." 120 ); 121 } 122 if (categoryParameterName == null) { 123 throw new IllegalArgumentException ( 124 "Null 'categoryParameterName' argument." 125 ); 126 } 127 this.prefix = prefix; 128 this.seriesParameterName = seriesParameterName; 129 this.categoryParameterName = categoryParameterName; 130 131 } 132 133 142 public String generateURL(CategoryDataset dataset, int series, 143 int category) { 144 String url = this.prefix; 145 Comparable seriesKey = dataset.getRowKey(series); 146 Comparable categoryKey = dataset.getColumnKey(category); 147 boolean firstParameter = url.indexOf("?") == -1; 148 url += firstParameter ? "?" : "&"; 149 url += this.seriesParameterName + "=" 151 + URLEncoder.encode(seriesKey.toString()); 152 url += "&" + this.categoryParameterName + "=" 160 + URLEncoder.encode(categoryKey.toString()); 161 return url; 169 } 170 171 179 public Object clone() throws CloneNotSupportedException { 180 181 return super.clone(); 183 184 } 185 186 193 public boolean equals(Object obj) { 194 if (obj == this) { 195 return true; 196 } 197 if (!(obj instanceof StandardCategoryURLGenerator)) { 198 return false; 199 } 200 StandardCategoryURLGenerator that = (StandardCategoryURLGenerator) obj; 201 if (!ObjectUtilities.equal(this.prefix, that.prefix)) { 202 return false; 203 } 204 205 if (!ObjectUtilities.equal(this.seriesParameterName, 206 that.seriesParameterName)) { 207 return false; 208 } 209 if (!ObjectUtilities.equal(this.categoryParameterName, 210 that.categoryParameterName)) { 211 return false; 212 } 213 return true; 214 } 215 216 221 public int hashCode() { 222 int result; 223 result = (this.prefix != null ? this.prefix.hashCode() : 0); 224 result = 29 * result 225 + (this.seriesParameterName != null 226 ? this.seriesParameterName.hashCode() : 0); 227 result = 29 * result 228 + (this.categoryParameterName != null 229 ? this.categoryParameterName.hashCode() : 0); 230 return result; 231 } 232 233 } 234 | Popular Tags |