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
All Methods Instance Methods Concrete Methods 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 Detail
-
exportStream
private final Writer exportStream
-
properties
private final List<ExportedProperty> properties
-
colNum
private int colNum
-
collectionSeparator
private String collectionSeparator
-
UNSAFE
private static final Pattern UNSAFE
-
-
Constructor Detail
-
PlainTextTemplate
public PlainTextTemplate(Writer exportStream, List<ExportedProperty> properties, Item itemType)
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 Detail
-
getMimeType
public String 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
public String 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
public void beginDocument() throws IOException
Do nothing.- Specified by:
beginDocument
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
writeHeaders
public void writeHeaders() throws IOException
Write the headers on a single line.- Specified by:
writeHeaders
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
beginItem
public void beginItem(int id) throws IOException
Reset column number.- Specified by:
beginItem
in interfaceExportTemplate
- Parameters:
id
- Id of the new item.- Throws:
IOException
- If there is an error
-
writeAnnotations
public void writeAnnotations(ExportedProperty ep, List<?> values, String unit) throws IOException
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
public void writeProperty(ExportedProperty ep, Object data) throws IOException
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
public void writeCollection(ExportedProperty ep, Collection<?> values) throws IOException
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
public void endItem() throws IOException
Write a newline.- Specified by:
endItem
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
endDocument
public void endDocument(ProgressReporter progress) throws IOException
Do nothing.- Specified by:
endDocument
in interfaceExportTemplate
- Throws:
IOException
- If there is an error
-
close
public void close() throws IOException
Do nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-