www.sdmetrics.com

com.sdmetrics.output
Class ExportFormatter

java.lang.Object
  extended by com.sdmetrics.output.ExportFormatter

public abstract class ExportFormatter
extends java.lang.Object

Base class for data export formatters.


Field Summary
protected  DataExportConfiguration config
          The configuration parameters for this data export.
protected  java.io.PrintWriter out
          Output target for the formatter to write to.
 
Constructor Summary
ExportFormatter()
           
 
Method Summary
 boolean accept(java.io.File f)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.PrintWriter out
Output target for the formatter to write to.


config

protected DataExportConfiguration config
The configuration parameters for this data export.

Constructor Detail

ExportFormatter

public ExportFormatter()
Method Detail

accept

public boolean accept(java.lang.String s)
Tests whether a file name matches this format's extension.

Parameters:
s - File name to test.
Returns:
true if the file name matches the file format extension, else false.

accept

public boolean accept(java.io.File f)
Tests whether the name of a file matches this format's extension. Also accepts directories, which is useful for file chooser dialogs.

Parameters:
f - File to test.
Returns:
true if the file is a directory or if its name matches the file format extension, else false.

getExtension

public abstract java.lang.String getExtension()
Gets the file extension for this format.

Returns:
The most commonly used file extension for this format, in lower case.

getDescription

public abstract java.lang.String getDescription()
Gets a description string for this format.

Returns:
Description string suitable for a file chooser dialog, e.g. "HTML File (*.html)"

init

protected boolean init(java.lang.String file,
                       DataTables data)
                throws java.io.IOException
Performs any up-front activities before the individual data files are created. For example, creating an index file that links to the separate files to be subsequently written.

Parameters:
file - (base) name of the output file(s) to be created.
data - The data to be written.
Returns:
true if initialization was performed successfully, false if initialization was aborted for an expected reason such as user cancellation
Throws:
java.io.IOException - Technical problem during initialization

fileBegin

protected void fileBegin(java.lang.String fileName)
Prints formatting required at the beginning of a new file.

Parameters:
fileName - Name of the file to be written to.

newTable

protected void newTable(java.lang.String tablename)
Prints formatting required to start a new table.

Parameters:
tablename - The name of the table (metamodel element type in most cases).

startRow

protected void startRow()
Prints the formatting to start a new table row. Used for both table header rows and table body rows.


tableHeaderCell

protected void tableHeaderCell(java.lang.String caption)
Prints the table header cell of a table column.

Parameters:
caption - Caption of the column.

tableCell

protected void tableCell(java.lang.Object c)
Prints a table body data cell.

Parameters:
c - Contents of the cell. This will usually be an instance of Number (integer or floats), a string, or a collection.

endRow

protected void endRow()
Prints the formatting to end a table row. Used for both table header rows and table body rows.


endTable

protected void endTable()
Prints the formatting to end a table.


fileEnd

protected void fileEnd()
Prints the formatting to end a file.


exit

protected void exit(java.lang.String fileName)
             throws java.io.IOException
Performs any processing after an output file has been closed. For example, formats with inbuilt compression would compress the file just created.

Parameters:
fileName - Name of the file that has just been completed and closed.
Throws:
java.io.IOException - technical problems during post processing.

formatValue

protected java.lang.String formatValue(java.lang.Object o)
Formats a table cell value.

Parameters:
o - Value to format
Returns:
String representation of the value

outputXMLEscaped

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.

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.

Parameters:
str - the string to write

createOutputFile

protected java.io.PrintWriter createOutputFile(java.lang.String file)
                                        throws java.io.IOException
Creates an output file with the configured encoding. Asks for confirmation before overwriting existing files.

Parameters:
file - Name of the file to create
Returns:
PrintWriter to the file, or null if the file exists and overwriting was not allowed.
Throws:
java.io.IOException - technical problem creating the file

www.sdmetrics.com