Class CSVReaderService

java.lang.Object
fr.paris.lutece.portal.service.csv.CSVReaderService
Direct Known Subclasses:
ImportAdminUserService

public abstract class CSVReaderService extends Object
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 Details

    • CSVReaderService

      public CSVReaderService()
  • Method Details

    • getDefaultCSVSeparator

      public static 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 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 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.
      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 locale
      strBaseUrl - The base URL
      Returns:
      Returns the list of errors that occurred during the processing of the file. The returned list is sorted
      See Also:
    • readCSVFile

      public 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.
      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 locale
      strBaseUrl - The base URL
      Returns:
      Returns the list of errors that occurred during the processing of the file. The returned list is sorted
      See Also:
    • readCSVFile

      public 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.
      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 locale
      strBaseUrl - The base URL
      Returns:
      Returns the list of errors that occurred during the processing of the file. The returned list is sorted
      See Also:
    • readCSVFile

      public 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.
      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 locale
      strBaseUrl - The base URL
      Returns:
      Returns the list of errors that occurred during the processing of the file. The returned list is sorted
      See Also:
    • getCSVSeparator

      public 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(Character strCSVSeparator)
      Set the separator to use for CSV files.
      Parameters:
      strCSVSeparator - The separator to use for CSV files.
    • getCSVEscapeCharacter

      public 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(Character strCSVEscapeCharacter)
      Set the escape character to use for CSV files.
      Parameters:
      strCSVEscapeCharacter - The escape character to use for CSV files.