org.springframework.batch.item.excel
Class AbstractExcelItemReader<T>

java.lang.Object
  extended by org.springframework.batch.item.ItemStreamSupport
      extended by org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
          extended by org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
              extended by org.springframework.batch.item.excel.AbstractExcelItemReader<T>
Type Parameters:
T - the type
All Implemented Interfaces:
org.springframework.batch.item.file.ResourceAwareItemReaderItemStream<T>, org.springframework.batch.item.ItemReader<T>, org.springframework.batch.item.ItemStream, org.springframework.batch.item.ItemStreamReader<T>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
JxlItemReader, PoiItemReader

public abstract class AbstractExcelItemReader<T>
extends org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
implements org.springframework.batch.item.file.ResourceAwareItemReaderItemStream<T>, org.springframework.beans.factory.InitializingBean

ItemReader implementation to read an Excel file. It will read the file sheet for sheet and row for row. It is loosy based on the FlatFileItemReader

Since:
0.5.0
Author:
Marten Deinum

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
AbstractExcelItemReader()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void doClose()
           
protected  void doOpen()
           
protected  T doRead()
           
protected abstract  int getNumberOfSheets()
          The number of sheets in the underlying workbook.
protected abstract  Sheet getSheet(int sheet)
           
protected  void jumpToItem(int itemIndex)
          On restart this will increment rowSet to where job left off previously
protected abstract  void openExcelFile(org.springframework.core.io.Resource resource)
           
 T read()
           
 void setEndAfterBlankLines(int endAfterBlankLines)
           
 void setLinesToSkip(int linesToSkip)
          Set the number of lines to skip.
 void setResource(org.springframework.core.io.Resource resource)
          Public setter for the input resource.
 void setRowMapper(RowMapper<T> rowMapper)
          Public setter for the rowMapper.
 void setRowSetFactory(RowSetFactory rowSetFactory)
          Public setter for the rowSetFactory.
 void setSkippedRowsCallback(RowCallbackHandler skippedRowsCallback)
           
 void setStrict(boolean strict)
          In strict mode the reader will throw an exception on AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext) if the input resource does not exist.
 
Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, setCurrentItemCount, setMaxItemCount, setSaveState, update
 
Methods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.batch.item.ItemStream
close, open, update
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

AbstractExcelItemReader

public AbstractExcelItemReader()
Method Detail

read

public T read()
       throws Exception,
              org.springframework.batch.item.UnexpectedInputException,
              org.springframework.batch.item.ParseException
Specified by:
read in interface org.springframework.batch.item.ItemReader<T>
Overrides:
read in class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception
org.springframework.batch.item.UnexpectedInputException
org.springframework.batch.item.ParseException

doRead

protected T doRead()
            throws Exception
Specified by:
doRead in class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
Returns:
string corresponding to logical record according to setRowMapper(RowMapper) (might span multiple rows in file).
Throws:
Exception

jumpToItem

protected void jumpToItem(int itemIndex)
                   throws Exception
On restart this will increment rowSet to where job left off previously

Overrides:
jumpToItem in class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

doOpen

protected void doOpen()
               throws Exception
Specified by:
doOpen in class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

doClose

protected void doClose()
                throws Exception
Specified by:
doClose in class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
Throws:
Exception

setResource

public void setResource(org.springframework.core.io.Resource resource)
Public setter for the input resource.

Specified by:
setResource in interface org.springframework.batch.item.file.ResourceAwareItemReaderItemStream<T>
Parameters:
resource - the Resource pointing to the Excelfile

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

setLinesToSkip

public void setLinesToSkip(int linesToSkip)
Set the number of lines to skip. This number is applied to all worksheet in the excel file! default to 0

Parameters:
linesToSkip - number of lines to skip

getSheet

protected abstract Sheet getSheet(int sheet)
Parameters:
sheet - the sheet index
Returns:
the sheet or null when no sheet available.

getNumberOfSheets

protected abstract int getNumberOfSheets()
The number of sheets in the underlying workbook.

Returns:
the number of sheets.

openExcelFile

protected abstract void openExcelFile(org.springframework.core.io.Resource resource)
                               throws Exception
Parameters:
resource - Resource pointing to the Excel file to read
Throws:
Exception - when the Excel sheet cannot be accessed

setStrict

public void setStrict(boolean strict)
In strict mode the reader will throw an exception on AbstractItemCountingItemStreamItemReader.open(org.springframework.batch.item.ExecutionContext) if the input resource does not exist.

Parameters:
strict - true by default

setRowMapper

public void setRowMapper(RowMapper<T> rowMapper)
Public setter for the rowMapper. Used to map a row read from the underlying Excel workbook.

Parameters:
rowMapper - the RowMapper to use.

setRowSetFactory

public void setRowSetFactory(RowSetFactory rowSetFactory)
Public setter for the rowSetFactory. Used to create a RowSet implemenation. By default the DefaultRowSetFactory is used.

Parameters:
rowSetFactory - the RowSetFactory to use.

setSkippedRowsCallback

public void setSkippedRowsCallback(RowCallbackHandler skippedRowsCallback)
Parameters:
skippedRowsCallback - will be called for each one of the initial skipped lines before any items are read.

setEndAfterBlankLines

public void setEndAfterBlankLines(int endAfterBlankLines)


Copyright © 2017. All rights reserved.