|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfr.paris.lutece.portal.service.csv.CSVReaderService
public abstract class CSVReaderService
Service to get data from a CSV file. The CSV might be a physical file, or a memory file. Implementations can either be statefull or stateless, but if the separator or the escape character are controlled by the user, then it has to be statefull.
Constructor Summary | |
---|---|
CSVReaderService()
|
Method Summary | |
---|---|
protected List<CSVMessageDescriptor> |
checkCSVFileValidity(List<String[]> listLines,
int nColumnNumber,
boolean bSkipFirstLine,
Locale locale)
Check the validity of the whole CSV file. |
protected List<CSVMessageDescriptor> |
checkCSVLineColumnNumber(String[] strLine,
int nColumnNumber,
int nLineNumber,
Locale locale)
Check the number of columns of a line. |
protected abstract List<CSVMessageDescriptor> |
checkLineOfCSVFile(String[] strLineDataArray,
int nLineNumber,
Locale locale)
Check the line of the CSV file. |
Character |
getCSVEscapeCharacter()
Get the escape character used for CSV files. |
Character |
getCSVSeparator()
Get the separator used for CSV files. |
static Character |
getDefaultCSVEscapeCharacter()
Get the default CSV escape character to use. |
static Character |
getDefaultCSVSeparator()
Get the default CSV separator to use. |
protected abstract List<CSVMessageDescriptor> |
getEndOfProcessMessages(int nNbLineParses,
int nNbLinesWithoutErrors,
Locale locale)
Get messages after the process is completed. |
List<CSVMessageDescriptor> |
readCSVFile(File file,
int nColumnNumber,
boolean bCheckFileBeforeProcessing,
boolean bExitOnError,
boolean bSkipFirstLine,
Locale locale,
String strBaseUrl)
Read a CSV file and call the method readLineOfCSVFile for
each of its lines. |
List<CSVMessageDescriptor> |
readCSVFile(org.apache.commons.fileupload.FileItem fileItem,
int nColumnNumber,
boolean bCheckFileBeforeProcessing,
boolean bExitOnError,
boolean bSkipFirstLine,
Locale locale,
String strBaseUrl)
Read a CSV file and call the method readLineOfCSVFile for
each of its lines. |
List<CSVMessageDescriptor> |
readCSVFile(PhysicalFile physicalFile,
int nColumnNumber,
boolean bCheckFileBeforeProcessing,
boolean bExitOnError,
boolean bSkipFirstLine,
Locale locale,
String strBaseUrl)
Read a CSV file and call the method readLineOfCSVFile for
each of its lines. |
protected List<CSVMessageDescriptor> |
readCSVFile(Reader reader,
au.com.bytecode.opencsv.CSVReader csvReader,
int nColumnNumber,
boolean bCheckFileBeforeProcessing,
boolean bExitOnError,
boolean bSkipFirstLine,
Locale locale,
String strBaseUrl)
Read a CSV file and call the method readLineOfCSVFile for each
of its lines. |
List<CSVMessageDescriptor> |
readCSVFile(String strPath,
int nColumnNumber,
boolean bCheckFileBeforeProcessing,
boolean bExitOnError,
boolean bSkipFirstLine,
Locale locale,
String strBaseUrl)
Read a CSV file and call the method readLineOfCSVFile for
each of its lines. |
protected abstract List<CSVMessageDescriptor> |
readLineOfCSVFile(String[] strLineDataArray,
int nLineNumber,
Locale locale,
String strBaseUrl)
Read a line of the CSV file. |
void |
setCSVEscapeCharacter(Character strCSVEscapeCharacter)
Set the escape character to use for CSV files. |
void |
setCSVSeparator(Character strCSVSeparator)
Set the separator to use for CSV files. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CSVReaderService()
Method Detail |
---|
protected abstract List<CSVMessageDescriptor> readLineOfCSVFile(String[] strLineDataArray, int nLineNumber, Locale locale, String strBaseUrl)
strLineDataArray
- The content of the line of the CSV file.nLineNumber
- Number of the current linelocale
- the localestrBaseUrl
- The base URL
protected abstract List<CSVMessageDescriptor> checkLineOfCSVFile(String[] strLineDataArray, int nLineNumber, Locale locale)
strLineDataArray
- The content of the line of the CSV file.nLineNumber
- Number of the current linelocale
- the locale
INFO
will NOT be processed, and the
global processing may stop if the ExitOnError flag has been set
to true !protected abstract List<CSVMessageDescriptor> getEndOfProcessMessages(int nNbLineParses, int nNbLinesWithoutErrors, Locale locale)
nNbLineParses
- The number of lines parses. If the first line was
skipped, it is not counted.nNbLinesWithoutErrors
- the number of lines parses whitout error.locale
- The locale
public static Character getDefaultCSVSeparator()
public static Character getDefaultCSVEscapeCharacter()
public List<CSVMessageDescriptor> readCSVFile(org.apache.commons.fileupload.FileItem fileItem, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, Locale locale, String strBaseUrl)
readLineOfCSVFile
for
each of its lines.
fileItem
- FileItem to get the CSV file from. If the creation of the
input stream associated to this file throws a IOException,
then an error is returned and the file is not red.nColumnNumber
- Number of columns of each lines. Use 0 to skip
column number check (for example if every lines don't have the
same number of columns)bCheckFileBeforeProcessing
- Indicates if the file should be check
before processing any of its line. If it is set to true, then
then no line is processed if the file has any error.bExitOnError
- Indicates if the processing of the CSV file should
end on the first error, or at the end of the file.bSkipFirstLine
- Indicates if the first line of the file should be
skipped or not.locale
- the localestrBaseUrl
- The base URL
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information
about sort
public List<CSVMessageDescriptor> readCSVFile(String strPath, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, Locale locale, String strBaseUrl)
readLineOfCSVFile
for
each of its lines.
strPath
- Path if the file to read in the file system.nColumnNumber
- Number of columns of each lines. Use 0 to skip
column number check (for example if every lines don't have the
same number of columns)bCheckFileBeforeProcessing
- Indicates if the file should be check
before processing any of its line. If it is set to true, then
then no line is processed if the file has any error.bExitOnError
- Indicates if the processing of the CSV file should
end on the first error, or at the end of the file.bSkipFirstLine
- Indicates if the first line of the file should be
skipped or not.locale
- the localestrBaseUrl
- The base URL
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information
about sort
public List<CSVMessageDescriptor> readCSVFile(File file, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, Locale locale, String strBaseUrl)
readLineOfCSVFile
for
each of its lines.
file
- File to get the values from. If the physical file of this
file has no value, then it is gotten from the database.nColumnNumber
- Number of columns of each lines. Use 0 to skip
column number check (for example if every lines don't have the
same number of columns)bCheckFileBeforeProcessing
- Indicates if the file should be check
before processing any of its line. If it is set to true, then
then no line is processed if the file has any error.bExitOnError
- Indicates if the processing of the CSV file should
end on the first error, or at the end of the file.bSkipFirstLine
- Indicates if the first line of the file should be
skipped or not.locale
- the localestrBaseUrl
- The base URL
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information
about sort
public List<CSVMessageDescriptor> readCSVFile(PhysicalFile physicalFile, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, Locale locale, String strBaseUrl)
readLineOfCSVFile
for
each of its lines.
physicalFile
- The physicalFile to get the values from. If the
physical file has no value, then it is gotten from the
database.nColumnNumber
- Number of columns of each lines. Use 0 to skip
column number check (for example if every lines don't have the
same number of columns)bCheckFileBeforeProcessing
- Indicates if the file should be check
before processing any of its line. If it is set to true, then
then no line is processed if the file has any error.bExitOnError
- Indicates if the processing of the CSV file should
end on the first error, or at the end of the file.bSkipFirstLine
- Indicates if the first line of the file should be
skipped or not.locale
- the localestrBaseUrl
- The base URL
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information
about sort
protected List<CSVMessageDescriptor> readCSVFile(Reader reader, au.com.bytecode.opencsv.CSVReader csvReader, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, Locale locale, String strBaseUrl)
readLineOfCSVFile
for each
of its lines.
reader
- The file reader that was used to create the CSV reader.
This reader will be closed by this methodcsvReader
- CSV reader to use to read the CSV filenColumnNumber
- Number of columns of each lines. Use 0 to skip
column number check (for example if every lines don't have the
same number of columns)bCheckFileBeforeProcessing
- Indicates if the file should be check
before processing any of its line. If it is set to true, then
then no line is processed if the file has any error.bExitOnError
- Indicates if the processing of the CSV file should
end on the first error, or at the end of the file.bSkipFirstLine
- Indicates if the first line of the file should be
skipped or not.locale
- the localestrBaseUrl
- The base URL
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information
about sort
protected List<CSVMessageDescriptor> checkCSVFileValidity(List<String[]> listLines, int nColumnNumber, boolean bSkipFirstLine, Locale locale)
listLines
- The list of lines of the filenColumnNumber
- The number of columns every line must have.bSkipFirstLine
- True if the first line should be ignored, false
otherwiselocale
- The locale
protected List<CSVMessageDescriptor> checkCSVLineColumnNumber(String[] strLine, int nColumnNumber, int nLineNumber, Locale locale)
strLine
- The line to checknColumnNumber
- The number of columns the line must havenLineNumber
- The number of the current linelocale
- The locale
public Character getCSVSeparator()
public void setCSVSeparator(Character strCSVSeparator)
strCSVSeparator
- The separator to use for CSV files.public Character getCSVEscapeCharacter()
public void setCSVEscapeCharacter(Character strCSVEscapeCharacter)
strCSVEscapeCharacter
- The escape character to use for CSV files.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |