# HG changeset patch # User František Kučera # Date 1544190400 -3600 # Node ID 3e73d4ae8b499f3dfae81574f01377fb7997f16d # Parent a8cb46dbb6125bd347b505bf47322c927337ce68 first working version diff -r a8cb46dbb612 -r 3e73d4ae8b49 nbproject/configurations.xml --- a/nbproject/configurations.xml Fri Dec 07 12:53:43 2018 +0100 +++ b/nbproject/configurations.xml Fri Dec 07 14:46:40 2018 +0100 @@ -67,8 +67,7 @@ false - + @@ -80,12 +79,8 @@ build/Debug/src/relpipe-out-ods - ../relpipe-lib-cli.cpp/include/relpipe/cli - ../relpipe-lib-reader.cpp/include/relpipe/reader - src - ../relpipe-lib-reader.cpp/include/relpipe/reader/handlers + ../relpipe-lib-reader.cpp/include ../relpipe-lib-cli.cpp/include - ../relpipe-lib-reader.cpp/include build/Debug/src diff -r a8cb46dbb612 -r 3e73d4ae8b49 src/OdsHandler.h --- a/src/OdsHandler.h Fri Dec 07 12:53:43 2018 +0100 +++ b/src/OdsHandler.h Fri Dec 07 14:46:40 2018 +0100 @@ -39,7 +39,14 @@ class OdsHandler : public handlers::RelationalReaderStringHadler { private: std::wstring_convert> convertor; // XML output will be always in UTF-8 - const char* INDENT = "\t"; + + // TODO: refactor and move common XML functions to relpipe-lib-xml + const char* INDENT_1 = "\t"; + const char* INDENT_2 = "\t\t"; + const char* INDENT_3 = "\t\t\t"; + const char* INDENT_4 = "\t\t\t\t"; + const char* INDENT_5 = "\t\t\t\t\t"; + const char* INDENT_6 = "\t\t\t\t\t\t"; std::ostream &output; @@ -50,6 +57,8 @@ integer_t columnCount = 0; integer_t relationCount = 0; + // TODO: refactor and move common XML functions to relpipe-lib-xml + const std::string escapeXmlText(const string_t &value) { std::wstringstream result; @@ -85,50 +94,68 @@ if (relationCount == 0) { output << "" << std::endl; - output << "" << std::endl; - // TODO: xmlns + output << "" << std::endl; + + output << INDENT_1 << "" << std::endl; + output << INDENT_2 << "" << std::endl; + } else { - output << INDENT << INDENT << "" << std::endl; - output << INDENT << "" << std::endl; + output << INDENT_4 << "" << std::endl; + output << INDENT_3 << "" << std::endl; } relationCount++; - output << INDENT << "" << std::endl; - - output << INDENT << INDENT << "" << escapeXmlText(name) << "" << std::endl; + // TODO: rename relations with same names + output << INDENT_3 << "" << std::endl; columnCount = attributes.size(); columnTypes.resize(columnCount); columnTypeCodes.resize(columnCount); columnNames.resize(columnCount); + + output << INDENT_4 << "" << std::endl; for (int i = 0; i < attributes.size(); i++) { columnNames[i] = attributes[i].getAttributeName(); columnTypes[i] = attributes[i].getTypeId(); columnTypeCodes[i] = attributes[i].getTypeName(); + + output << INDENT_5 << "" << std::endl; + output << INDENT_6 << ""; + output << escapeXmlText(columnNames[i]); + output << "" << std::endl; + output << INDENT_5 << "" << std::endl; } - - // TODO: print attribute metadata + output << INDENT_4 << "" << std::endl; + } void attribute(const string_t& value) override { integer_t i = valueCount % columnCount; - if (i == 0 && valueCount) output << INDENT << INDENT << "" << std::endl; - if (i == 0) output << INDENT << INDENT << "" << std::endl; + if (i == 0 && valueCount) output << INDENT_4 << "" << std::endl; + if (i == 0) output << INDENT_4 << "" << std::endl; valueCount++; - // TODO: print attribute metadata (optional) - output << INDENT << INDENT << INDENT << ""; + output << INDENT_5 << "" << std::endl; + output << INDENT_6 << ""; output << escapeXmlText(value); - output << "" << std::endl; + output << "" << std::endl; + output << INDENT_5 << "" << std::endl; } void endOfPipe() { - if (valueCount) output << INDENT << INDENT << "" << std::endl; - if (relationCount) output << INDENT << "" << std::endl; - output << "" << std::endl; + if (valueCount) output << INDENT_4 << "" << std::endl; + if (relationCount) output << INDENT_3 << "" << std::endl; + output << INDENT_2 << "" << std::endl; + output << INDENT_1 << "" << std::endl; + output << "" << std::endl; }