public class PlainTextTemplate extends Object implements ExportTemplate
Modifier and Type | Field and Description |
---|---|
private String |
collectionSeparator |
private int |
colNum |
private Writer |
exportStream |
private List<ExportedProperty> |
properties |
private static Pattern |
UNSAFE |
Constructor and Description |
---|
PlainTextTemplate(Writer exportStream,
List<ExportedProperty> properties,
Item itemType)
Create a new template.
|
PlainTextTemplate(Writer exportStream,
List<ExportedProperty> properties,
Item itemType,
String collectionSeparator)
Create a new template.
|
Modifier and Type | Method and Description |
---|---|
void |
beginDocument()
Do nothing.
|
void |
beginItem(int id)
Reset column number.
|
void |
endDocument()
Do nothing.
|
void |
endItem()
Write a newline.
|
private String |
escape(String data)
Replace newlines and tabs with a space.
|
String |
getDefaultFileExtension()
Get the default file extension to give to files generated by this template.
|
String |
getMimeType()
Get the MIME type to assign to files generated by this template.
|
void |
writeAnnotations(ExportedProperty ep,
List<?> values,
String unit)
Join the annotation values into a single string with a comma.
|
void |
writeCollection(ExportedProperty ep,
Collection<?> values)
Writes a collection of values.
|
void |
writeHeaders()
Write the headers on a single line.
|
void |
writeProperty(ExportedProperty ep,
Object data)
Write the data object.
|
private final Writer exportStream
private final List<ExportedProperty> properties
private int colNum
private String collectionSeparator
private static final Pattern UNSAFE
public PlainTextTemplate(Writer exportStream, List<ExportedProperty> properties, Item itemType)
exportStream
- The stream to write toproperties
- All exported propertiesitemType
- The type of items we are exportingpublic PlainTextTemplate(Writer exportStream, List<ExportedProperty> properties, Item itemType, String collectionSeparator)
exportStream
- The stream to write toproperties
- All exported propertiesitemType
- The type of items we are exportingcollectionSeparator
- The character string that is used as separator when joining
a collection of values into a single value for an exported column (default is ',').public String getMimeType()
ExportTemplate
getMimeType
in interface ExportTemplate
public String getDefaultFileExtension()
ExportTemplate
getDefaultFileExtension
in interface ExportTemplate
public void beginDocument() throws IOException
beginDocument
in interface ExportTemplate
IOException
- If there is an errorpublic void writeHeaders() throws IOException
writeHeaders
in interface ExportTemplate
IOException
- If there is an errorpublic void beginItem(int id) throws IOException
beginItem
in interface ExportTemplate
id
- Id of the new item.IOException
- If there is an errorpublic void writeAnnotations(ExportedProperty ep, List<?> values, String unit) throws IOException
writeAnnotations
in interface ExportTemplate
ep
- Exported property the annotations belongs tovalues
- Annotation values to be written.unit
- The unit of the annotation values, or null
to not display write a unitIOException
- If there is an errorpublic void writeProperty(ExportedProperty ep, Object data) throws IOException
writeProperty
in interface ExportTemplate
ep
- The exported property the data
belongs to.data
- Data to be written.IOException
- If there is an errorpublic void writeCollection(ExportedProperty ep, Collection<?> values) throws IOException
writeCollection
in interface ExportTemplate
ep
- Exported property the values belong tovalues
- The values to be writtenIOException
public void endItem() throws IOException
endItem
in interface ExportTemplate
IOException
- If there is an errorpublic void endDocument() throws IOException
endDocument
in interface ExportTemplate
IOException
- If there is an error