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 ofExportFileWriterthat 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 booleancanHandle(Export export)Returns whether the writer can support writing the file for the given export.CSVExportFileWriteContextcreateExecutionContext(OutputStream outputStream)Creates a new instance of anExportFileWriteContextfor writing to the givenoutputStream.StringgetFileExtension()Returns the file extension that should be used for the export file that the writer will be writing to.ExportFileWriteResponsewriteHeaders(LinkedHashSet<String> headers, CSVExportFileWriteContext executionContext)Writes the given headers to the output file.ExportFileWriteResponsewriteRows(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:ExportFileWriterReturns whether the writer can support writing the file for the given export. Generally this should be entirely based onExport.fileType.- Specified by:
canHandlein 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:ExportFileWriterReturns the file extension that should be used for the export file that the writer will be writing to.- Specified by:
getFileExtensionin 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:ExportFileWriterCreates a new instance of anExportFileWriteContextfor writing to the givenoutputStream.- Specified by:
createExecutionContextin 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:ExportFileWriterWrites the given headers to the output file. TheExportFileWriteContext.outputStreamshould be left open for further writes.- Specified by:
writeHeadersin 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:ExportFileWriterWrites the given rows to the export file. TheExportFileWriteContext.outputStreamshould be left open for further writes.- Specified by:
writeRowsin 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
-
-