Class TemplateWriter
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.core.DataEndpoint
com.northconcepts.datapipeline.core.DataWriter
com.northconcepts.datapipeline.core.AbstractWriter
com.northconcepts.datapipeline.core.TextWriter
com.northconcepts.datapipeline.template.TemplateWriter
Writes records to a text stream using FreeMarker template.
See the Write an XML file
example. See the FreeMarker Manual.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.AbstractWriter
currentRecordFields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionTemplateWriter(File file) Creates a writer that overwrites the file and wraps values with aTemplateObjectWrapper.TemplateWriter(File file, boolean append) Creates a writer for the file that wraps values with aTemplateObjectWrapper.TemplateWriter(File file, boolean append, boolean useTemplateObjectWrapper) Creates a writer for the file;useTemplateObjectWrapperchooses whether values are wrapped with aTemplateObjectWrapperbefore templates see them.TemplateWriter(Writer writer) Creates a writer that wraps values with aTemplateObjectWrapper.TemplateWriter(Writer writer, boolean useTemplateObjectWrapper) Creates a writer;useTemplateObjectWrapperchooses whether values are wrapped with aTemplateObjectWrapperbefore templates see them. -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.voidclose()Indicates that this endpoint has finished reading or writing.freemarker.template.ConfigurationReturns the FreeMarker configuration that loads the templates named in theStringtemplate setters.getData()Returns the data model given to the templates, holdingwriter,recordand the current record's fields by name; entries added here are visible to the templates too.freemarker.template.TemplateReturns the template written for each record.freemarker.template.TemplateReturns the template written after the records or null if there is none.freemarker.template.TemplateReturns the template written before the records or null if there is none.booleanIndicates if the footer should be written, even if no records were written (defaults to true).booleanIndicates if the header should be written, even if no records are written (defaults to true).booleanIndicates if values are wrapped with aTemplateObjectWrapperbefore templates see them; fixed by the constructor.voidopen()Makes this endpoint ready for reading or writing.setAlwaysShowFooter(boolean alwaysShowFooter) Indicates if the footer should be written, even if no records were written (defaults to true).setAlwaysShowHeader(boolean alwaysShowHeader) Indicates if the header should be written, even if no records are written (defaults to true).setDetailTemplate(freemarker.template.Template detailTemplate) Sets the template written for each record; only allowed before the writer is opened.setDetailTemplate(String detailTemplate) Sets the detail template to the template with this name, loaded throughgetConfiguration().setFooterTemplate(freemarker.template.Template footerTemplate) Sets the template written after the records; only allowed before the writer is opened.setFooterTemplate(String footerTemplate) Sets the footer template to the template with this name, loaded throughgetConfiguration().setHeaderTemplate(freemarker.template.Template headerTemplate) Sets the template written before the records; only allowed before the writer is opened.setHeaderTemplate(String headerTemplate) Sets the header template to the template with this name, loaded throughgetConfiguration().protected voidwriteRecord(Record record) Writes one row; called first for the header row (seeAbstractWriter.isHeaderRow()) when field names are written, then for each record.Methods inherited from class com.northconcepts.datapipeline.core.TextWriter
getFile, getWriter, isAppend, isAutoCloseWriter, isFieldNamesInFirstRow, isFlushOnWrite, setAutoCloseWriter, setFlushOnWrite, writeMethods inherited from class com.northconcepts.datapipeline.core.AbstractWriter
createHeaderRecord, isHeaderRow, setFieldNamesInFirstRow, writeImplMethods inherited from class com.northconcepts.datapipeline.core.DataWriter
available, getNestedEndpoint, getNestedWriter, getRootEndpoint, getRootWriter, getWriterMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Constructor Details
-
TemplateWriter
Creates a writer for the file that wraps values with aTemplateObjectWrapper. -
TemplateWriter
Creates a writer that overwrites the file and wraps values with aTemplateObjectWrapper. -
TemplateWriter
Creates a writer that wraps values with aTemplateObjectWrapper. -
TemplateWriter
Creates a writer for the file;useTemplateObjectWrapperchooses whether values are wrapped with aTemplateObjectWrapperbefore templates see them. -
TemplateWriter
Creates a writer;useTemplateObjectWrapperchooses whether values are wrapped with aTemplateObjectWrapperbefore templates see them.
-
-
Method Details
-
getData
Returns the data model given to the templates, holdingwriter,recordand the current record's fields by name; entries added here are visible to the templates too. -
getConfiguration
public freemarker.template.Configuration getConfiguration()Returns the FreeMarker configuration that loads the templates named in theStringtemplate setters. -
isAlwaysShowHeader
public boolean isAlwaysShowHeader()Indicates if the header should be written, even if no records are written (defaults to true). -
setAlwaysShowHeader
Indicates if the header should be written, even if no records are written (defaults to true). -
isUseTemplateObjectWrapper
public boolean isUseTemplateObjectWrapper()Indicates if values are wrapped with aTemplateObjectWrapperbefore templates see them; fixed by the constructor. -
getHeaderTemplate
public freemarker.template.Template getHeaderTemplate()Returns the template written before the records or null if there is none. -
setHeaderTemplate
Sets the header template to the template with this name, loaded throughgetConfiguration(). -
setHeaderTemplate
Sets the template written before the records; only allowed before the writer is opened. -
getDetailTemplate
public freemarker.template.Template getDetailTemplate()Returns the template written for each record. -
setDetailTemplate
Sets the detail template to the template with this name, loaded throughgetConfiguration(). -
setDetailTemplate
Sets the template written for each record; only allowed before the writer is opened. -
open
Description copied from class:DataEndpointMakes this endpoint ready for reading or writing.- Overrides:
openin classAbstractWriter- Throws:
DataException
-
close
Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classTextWriter- Throws:
DataException
-
writeRecord
Description copied from class:AbstractWriterWrites one row; called first for the header row (seeAbstractWriter.isHeaderRow()) when field names are written, then for each record.- Specified by:
writeRecordin classAbstractWriter- Throws:
Throwable
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classTextWriter
-