Class XLSFileReader
java.lang.Object
com.broadleafcommerce.dataimport.processor.xls.XLSFileReader
- All Implemented Interfaces:
FileReader<XLSFileReader.XLSFileReaderContext>
A reader that knows how to parse out records from an Excel sheet
- Author:
- Phillip Verheyden (phillipuniverse)
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionXLSFileReader
(String sheetTitle) XLSFileReader
(String sheetTitle, org.apache.poi.ss.usermodel.DataFormatter formatter) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether or not this reader is applicable for the current contextlong
countTotalItems
(InputStream file) Counts all of the data records within the file.createParsingContext
(InputStream fileStream, long dataLinesToSkip) Creates a parsing context that is passed back throughout the rest of the parsing flows.long
The current line that the context is pointing to, 1-indexedString[]
Obtains the headers for the given contextboolean
Whether or not there are more data records to read as determined bycontext
.Returns the next row of data.
-
Constructor Details
-
XLSFileReader
-
XLSFileReader
-
-
Method Details
-
canHandle
Description copied from interface:FileReader
Whether or not this reader is applicable for the current context- Specified by:
canHandle
in interfaceFileReader<XLSFileReader.XLSFileReaderContext>
- Parameters:
fileType
- type of the file that should be read- Returns:
- whether or not this can handle the given file type
-
countTotalItems
Description copied from interface:FileReader
Counts all of the data records within the file. This should not include all of the physical lines within the file. For instance this should not include the header line or any lines that are denoted as comments- Specified by:
countTotalItems
in interfaceFileReader<XLSFileReader.XLSFileReaderContext>
- Parameters:
file
- file to count records for- Returns:
- the total number of data records in the file
-
createParsingContext
public XLSFileReader.XLSFileReaderContext createParsingContext(InputStream fileStream, long dataLinesToSkip) throws IOException Description copied from interface:FileReader
Creates a parsing context that is passed back throughout the rest of the parsing flows. This must be invoked before attempting to invoke the parsing logic, but is not required for couting records in the file. Any data necessary to read off items, open additional resources, etc should be initialized here and stored within the returned context- Specified by:
createParsingContext
in interfaceFileReader<XLSFileReader.XLSFileReaderContext>
- Parameters:
fileStream
- the underlying file that should be read fromdataLinesToSkip
- how many lines should be skipped from the read in file. Assuming there is a header line, given a current line number the lines to skip should subtract 2- Returns:
- a context with reader-specific variables passed back through the lifecycle of the processing flow
- Throws:
IOException
-
getHeaders
Description copied from interface:FileReader
Obtains the headers for the given context- Specified by:
getHeaders
in interfaceFileReader<XLSFileReader.XLSFileReaderContext>
- Parameters:
context
- the context initialized byFileReader.createParsingContext(InputStream, long)
- Returns:
- the headers from the file
-
currentLineNumber
Description copied from interface:FileReader
The current line that the context is pointing to, 1-indexed- Specified by:
currentLineNumber
in interfaceFileReader<XLSFileReader.XLSFileReaderContext>
- Parameters:
context
- the context initialized byFileReader.createParsingContext(InputStream, long)
- Returns:
- the current line number that this reader is pointing to based on the context
-
readNextLine
Description copied from interface:FileReader
Returns the next row of data. Keys correspond to the headers and values are the specific values for those headers- Specified by:
readNextLine
in interfaceFileReader<XLSFileReader.XLSFileReaderContext>
- Parameters:
context
- the context initialized byFileReader.createParsingContext(InputStream, long)
- Returns:
- a row of data from the file specified by
context
-
hasNext
Description copied from interface:FileReader
Whether or not there are more data records to read as determined bycontext
. Should be used as a guard againstFileReader.readNextLine(FileReaderContext)
to protect against an attempt at reading too far- Specified by:
hasNext
in interfaceFileReader<XLSFileReader.XLSFileReaderContext>
- Parameters:
context
- the context initialized byFileReader.createParsingContext(InputStream, long)
- Returns:
- whether or not there are more data records to read
-