public class PlainTextTemplate extends java.lang.Object implements ExportTemplate
Modifier and Type | Field and Description |
---|---|
private int |
colNum |
private java.io.Writer |
exportStream |
private java.util.List<ExportedProperty> |
properties |
private static java.util.regex.Pattern |
UNSAFE |
Constructor and Description |
---|
PlainTextTemplate(java.io.Writer exportStream,
java.util.List<ExportedProperty> properties,
Item itemType)
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 java.lang.String |
escape(java.lang.String data)
Replace newlines and tabs with a space.
|
java.lang.String |
getDefaultFileExtension()
Get the default file extension to give to files generated by this template.
|
java.lang.String |
getMimeType()
Get the MIME type to assign to files generated by this template.
|
void |
writeAnnotations(ExportedProperty ep,
java.util.List<?> values,
java.lang.String unit)
Join the annotation values into a single string with a comma.
|
void |
writeCollection(ExportedProperty ep,
java.util.Collection<?> values)
Writes a collection of values.
|
void |
writeHeaders()
Write the headers on a single line.
|
void |
writeProperty(ExportedProperty ep,
java.lang.Object data)
Write the data object.
|
private final java.io.Writer exportStream
private final java.util.List<ExportedProperty> properties
private int colNum
private static final java.util.regex.Pattern UNSAFE
public PlainTextTemplate(java.io.Writer exportStream, java.util.List<ExportedProperty> properties, Item itemType)
exportStream
- The stream to write toproperties
- All exported propertiesitemType
- The type of items we are exportingpublic java.lang.String getMimeType()
ExportTemplate
getMimeType
in interface ExportTemplate
public java.lang.String getDefaultFileExtension()
ExportTemplate
getDefaultFileExtension
in interface ExportTemplate
public void beginDocument() throws java.io.IOException
beginDocument
in interface ExportTemplate
java.io.IOException
- If there is an errorpublic void writeHeaders() throws java.io.IOException
writeHeaders
in interface ExportTemplate
java.io.IOException
- If there is an errorpublic void beginItem(int id) throws java.io.IOException
beginItem
in interface ExportTemplate
id
- Id of the new item.java.io.IOException
- If there is an errorpublic void writeAnnotations(ExportedProperty ep, java.util.List<?> values, java.lang.String unit) throws java.io.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 unitjava.io.IOException
- If there is an errorpublic void writeProperty(ExportedProperty ep, java.lang.Object data) throws java.io.IOException
writeProperty
in interface ExportTemplate
ep
- The exported property the data
belongs to.data
- Data to be written.java.io.IOException
- If there is an errorpublic void writeCollection(ExportedProperty ep, java.util.Collection<?> values) throws java.io.IOException
writeCollection
in interface ExportTemplate
ep
- Exported property the values belong tovalues
- The values to be writtenjava.io.IOException
public void endItem() throws java.io.IOException
endItem
in interface ExportTemplate
java.io.IOException
- If there is an errorpublic void endDocument() throws java.io.IOException
endDocument
in interface ExportTemplate
java.io.IOException
- If there is an errorprivate java.lang.String escape(java.lang.String data)