public class JRCsvDataSource extends JRAbstractTextDataSource
Since CSV does not specify column names, the default naming convention is to name report fields COLUMN_x and map each column with the field found at index x in each row (these indices start with 0). To avoid this situation, users can either specify a collection of column names or set a flag to read the column names from the first row of the CSV file.
Modifier and Type | Field and Description |
---|---|
static String |
EXCEPTION_MESSAGE_KEY_CSV_FIELD_VALUE_NOT_RETRIEVED |
static String |
EXCEPTION_MESSAGE_KEY_MALFORMED_QUOTED_FIELD |
static String |
EXCEPTION_MESSAGE_KEY_MISPLACED_QUOTE |
static String |
EXCEPTION_MESSAGE_KEY_NO_MORE_CHARS |
static String |
INDEXED_COLUMN_PREFIX |
protected static org.apache.commons.logging.Log |
log |
static String |
PROPERTY_FIELD_COLUMN_INDEX
Property specifying the CSV column index for the dataset field.
|
static String |
PROPERTY_FIELD_COLUMN_NAME
Property specifying the CSV column name for the dataset field.
|
EXCEPTION_MESSAGE_KEY_CANNOT_CONVERT_FIELD_TYPE, EXCEPTION_MESSAGE_KEY_CANNOT_MODIFY_PROPERTIES_AFTER_START, EXCEPTION_MESSAGE_KEY_NODE_NOT_AVAILABLE, EXCEPTION_MESSAGE_KEY_NULL_DOCUMENT, EXCEPTION_MESSAGE_KEY_NULL_SELECT_EXPRESSION, EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME, EXCEPTION_MESSAGE_KEY_UNKNOWN_NUMBER_TYPE
Constructor and Description |
---|
JRCsvDataSource(File file)
Creates a datasource instance from a CSV file, using the default encoding.
|
JRCsvDataSource(File file,
String charsetName)
Creates a datasource instance from a CSV file, using the specified encoding.
|
JRCsvDataSource(InputStream stream)
Creates a datasource instance from a CSV data input stream, using the default encoding.
|
JRCsvDataSource(InputStream stream,
String charsetName)
Creates a datasource instance from a CSV data input stream, using the specified encoding.
|
JRCsvDataSource(JasperReportsContext jasperReportsContext,
String location)
Creates a datasource instance that reads CSV data from a given location, using the default encoding.
|
JRCsvDataSource(JasperReportsContext jasperReportsContext,
String location,
String charsetName)
Creates a datasource instance that reads CSV data from a given location, using the specified encoding.
|
JRCsvDataSource(Reader reader)
Creates a datasource instance from a CSV data reader.
|
JRCsvDataSource(RepositoryContext context,
String location) |
JRCsvDataSource(RepositoryContext context,
String location,
String charsetName) |
JRCsvDataSource(String location) |
JRCsvDataSource(String location,
String charsetName) |
JRCsvDataSource(URL url)
Creates a datasource instance that reads CSV data from a given URL, using the default encoding.
|
JRCsvDataSource(URL url,
String charsetName)
Creates a datasource instance that reads CSV data from a given URL, using the specified encoding.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assignColumnNames() |
void |
close()
Closes the reader.
|
Map<String,Integer> |
getColumnNames() |
DateFormat |
getDateFormat()
Gets the date format that will be used to parse date fields
|
char |
getFieldDelimiter()
Returns the field delimiter character.
|
Object |
getFieldValue(JRField jrField)
Gets the field value for the current position.
|
NumberFormat |
getNumberFormat() |
String |
getRecordDelimiter()
Returns the record delimiter string.
|
boolean |
next()
Tries to position the cursor on the next element in the data source.
|
void |
setColumnNames(String[] columnNames)
Specifies an array of strings representing column names matching field names in the report template
|
void |
setDateFormat(DateFormat dateFormat)
Sets the desired date format to be used for parsing date fields
|
void |
setFieldDelimiter(char fieldDelimiter)
Sets the field delimiter character.
|
void |
setNumberFormat(NumberFormat numberFormat) |
void |
setRecordDelimiter(String recordDelimiter)
Sets the record delimiter string.
|
void |
setUseFirstRowAsHeader(boolean useFirstRowAsHeader)
Specifies whether the first line of the CSV file should be considered a table
header, containing column names matching field names in the report template
|
convertNumber, convertStringValue, getConvertBean, getDatePattern, getFormattedDate, getFormattedNumber, getLocale, getNumberPattern, getTextAttributes, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTextAttributes, setTimeZone, setTimeZone
protected static final org.apache.commons.logging.Log log
public static final String EXCEPTION_MESSAGE_KEY_CSV_FIELD_VALUE_NOT_RETRIEVED
public static final String EXCEPTION_MESSAGE_KEY_MALFORMED_QUOTED_FIELD
public static final String EXCEPTION_MESSAGE_KEY_MISPLACED_QUOTE
public static final String EXCEPTION_MESSAGE_KEY_NO_MORE_CHARS
public static final String PROPERTY_FIELD_COLUMN_NAME
public static final String PROPERTY_FIELD_COLUMN_INDEX
public static final String INDEXED_COLUMN_PREFIX
public JRCsvDataSource(InputStream stream)
stream
- an input stream containing CSV datapublic JRCsvDataSource(InputStream stream, String charsetName) throws UnsupportedEncodingException
stream
- an input stream containing CSV datacharsetName
- the encoding to useUnsupportedEncodingException
public JRCsvDataSource(URL url) throws IOException
url
- an URL from where to read CSV dataIOException
public JRCsvDataSource(URL url, String charsetName) throws IOException
url
- an URL from where to read CSV dataIOException
public JRCsvDataSource(File file) throws FileNotFoundException
file
- a file containing CSV dataFileNotFoundException
public JRCsvDataSource(File file, String charsetName) throws FileNotFoundException, UnsupportedEncodingException
file
- a file containing CSV datacharsetName
- the encoding to useFileNotFoundException
UnsupportedEncodingException
public JRCsvDataSource(JasperReportsContext jasperReportsContext, String location) throws JRException
jasperReportsContext
- the JasperReportsContextlocation
- a String representing CSV data sourceJRException
public JRCsvDataSource(RepositoryContext context, String location) throws JRException
JRException
public JRCsvDataSource(JasperReportsContext jasperReportsContext, String location, String charsetName) throws JRException, UnsupportedEncodingException
jasperReportsContext
- the JasperReportsContextlocation
- a String representing CSV data sourcecharsetName
- the encoding to useJRException
UnsupportedEncodingException
public JRCsvDataSource(RepositoryContext context, String location, String charsetName) throws JRException, UnsupportedEncodingException
public JRCsvDataSource(String location) throws JRException
JRException
JRCsvDataSource(JasperReportsContext, String)
public JRCsvDataSource(String location, String charsetName) throws JRException, UnsupportedEncodingException
public JRCsvDataSource(Reader reader)
reader
- a Reader instance, for reading the streampublic boolean next() throws JRException
JRDataSource
JRException
- if any error occurs while trying to move to the next elementprotected void assignColumnNames()
public Object getFieldValue(JRField jrField) throws JRException
JRDataSource
JRException
public DateFormat getDateFormat()
public void setDateFormat(DateFormat dateFormat)
public char getFieldDelimiter()
public void setFieldDelimiter(char fieldDelimiter)
fieldDelimiter
- public String getRecordDelimiter()
public void setRecordDelimiter(String recordDelimiter)
recordDelimiter
- public void setColumnNames(String[] columnNames)
public void setUseFirstRowAsHeader(boolean useFirstRowAsHeader)
public void close()
public NumberFormat getNumberFormat()
public void setNumberFormat(NumberFormat numberFormat)
Copyright © 2020 TIBCO Software Inc.. All rights reserved.