public abstract class ExportFormatter
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected DataExportConfiguration |
config
The configuration parameters for this data export.
|
protected java.io.PrintWriter |
out
Output target for the formatter to write to.
|
Constructor and Description |
---|
ExportFormatter() |
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.nio.file.Path p)
Tests whether the name of a file matches this format's extension.
|
boolean |
accept(java.lang.String s)
Tests whether a file name matches this format's extension.
|
protected java.io.PrintWriter |
createOutputFile(java.lang.String file)
Creates an output file with the configured encoding.
|
protected void |
endRow()
Prints the formatting to end a table row.
|
protected void |
endTable()
Prints the formatting to end a table.
|
protected void |
exit(java.lang.String fileName)
Performs any processing after an output file has been closed.
|
protected void |
fileBegin(java.lang.String fileName)
Prints formatting required at the beginning of a new file.
|
protected void |
fileEnd()
Prints the formatting to end a file.
|
protected java.lang.String |
formatValue(java.lang.Object o)
Formats a table cell value.
|
abstract java.lang.String |
getDescription()
Gets a description string for this format.
|
abstract java.lang.String |
getExtension()
Gets the file extension for this format.
|
protected boolean |
init(java.lang.String file,
DataTables data)
Performs any up-front activities before the individual data files are
created.
|
protected void |
newTable(java.lang.String tablename)
Prints formatting required to start a new table.
|
protected void |
outputXMLEscaped(java.lang.String str)
Writes a string to the current output file, substituting XML and HTML
special characters by their entity references.
|
protected void |
startRow()
Prints the formatting to start a new table row.
|
protected void |
tableCell(java.lang.Object c)
Prints a table body data cell.
|
protected void |
tableHeaderCell(java.lang.String caption)
Prints the table header cell of a table column.
|
protected java.io.PrintWriter out
protected DataExportConfiguration config
public boolean accept(java.lang.String s)
s
- File name to test.true
if the file name matches the file format
extension, else false
.public boolean accept(java.nio.file.Path p)
p
- File to test.true
if the file is a directory or if its name
matches the file format extension, else false
.public abstract java.lang.String getExtension()
public abstract java.lang.String getDescription()
protected boolean init(java.lang.String file, DataTables data) throws java.io.IOException
file
- (base) name of the output file(s) to be created.data
- The data to be written.true
if initialization was performed successfully,
false
if initialization was aborted for an expected
reason such as user cancellationjava.io.IOException
- Technical problem during initializationprotected void fileBegin(java.lang.String fileName)
fileName
- Name of the file to be written to.protected void newTable(java.lang.String tablename)
tablename
- The name of the table (metamodel element type in most
cases).protected void startRow()
protected void tableHeaderCell(java.lang.String caption)
caption
- Caption of the column.protected void tableCell(java.lang.Object c)
c
- Contents of the cell. This will usually be an instance of
Number
(integer or floats), a string, or a collection.protected void endRow()
protected void endTable()
protected void fileEnd()
protected void exit(java.lang.String fileName) throws java.io.IOException
fileName
- Name of the file that has just been completed and closed.java.io.IOException
- technical problems during post processing.protected java.lang.String formatValue(java.lang.Object o)
null
values are mapped to empty strings
o.toString()
o
- Value to formatprotected void outputXMLEscaped(java.lang.String str)
The escaped characters are <, >, &, and ". As a concession to HTML, apostrophes are not substituted. Therefore, specializations should delimit XML/HTML attributes using quotes in the output when using this function to write attribute values.
str
- the string to writeprotected java.io.PrintWriter createOutputFile(java.lang.String file) throws java.io.IOException
file
- Name of the file to createnull
if the file exists
and overwriting was not allowed.java.io.IOException
- technical problem creating the file