alma::acs::logging::tools::CSVConverter Class Reference

Inheritance diagram for alma::acs::logging::tools::CSVConverter:
Inheritance graph
[legend]
Collaboration diagram for alma::acs::logging::tools::CSVConverter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CSVConverter (String cols)
 CSVConverter ()
 CSVConverter (String cols, char separator, boolean doubleQuotes)
void setSeparator (char sep)
void encloseByDoubleQuotes (boolean enclose)
String getHeader ()
String convert (ILogEntry log)

Private Member Functions

void appendField (String fld, StringBuilder str)
String formatData (Vector< ILogEntry.AdditionalData > datas)

Private Attributes

char separator = ','
boolean useDoubleQuotes = true

Detailed Description

Objects of this class produce a CSV string from a given log. The CSV adhere to the definition in RFC4180.

It is possible to select the columns of the log to export and their positions by setting a string.

A method generate the header in CSV format

All the fields appear inside double quotes. If a field contains double quotes they are escaped by double quotes. It is also possible not to enclose the fields by double quotes but in that case the content of the field is changed because some character are not allowed.

It is possible to define a different separator instead of a comma, like for example the TAB.

Author:
acaproni

Constructor & Destructor Documentation

alma::acs::logging::tools::CSVConverter::CSVConverter ( String  cols  )  [inline]

Constructor

Parameters:
cols A string describing the field of the log and their position in the output
alma::acs::logging::tools::CSVConverter::CSVConverter (  )  [inline]

Constructor.

The converted string contains all the fields just once and the additional data.

alma::acs::logging::tools::CSVConverter::CSVConverter ( String  cols,
char  separator,
boolean  doubleQuotes 
) [inline]

Constructor

Parameters:
cols A string describing the field of the log and their position in the output
separator A character to use as fields separator
doubleQuotes If true the fields are enclosed by double quotes

References useDoubleQuotes.


Member Function Documentation

void alma::acs::logging::tools::CSVConverter::appendField ( String  fld,
StringBuilder  str 
) [inline, private]

Append a field to the string (str) The field is into double quotes. If double quotes exist into the string, they are escaped.

Parameters:
fld The field to append
str The string builder where the field is appended

References useDoubleQuotes.

Referenced by convert(), and getHeader().

String alma::acs::logging::tools::CSVConverter::convert ( ILogEntry  log  )  [inline, virtual]
void alma::acs::logging::tools::CSVConverter::encloseByDoubleQuotes ( boolean  enclose  )  [inline]

Put or remove the double quotes around the fields

Parameters:
enclose If true the fields are enclosed by double quotes

References useDoubleQuotes.

String alma::acs::logging::tools::CSVConverter::formatData ( Vector< ILogEntry.AdditionalData >  datas  )  [inline, private]

Format the additional data in a string to be appended in the CSV. The produced string is not converted in CSV but contains all the entries of the additional data

The format is the following: [name1 ==> val1] [name2 ==> val2] ....

Parameters:
datas The additional data of a log
Returns:
A string with the additional data

Referenced by convert().

String alma::acs::logging::tools::CSVConverter::getHeader (  )  [inline, virtual]

Generate the header for the CSV file (it is optional and can appear in the first line of the file)

Returns:
The CSV string representing the header in CSV format with CR/LF at the end of the line

Implements alma::acs::logging::tools::LogConverter.

Reimplemented in alma::acs::logging::tools::TwikiTableConverter.

References appendField(), alma::acs::logging::tools::LogConverter::colIndex, and separator.

Referenced by alma::acs::jlog::test::tools::ConvertersTest::testGetHeader().

void alma::acs::logging::tools::CSVConverter::setSeparator ( char  sep  )  [inline]

Set the separator

Parameters:
sep The new separator char

References separator.

Referenced by alma::acs::jlog::test::tools::ConvertersTest::testSetSeparator().


Member Data Documentation

The separator, usually a ','

Referenced by convert(), getHeader(), and setSeparator().

If true each field is enclosed in double quotes otherwise the double quotes do not enclose the fields but some character in the fields will be replaced because are not allowed (like the double quotes for example)

Referenced by appendField(), CSVConverter(), and encloseByDoubleQuotes().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2