

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 |
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.
| alma::acs::logging::tools::CSVConverter::CSVConverter | ( | String | cols | ) | [inline] |
Constructor
| 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
| 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.
| 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.
| 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] |
Convert a log in a CSV string
| log | The log to convert |
Implements alma::acs::logging::tools::LogConverter.
Reimplemented in alma::acs::logging::tools::TwikiTableConverter.
References appendField(), alma::acs::logging::tools::LogConverter::colIndex, formatData(), com::cosylab::logging::engine::log::ILogEntry::getAdditionalData(), com::cosylab::logging::engine::log::ILogEntry::getField(), com::cosylab::logging::engine::log::ILogEntry::hasDatas(), and separator.
Referenced by alma::acs::jlog::test::tools::ConvertersTest::testColumnsVector(), alma::acs::jlog::test::tools::ConvertersTest::testCSVConverterAllFields(), alma::acs::jlog::test::tools::ConvertersTest::testCVSSomeFields(), alma::acs::jlog::test::tools::ConvertersTest::testSetSeparator(), and alma::acs::jlog::test::tools::ConvertersTest::testTextConverter().
| void alma::acs::logging::tools::CSVConverter::encloseByDoubleQuotes | ( | boolean | enclose | ) | [inline] |
Put or remove the double quotes around the fields
| 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] ....
| datas | The additional data of a log |
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)
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
| sep | The new separator char |
References separator.
Referenced by alma::acs::jlog::test::tools::ConvertersTest::testSetSeparator().
char alma::acs::logging::tools::CSVConverter::separator = ',' [private] |
The separator, usually a ','
Referenced by convert(), getHeader(), and setSeparator().
boolean alma::acs::logging::tools::CSVConverter::useDoubleQuotes = true [private] |
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().
1.6.2