Class CSVReaderService
- java.lang.Object
-
- fr.paris.lutece.portal.service.csv.CSVReaderService
-
- Direct Known Subclasses:
ImportAdminUserService
public abstract class CSVReaderService extends java.lang.ObjectService 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
Constructors Constructor Description CSVReaderService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.CharactergetCSVEscapeCharacter()Get the escape character used for CSV files.java.lang.CharactergetCSVSeparator()Get the separator used for CSV files.static java.lang.CharactergetDefaultCSVEscapeCharacter()Get the default CSV escape character to use.static java.lang.CharactergetDefaultCSVSeparator()Get the default CSV separator to use.java.util.List<CSVMessageDescriptor>readCSVFile(File file, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.java.util.List<CSVMessageDescriptor>readCSVFile(PhysicalFile physicalFile, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.java.util.List<CSVMessageDescriptor>readCSVFile(java.lang.String strPath, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.java.util.List<CSVMessageDescriptor>readCSVFile(org.apache.commons.fileupload.FileItem fileItem, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.voidsetCSVEscapeCharacter(java.lang.Character strCSVEscapeCharacter)Set the escape character to use for CSV files.voidsetCSVSeparator(java.lang.Character strCSVSeparator)Set the separator to use for CSV files.
-
-
-
Method Detail
-
getDefaultCSVSeparator
public static java.lang.Character getDefaultCSVSeparator()
Get the default CSV separator to use. If the property of the default separator to use is not set, then the semi-colon is returned.- Returns:
- the default CSV separator to use
-
getDefaultCSVEscapeCharacter
public static java.lang.Character getDefaultCSVEscapeCharacter()
Get the default CSV escape character to use. If the property of the default escape character to use is not set, then the comma is returned.- Returns:
- the default CSV escape character to use
-
readCSVFile
public java.util.List<CSVMessageDescriptor> readCSVFile(org.apache.commons.fileupload.FileItem fileItem, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)
Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.- Parameters:
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- Returns:
- Returns the list of errors that occurred during the processing of the file. The returned list is sorted
- See Also:
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information about sort
-
readCSVFile
public java.util.List<CSVMessageDescriptor> readCSVFile(java.lang.String strPath, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)
Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.- Parameters:
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- Returns:
- Returns the list of errors that occurred during the processing of the file. The returned list is sorted
- See Also:
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information about sort
-
readCSVFile
public java.util.List<CSVMessageDescriptor> readCSVFile(File file, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)
Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.- Parameters:
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- Returns:
- Returns the list of errors that occurred during the processing of the file. The returned list is sorted
- See Also:
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information about sort
-
readCSVFile
public java.util.List<CSVMessageDescriptor> readCSVFile(PhysicalFile physicalFile, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, java.util.Locale locale, java.lang.String strBaseUrl)
Read a CSV file and call the methodreadLineOfCSVFilefor each of its lines.- Parameters:
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- Returns:
- Returns the list of errors that occurred during the processing of the file. The returned list is sorted
- See Also:
CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information about sort
-
getCSVSeparator
public java.lang.Character getCSVSeparator()
Get the separator used for CSV files. If no separator has been set, then the default CSV separator is used.- Returns:
- the separator used for CSV files, of the default one if non has been set.
-
setCSVSeparator
public void setCSVSeparator(java.lang.Character strCSVSeparator)
Set the separator to use for CSV files.- Parameters:
strCSVSeparator- The separator to use for CSV files.
-
getCSVEscapeCharacter
public java.lang.Character getCSVEscapeCharacter()
Get the escape character used for CSV files. If no escape character has been set, then the default CSV escape character is used.- Returns:
- the escape character used for CSV files, of the default one if non has been set.
-
setCSVEscapeCharacter
public void setCSVEscapeCharacter(java.lang.Character strCSVEscapeCharacter)
Set the escape character to use for CSV files.- Parameters:
strCSVEscapeCharacter- The escape character to use for CSV files.
-
-