Class CSVExportFileWriter
- java.lang.Object
-
- com.broadleafcommerce.common.dataexport.service.CSVExportFileWriter
-
- All Implemented Interfaces:
ExportFileWriter<CSVExportFileWriteContext>
public class CSVExportFileWriter extends Object implements ExportFileWriter<CSVExportFileWriteContext>
An implementation ofExportFileWriter
that can write CSV files.- Author:
- Samarth Dhruva (samarthd)
-
-
Constructor Summary
Constructors Constructor Description CSVExportFileWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canHandle(Export export)
Returns whether the writer can support writing the file for the given export.CSVExportFileWriteContext
createExecutionContext(OutputStream outputStream)
Creates a new instance of anExportFileWriteContext
for writing to the givenoutputStream
.String
getFileExtension()
Returns the file extension that should be used for the export file that the writer will be writing to.ExportFileWriteResponse
writeHeaders(LinkedHashSet<String> headers, CSVExportFileWriteContext executionContext)
Writes the given headers to the output file.ExportFileWriteResponse
writeRows(List<Map<String,String>> rows, CSVExportFileWriteContext executionContext)
Writes the given rows to the export file.
-
-
-
Method Detail
-
canHandle
public boolean canHandle(Export export)
Description copied from interface:ExportFileWriter
Returns whether the writer can support writing the file for the given export. Generally this should be entirely based onExport.fileType
.- Specified by:
canHandle
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
export
- details about the export that will be processed- Returns:
- true if the file writer can support writing the file for the given export, false otherwise
-
getFileExtension
public String getFileExtension()
Description copied from interface:ExportFileWriter
Returns the file extension that should be used for the export file that the writer will be writing to.- Specified by:
getFileExtension
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Returns:
- the file extension (including the ".") that should be used for the export file
-
createExecutionContext
public CSVExportFileWriteContext createExecutionContext(OutputStream outputStream)
Description copied from interface:ExportFileWriter
Creates a new instance of anExportFileWriteContext
for writing to the givenoutputStream
.- Specified by:
createExecutionContext
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
outputStream
- the output stream that the writer should be writing to- Returns:
- a new instance of a file writing context that is bound to the given output stream
-
writeHeaders
public ExportFileWriteResponse writeHeaders(LinkedHashSet<String> headers, CSVExportFileWriteContext executionContext)
Description copied from interface:ExportFileWriter
Writes the given headers to the output file. TheExportFileWriteContext.outputStream
should be left open for further writes.- Specified by:
writeHeaders
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
headers
- the headers that need to be written to the export fileexecutionContext
- state information for the particular export being written- Returns:
- a response describing whether the write operation succeeded or failed
-
writeRows
public ExportFileWriteResponse writeRows(List<Map<String,String>> rows, CSVExportFileWriteContext executionContext)
Description copied from interface:ExportFileWriter
Writes the given rows to the export file. TheExportFileWriteContext.outputStream
should be left open for further writes.- Specified by:
writeRows
in interfaceExportFileWriter<CSVExportFileWriteContext>
- Parameters:
rows
- the rows that need to be written to the export fileexecutionContext
- state information for the particular export being written- Returns:
- a response describing whether the write operation succeeded or failed
-
-