Class PlainTextTemplate
java.lang.Object
net.sf.basedb.clients.web.plugins.PlainTextTemplate
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ExportTemplate
public class PlainTextTemplate extends Object implements ExportTemplate
A plain text template that exports data in tab-delimited format.
- Version:
- 2.2
- Author:
- nicklas
- Last modified
- $Date: 2019-03-12 10:56:19 +0100 (tis, 12 mars 2019) $
-
Field Summary
Fields Modifier and Type Field Description private String
collectionSeparator
private int
colNum
private Writer
exportStream
private List<ExportedProperty>
properties
private static Pattern
UNSAFE
-
Constructor Summary
Constructors Constructor 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. -
Method Summary
Modifier and Type Method Description void
beginDocument()
Do nothing.void
beginItem(int id)
Reset column number.void
close()
Do nothing.void
endDocument(ProgressReporter progress)
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.
-
Field Details
-
exportStream
-
properties
-
colNum
private int colNum -
collectionSeparator
-
UNSAFE
-
-
Constructor Details
-
PlainTextTemplate
Create a new template.- Parameters:
exportStream
- The stream to write toproperties
- All exported propertiesitemType
- The type of items we are exporting
-
PlainTextTemplate
public PlainTextTemplate(Writer exportStream, List<ExportedProperty> properties, Item itemType, String collectionSeparator)Create a new template.- Parameters:
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 ',').- Since:
- 3.8
-
-
Method Details
-
getMimeType
Description copied from interface:ExportTemplate
Get the MIME type to assign to files generated by this template.- Specified by:
getMimeType
in interfaceExportTemplate
- Returns:
- text/plain
-
getDefaultFileExtension
Description copied from interface:ExportTemplate
Get the default file extension to give to files generated by this template.- Specified by:
getDefaultFileExtension
in interfaceExportTemplate
- Returns:
- Always "csv"
- Since:
- 3.0
-
beginDocument
Do nothing.- Specified by:
beginDocument
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
writeHeaders
Write the headers on a single line.- Specified by:
writeHeaders
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
beginItem
Reset column number.- Specified by:
beginItem
in interfaceExportTemplate
- Parameters:
id
- Id of the new item.- Throws:
IOException
- If there is an error
-
writeAnnotations
Join the annotation values into a single string with a comma.- Specified by:
writeAnnotations
in interfaceExportTemplate
- Parameters:
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 unit- Throws:
IOException
- If there is an error
-
writeProperty
Write the data object.- Specified by:
writeProperty
in interfaceExportTemplate
- Parameters:
ep
- The exported property thedata
belongs to.data
- Data to be written.- Throws:
IOException
- If there is an error
-
writeCollection
Writes a collection of values.- Specified by:
writeCollection
in interfaceExportTemplate
- Parameters:
ep
- Exported property the values belong tovalues
- The values to be written- Throws:
IOException
- Since:
- 2.12
-
endItem
Write a newline.- Specified by:
endItem
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
endDocument
Do nothing.- Specified by:
endDocument
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
close
Do nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
escape
Replace newlines and tabs with a space. Null values are converted to empty strings.
-