1 46 47 package org.jfree.chart.urls; 48 49 import java.io.Serializable ; 50 import java.text.DateFormat ; 51 import java.util.Date ; 52 53 import org.jfree.data.xy.XYDataset; 54 55 60 public class TimeSeriesURLGenerator implements XYURLGenerator, Serializable { 61 62 63 private static final long serialVersionUID = -9122773175671182445L; 64 65 66 private DateFormat dateFormat = DateFormat.getInstance(); 67 68 69 private String prefix = "index.html"; 70 71 72 private String seriesParameterName = "series"; 73 74 75 private String itemParameterName = "item"; 76 77 80 public TimeSeriesURLGenerator() { 81 super(); 82 } 83 84 92 public TimeSeriesURLGenerator(DateFormat dDateFormat, String sPrefix, 93 String sSeriesParameterName, 94 String sItemParameterName) { 95 96 this.dateFormat = dDateFormat; 97 this.prefix = sPrefix; 98 this.seriesParameterName = sSeriesParameterName; 99 this.itemParameterName = sItemParameterName; 100 101 } 102 103 112 public String generateURL(XYDataset dataset, int series, int item) { 113 String result = this.prefix; 114 boolean firstParameter = result.indexOf("?") == -1; 115 Comparable seriesKey = dataset.getSeriesKey(series); 116 if (seriesKey != null) { 117 result += firstParameter ? "?" : "&"; 118 result += this.seriesParameterName + "=" + seriesKey.toString(); 119 firstParameter = false; 120 } 121 122 long x = dataset.getX(series, item).longValue(); 123 String xValue = this.dateFormat.format(new Date (x)); 124 result += firstParameter ? "?" : "&"; 125 result += this.itemParameterName + "=" + xValue; 126 127 return result; 128 } 129 130 131 } 132 | Popular Tags |