Package net.sf.jasperreports.engine.data
Class JRCsvDataSourceProvider
- java.lang.Object
-
- net.sf.jasperreports.engine.data.JRCsvDataSourceProvider
-
- All Implemented Interfaces:
JRDataSourceProvider
public class JRCsvDataSourceProvider extends java.lang.Object implements JRDataSourceProvider
- Author:
- Ionut Nedelcu (ionutned@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEXCEPTION_MESSAGE_KEY_CANNOT_FIND_SOURCE
-
Constructor Summary
Constructors Constructor Description JRCsvDataSourceProvider(java.io.File file)Builds a datasource instance.JRCsvDataSourceProvider(java.io.InputStream stream)JRCsvDataSourceProvider(java.io.Reader reader)Builds a datasource instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JRDataSourcecreate(JasperReport report)Creates and returns a new instance of the provided data source.voiddispose(JRDataSource dataSource)Disposes the data source previously obtained using thecreatemethod.java.lang.String[]getColumnNames()java.text.DateFormatgetDateFormat()chargetFieldDelimiter()JRField[]getFields(JasperReport report)Returns the fields that are available from the data source.java.text.NumberFormatgetNumberFormat()java.lang.StringgetRecordDelimiter()voidsetColumnNames(java.lang.String[] colNames)voidsetDateFormat(java.text.DateFormat dateFormat)voidsetFieldDelimiter(char fieldDelimiter)voidsetNumberFormat(java.text.NumberFormat numberFormat)voidsetRecordDelimiter(java.lang.String recordDelimiter)booleansupportsGetFieldsOperation()Returns true if the provider supports thegetFieldsoperation.
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_CANNOT_FIND_SOURCE
public static final java.lang.String EXCEPTION_MESSAGE_KEY_CANNOT_FIND_SOURCE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JRCsvDataSourceProvider
public JRCsvDataSourceProvider(java.io.InputStream stream)
- Parameters:
stream- an input stream containing CSV data
-
JRCsvDataSourceProvider
public JRCsvDataSourceProvider(java.io.File file) throws java.io.FileNotFoundExceptionBuilds a datasource instance.- Parameters:
file- a file containing CSV data- Throws:
java.io.FileNotFoundException
-
JRCsvDataSourceProvider
public JRCsvDataSourceProvider(java.io.Reader reader)
Builds a datasource instance.- Parameters:
reader- a Reader instance, for reading the stream
-
-
Method Detail
-
supportsGetFieldsOperation
public boolean supportsGetFieldsOperation()
Description copied from interface:JRDataSourceProviderReturns true if the provider supports thegetFieldsoperation. By returning true in this method the data source provider indicates that it is able to introspect the data source and discover the available fields.- Specified by:
supportsGetFieldsOperationin interfaceJRDataSourceProvider- Returns:
- true if the getFields() operation is supported.
-
getFields
public JRField[] getFields(JasperReport report) throws JRException, java.lang.UnsupportedOperationException
Description copied from interface:JRDataSourceProviderReturns the fields that are available from the data source. The provider can use the passed in report to extract some additional configuration information such as report properties.- Specified by:
getFieldsin interfaceJRDataSourceProvider- Parameters:
report- the report that will be filled using the data source created by this provider. The passed in report can be null. That means that no compiled report is available yet.- Returns:
- a non null fields array. If there are no fields then an empty array must be returned.
- Throws:
JRException- if an error occurs.java.lang.UnsupportedOperationException- is the method is not supported
-
create
public JRDataSource create(JasperReport report) throws JRException
Description copied from interface:JRDataSourceProviderCreates and returns a new instance of the provided data source. The provider can use the passed in report to extract some additional configuration information such as report properties.- Specified by:
createin interfaceJRDataSourceProvider- Parameters:
report- the report that will be filled using the created data source.- Throws:
JRException- if the data source creation has failed
-
dispose
public void dispose(JRDataSource dataSource) throws JRException
Description copied from interface:JRDataSourceProviderDisposes the data source previously obtained using thecreatemethod. This method must close any resources associated with the data source. For instance the database connection should be closed in case of theJRResultSetDataSource.
Note: The provider must take care of the resource - data source association. For example in case of theJRResultSetDataSourcea subclass of this data source can be created. This subclass will hold the database connection and the prepared statement that were used to obtain the ResultSet. On the time of the dispose these resources can be retrieved from the data source object and closed.- Specified by:
disposein interfaceJRDataSourceProvider- Parameters:
dataSource- the data source to dispose- Throws:
JRException- if the data source could not be disposed
-
getColumnNames
public java.lang.String[] getColumnNames()
-
setColumnNames
public void setColumnNames(java.lang.String[] colNames)
-
getDateFormat
public java.text.DateFormat getDateFormat()
-
setDateFormat
public void setDateFormat(java.text.DateFormat dateFormat)
-
getFieldDelimiter
public char getFieldDelimiter()
-
setFieldDelimiter
public void setFieldDelimiter(char fieldDelimiter)
-
getRecordDelimiter
public java.lang.String getRecordDelimiter()
-
setRecordDelimiter
public void setRecordDelimiter(java.lang.String recordDelimiter)
-
getNumberFormat
public java.text.NumberFormat getNumberFormat()
-
setNumberFormat
public void setNumberFormat(java.text.NumberFormat numberFormat)
-
-