nl.bstoi.poiparser.core.strategy
Class AbstractPoiFileParser<T>

java.lang.Object
  extended by nl.bstoi.poiparser.core.strategy.AbstractPoiFileParser<T>
Direct Known Subclasses:
AnnotatedPoiFileParser

public abstract class AbstractPoiFileParser<T>
extends Object


Constructor Summary
AbstractPoiFileParser()
           
AbstractPoiFileParser(Map<String,Integer> columnFieldNameMapping)
           
AbstractPoiFileParser(Map<String,Integer> columnFieldNameMapping, Set<Integer> requiredFields)
           
 
Method Summary
 void addColumnFieldNameMapping(String fieldName, Integer columnNumber)
          Add a mapping for a column
 void addReadIgnoreColumn(Integer columnNumber)
          Add a column number for ignoring when reading.
 void addRequiredField(Integer columnNumber)
          Add the column number for a required field
 void addWriteIgnoreColumn(Integer columnNumber)
          Add a column number for ignoring when writing.
 Map<String,Integer> getColumnFieldNameMapping()
           
 DefaultConverterFactory getDefaultConverterFactory()
           
 Map<String,String> getHeaderFieldNameTranslationMapping()
           
 Set<Integer> getReadIgnoreColumns()
           
 Set<Integer> getWriteIgnoreColumns()
           
 boolean ignoreRow(org.apache.poi.ss.usermodel.Row row)
          If row is empty, the ignore empty row setting will determine the adding of the row.
 boolean isEmptyRow(org.apache.poi.ss.usermodel.Row row)
          Check whether a row is empty based on the column values
 boolean isEmptyValue(org.apache.poi.ss.usermodel.Cell cell)
          Check if the hssfCell is empty or blank
 boolean isIgnoreEmptyRows()
           
 boolean isIgnoreFirstRow()
           
 boolean isRemoveWriteIgnoreColumns()
          If columns that are ignored must be deleted from the sheet when writing.
abstract  List<T> readExcelFile(File excelFile, String sheetName, Class<T> clazz)
           
abstract  List<T> readExcelFile(File excelFile, String sheetName, Class<T> clazz, int startRow)
          Read a excel file from start row to last row.
abstract  List<T> readExcelFile(File excelFile, String sheetName, Class<T> clazz, int startRow, int endRow)
          Read a excel file from start row to end row
abstract  List<T> readExcelFile(InputStream inputStream, String sheetName, Class<T> clazz)
           
abstract  List<T> readExcelFile(InputStream inputStream, String sheetName, Class<T> clazz, int startRow)
          Read a excel file input stream from given start row until last row
abstract  List<T> readExcelFile(InputStream inputStream, String sheetName, Class<T> clazz, int startRow, int endRow)
          Read a excel file inputstream start row to end row
protected  void readField(String sheetName, org.apache.poi.ss.usermodel.Row row, T rowDimension, String fieldName)
          Read a specific field and fill it with the value in the excel
protected  T readRow(String sheetName, org.apache.poi.ss.usermodel.Row row, T rowDimension)
          Read a excel row and convert the selected field into a row dimension
protected  List<T> readSheet(org.apache.poi.ss.usermodel.Sheet sheet, Class<T> clazz)
          Read Excel sheet.
protected  List<T> readSheet(org.apache.poi.ss.usermodel.Sheet sheet, Class<T> clazz, int startRow)
           
protected  List<T> readSheet(org.apache.poi.ss.usermodel.Sheet sheet, Class<T> clazz, int startRow, int endRow)
           
protected  void remapColumnFieldMapForWriting()
          Re-map the columns when empty columns are ignored
 void setHeaderFieldNameTranslationMapping(Map<String,String> headerFieldNameTranslationMapping)
           
 void setIgnoreEmptyRows(boolean ignoreEmptyRows)
           
 void setIgnoreFirstRow(boolean ignoreFirstRow)
           
 void setRemoveWriteIgnoreColumns(boolean removeWriteIgnoreColumns)
          Set if the parser deletes the columns when writing a sheet.
protected  void validateColumnFieldMapForWriting()
          Validate if columns are used more than once.
protected  void writeCell(org.apache.poi.ss.usermodel.Row row, T dimension, String fieldName)
           
abstract  void writeExcelFile(OutputStream outputStream, LinkedHashMap<String,List<T>> excelDataMap, Class<T> clazz)
           
protected  void writeHeaderRow(org.apache.poi.ss.usermodel.Sheet sheet, Integer rowNumber)
           
protected  void writeRow(org.apache.poi.ss.usermodel.Sheet sheet, T dimension, Integer rowNumber)
           
protected  void writeSheet(org.apache.poi.ss.usermodel.Workbook workbook, String sheetName, List<T> dimensionList)
           
protected  org.apache.poi.ss.usermodel.Workbook writeWorkbook(LinkedHashMap<String,List<T>> excelDataMap)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPoiFileParser

