1 28 package net.sf.jasperreports.engine.data; 29 30 import java.text.DateFormat ; 31 import java.text.NumberFormat ; 32 import java.io.InputStream ; 33 import java.io.File ; 34 import java.io.Reader ; 35 import java.io.FileNotFoundException ; 36 import java.io.InputStreamReader ; 37 import java.io.FileReader ; 38 39 import net.sf.jasperreports.engine.JRDataSourceProvider; 40 import net.sf.jasperreports.engine.JRDataSource; 41 import net.sf.jasperreports.engine.JasperReport; 42 import net.sf.jasperreports.engine.JRException; 43 import net.sf.jasperreports.engine.JRField; 44 45 49 public class JRCsvDataSourceProvider implements JRDataSourceProvider 50 { 51 private Reader reader; 52 53 private DateFormat dateFormat; 54 private char fieldDelimiter; 55 private String recordDelimiter; 56 private String [] columnNames; 57 private NumberFormat numberFormat; 58 59 62 public JRCsvDataSourceProvider(InputStream stream) 63 { 64 this(new InputStreamReader (stream)); 65 } 66 67 68 72 public JRCsvDataSourceProvider(File file) throws FileNotFoundException 73 { 74 this(new FileReader (file)); 75 } 76 77 78 82 public JRCsvDataSourceProvider(Reader reader) 83 { 84 this.reader = reader; 85 } 86 87 90 public boolean supportsGetFieldsOperation() 91 { 92 return false; 93 } 94 95 96 99 public JRField[] getFields(JasperReport report) throws JRException, UnsupportedOperationException 100 { 101 return null; 102 } 103 104 105 108 public JRDataSource create(JasperReport report) throws JRException 109 { 110 JRCsvDataSource ds; 111 if (reader != null) 112 ds = new JRCsvDataSource(reader); 113 else { 114 throw new JRException("Cannot find a source to read the data from"); 115 } 116 117 ds.setDateFormat(dateFormat); 118 ds.setNumberFormat(numberFormat); 119 ds.setFieldDelimiter(fieldDelimiter); 120 ds.setRecordDelimiter(recordDelimiter); 121 ds.setColumnNames(columnNames); 122 123 return ds; 124 } 125 126 127 130 public void dispose(JRDataSource dataSource) throws JRException 131 { 132 } 133 134 public String [] getColumnNames() 135 { 136 return columnNames; 137 } 138 139 public void setColumnNames(String [] columnNames) 140 { 141 this.columnNames = columnNames; 142 } 143 144 public DateFormat getDateFormat() 145 { 146 return dateFormat; 147 } 148 149 public void setDateFormat(DateFormat dateFormat) 150 { 151 this.dateFormat = dateFormat; 152 } 153 154 public char getFieldDelimiter() 155 { 156 return fieldDelimiter; 157 } 158 159 public void setFieldDelimiter(char fieldDelimiter) 160 { 161 this.fieldDelimiter = fieldDelimiter; 162 } 163 164 public String getRecordDelimiter() 165 { 166 return recordDelimiter; 167 } 168 169 public void setRecordDelimiter(String recordDelimiter) 170 { 171 this.recordDelimiter = recordDelimiter; 172 } 173 174 175 public NumberFormat getNumberFormat() 176 { 177 return numberFormat; 178 } 179 180 181 public void setNumberFormat(NumberFormat numberFormat) 182 { 183 this.numberFormat = numberFormat; 184 } 185 } 186 | Popular Tags |