2.17.2: 2011-06-17

net.sf.basedb.clients.web.plugins
Class PlainTextTemplate

java.lang.Object
  extended by net.sf.basedb.clients.web.plugins.PlainTextTemplate
All Implemented Interfaces:
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: 2009-04-21 11:29:09 +0200 (Tue, 21 Apr 2009) $

Field Summary
private  int colNum
           
private  Writer exportStream
           
private  List<ExportedProperty> properties
           
private static Pattern UNSAFE
           
 
Constructor Summary
PlainTextTemplate(Writer exportStream, List<ExportedProperty> properties, Item itemType)
          Create a new template.
 
Method Summary
 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

exportStream

private final Writer exportStream

properties

private final List<ExportedProperty> properties

colNum

private int colNum

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 to
properties - All exported properties
itemType - The type of items we are exporting
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 interface ExportTemplate
Returns:
text/plain

beginDocument

public void beginDocument()
                   throws IOException
Do nothing.

Specified by:
beginDocument in interface ExportTemplate
Throws:
IOException - If there is an error

writeHeaders

public void writeHeaders()
                  throws IOException
Write the headers on a single line.

Specified by:
writeHeaders in interface ExportTemplate
Throws:
IOException - If there is an error

beginItem

public void beginItem(int id)
               throws IOException
Reset column number.

Specified by:
beginItem in interface ExportTemplate
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 interface ExportTemplate
Parameters:
ep - Exported property the annotations belongs to
values - 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 interface ExportTemplate
Parameters:
ep - The exported property the data 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 interface ExportTemplate
Parameters:
ep - Exported property the values belong to
values - The values to be written
Throws:
IOException
Since:
2.12

endItem

public void endItem()
             throws IOException
Write a newline.

Specified by:
endItem in interface ExportTemplate
Throws:
IOException - If there is an error

endDocument

public void endDocument()
                 throws IOException
Do nothing.

Specified by:
endDocument in interface ExportTemplate
Throws:
IOException - If there is an error

escape

private String escape(String data)
Replace newlines and tabs with a space. Null values are converted to empty strings.


2.17.2: 2011-06-17