public AbstractPoiFileParser()

AbstractPoiFileParser

public AbstractPoiFileParser(Map<String,Integer> columnFieldNameMapping)

AbstractPoiFileParser

public AbstractPoiFileParser(Map<String,Integer> columnFieldNameMapping,
                             Set<Integer> requiredFields)
Method Detail

readExcelFile

public abstract List<T> readExcelFile(File excelFile,
                                      String sheetName,
                                      Class<T> clazz)
                               throws IOException,
                                      FileNotFoundException,
                                      InstantiationException,
                                      IllegalAccessException,
                                      RequiredFieldPoiParserException,
                                      ReadPoiParserException
Throws:
IOException
FileNotFoundException
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readExcelFile

public abstract List<T> readExcelFile(InputStream inputStream,
                                      String sheetName,
                                      Class<T> clazz)
                               throws IOException,
                                      FileNotFoundException,
                                      InstantiationException,
                                      IllegalAccessException,
                                      RequiredFieldPoiParserException,
                                      ReadPoiParserException
Throws:
IOException
FileNotFoundException
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readExcelFile

public abstract List<T> readExcelFile(File excelFile,
                                      String sheetName,
                                      Class<T> clazz,
                                      int startRow,
                                      int endRow)
                               throws IOException,
                                      FileNotFoundException,
                                      InstantiationException,
                                      IllegalAccessException,
                                      RequiredFieldPoiParserException,
                                      ReadPoiParserException
Read a excel file from start row to end row

Parameters:
excelFile -
sheetName -
clazz -
startRow -
endRow -
Returns:
Throws:
IOException
FileNotFoundException
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readExcelFile

public abstract List<T> readExcelFile(File excelFile,
                                      String sheetName,
                                      Class<T> clazz,
                                      int startRow)
                               throws IOException,
                                      FileNotFoundException,
                                      InstantiationException,
                                      IllegalAccessException,
                                      RequiredFieldPoiParserException,
                                      ReadPoiParserException
Read a excel file from start row to last row.

Parameters:
excelFile -
sheetName -
clazz -
startRow -
Returns:
Throws:
IOException
FileNotFoundException
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readExcelFile

public abstract List<T> readExcelFile(InputStream inputStream,
                                      String sheetName,
                                      Class<T> clazz,
                                      int startRow,
                                      int endRow)
                               throws IOException,
                                      FileNotFoundException,
                                      InstantiationException,
                                      IllegalAccessException,
                                      RequiredFieldPoiParserException,
                                      ReadPoiParserException
Read a excel file inputstream start row to end row

Parameters:
inputStream -
sheetName -
clazz -
startRow -
endRow -
Returns:
Throws:
IOException
FileNotFoundException
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readExcelFile

public abstract List<T> readExcelFile(InputStream inputStream,
                                      String sheetName,
                                      Class<T> clazz,
                                      int startRow)
                               throws IOException,
                                      FileNotFoundException,
                                      InstantiationException,
                                      IllegalAccessException,
                                      RequiredFieldPoiParserException,
                                      ReadPoiParserException
Read a excel file input stream from given start row until last row

Parameters:
inputStream -
sheetName -
clazz -
startRow -
Returns:
Throws:
IOException
FileNotFoundException
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

writeExcelFile

public abstract void writeExcelFile(OutputStream outputStream,
                                    LinkedHashMap<String,List<T>> excelDataMap,
                                    Class<T> clazz)
                             throws IOException,
                                    InitialWritePoiParserException,
                                    WritePoiParserException
Throws:
IOException
InitialWritePoiParserException
WritePoiParserException

readSheet

protected List<T> readSheet(org.apache.poi.ss.usermodel.Sheet sheet,
                            Class<T> clazz)
                     throws InstantiationException,
                            IllegalAccessException,
                            RequiredFieldPoiParserException,
                            ReadPoiParserException
Read Excel sheet.

Parameters:
sheet -
clazz -
Returns:
Throws:
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readSheet

protected List<T> readSheet(org.apache.poi.ss.usermodel.Sheet sheet,
                            Class<T> clazz,
                            int startRow)
                     throws InstantiationException,
                            IllegalAccessException,
                            RequiredFieldPoiParserException,
                            ReadPoiParserException
Throws:
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readSheet

protected List<T> readSheet(org.apache.poi.ss.usermodel.Sheet sheet,
                            Class<T> clazz,
                            int startRow,
                            int endRow)
                     throws InstantiationException,
                            IllegalAccessException,
                            RequiredFieldPoiParserException,
                            ReadPoiParserException
Throws:
InstantiationException
IllegalAccessException
RequiredFieldPoiParserException
ReadPoiParserException

readRow

protected T readRow(String sheetName,
                    org.apache.poi.ss.usermodel.Row row,
                    T rowDimension)
             throws RequiredFieldPoiParserException,
                    ReadPoiParserException

Read a excel row and convert the selected field into a row dimension

Parameters:
row -
rowDimension -
Returns:
Throws:
RequiredFieldPoiParserException
ReadPoiParserException

readField

protected void readField(String sheetName,
                         org.apache.poi.ss.usermodel.Row row,
                         T rowDimension,
                         String fieldName)
                  throws RequiredFieldPoiParserException,
                         ReadPoiParserException

Read a specific field and fill it with the value in the excel

Parameters:
row - Excel row
rowDimension - Abstract representation of a row
fieldName - Name of a field in the class
Throws:
RequiredFieldPoiParserException
ReadPoiParserException

writeWorkbook

protected org.apache.poi.ss.usermodel.Workbook writeWorkbook(LinkedHashMap<String,List<T>> excelDataMap)
                                                      throws InitialWritePoiParserException,
                                                             WritePoiParserException
Throws:
InitialWritePoiParserException
WritePoiParserException

writeSheet

protected void writeSheet(org.apache.poi.ss.usermodel.Workbook workbook,
                          String sheetName,
                          List<T> dimensionList)
                   throws WritePoiParserException
Throws:
WritePoiParserException

writeRow

protected void writeRow(org.apache.poi.ss.usermodel.Sheet sheet,
                        T dimension,
                        Integer rowNumber)
                 throws WritePoiParserException
Throws:
WritePoiParserException

writeHeaderRow

protected void writeHeaderRow(org.apache.poi.ss.usermodel.Sheet sheet,
                              Integer rowNumber)

writeCell

protected void writeCell(org.apache.poi.ss.usermodel.Row row,
                         T dimension,
                         String fieldName)
                  throws WritePoiParserException
Throws:
WritePoiParserException

ignoreRow

public boolean ignoreRow(org.apache.poi.ss.usermodel.Row row)
If row is empty, the ignore empty row setting will determine the adding of the row.

Parameters:
hssfRow -
Returns:

isEmptyRow

public boolean isEmptyRow(org.apache.poi.ss.usermodel.Row row)
Check whether a row is empty based on the column values

Parameters:
hssfRow -
Returns:

isEmptyValue

public boolean isEmptyValue(org.apache.poi.ss.usermodel.Cell cell)
Check if the hssfCell is empty or blank

Parameters:
hssfCell -
Returns:

validateColumnFieldMapForWriting

protected void validateColumnFieldMapForWriting()
                                         throws InitialWritePoiParserException
Validate if columns are used more than once.

Throws:
InitialWritePoiParserException

remapColumnFieldMapForWriting

protected void remapColumnFieldMapForWriting()
                                      throws InitialWritePoiParserException
Re-map the columns when empty columns are ignored

Throws:
InitialWritePoiParserException

isIgnoreEmptyRows

public boolean isIgnoreEmptyRows()

setIgnoreEmptyRows

public void setIgnoreEmptyRows(boolean ignoreEmptyRows)

setIgnoreFirstRow

public void setIgnoreFirstRow(boolean ignoreFirstRow)

isIgnoreFirstRow

public boolean isIgnoreFirstRow()

isRemoveWriteIgnoreColumns

public boolean isRemoveWriteIgnoreColumns()
If columns that are ignored must be deleted from the sheet when writing.

Returns:

setRemoveWriteIgnoreColumns

public void setRemoveWriteIgnoreColumns(boolean removeWriteIgnoreColumns)
Set if the parser deletes the columns when writing a sheet.

Parameters:
removeWriteIgnoreColumns -

getColumnFieldNameMapping

public Map<String,Integer> getColumnFieldNameMapping()

getHeaderFieldNameTranslationMapping

public Map<String,String> getHeaderFieldNameTranslationMapping()

setHeaderFieldNameTranslationMapping

public void setHeaderFieldNameTranslationMapping(Map<String,String> headerFieldNameTranslationMapping)

addColumnFieldNameMapping

public void addColumnFieldNameMapping(String fieldName,
                                      Integer columnNumber)
Add a mapping for a column

Parameters:
fieldName -
columnNumber -

addRequiredField

public void addRequiredField(Integer columnNumber)
Add the column number for a required field

Parameters:
columnNumber -

addReadIgnoreColumn

public void addReadIgnoreColumn(Integer columnNumber)
Add a column number for ignoring when reading.

Parameters:
columnNumber -

addWriteIgnoreColumn

public void addWriteIgnoreColumn(Integer columnNumber)
Add a column number for ignoring when writing.

Parameters:
columnNumber -

getWriteIgnoreColumns

public Set<Integer> getWriteIgnoreColumns()

getReadIgnoreColumns

public Set<Integer> getReadIgnoreColumns()

getDefaultConverterFactory

public DefaultConverterFactory getDefaultConverterFactory()


Copyright © 2011 BSTOI.NL. All Rights Reserved.