Branch 'ayres' - c++/lib c++/tests
Camila Ayres
ayres at kolabsys.com
Thu Mar 1 17:32:38 CET 2012
c++/lib/kolabconversions.h | 124 +++++++++++++++++++++++++++++++++++++++
c++/tests/testfiles/testnote.xml | 18 +++++
2 files changed, 142 insertions(+)
New commits:
commit 325d67290e469286c0061ac46ad4ee7087f19a08
Author: Camila San <smayres at gmail.com>
Date: Thu Mar 1 17:37:32 2012 +0100
including kolabconversions.
diff --git a/c++/lib/kolabconversions.h b/c++/lib/kolabconversions.h
new file mode 100644
index 0000000..b7c4eb9
--- /dev/null
+++ b/c++/lib/kolabconversions.h
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2011 Camila Ayres <ayres at kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef KOLABCONVERSIONS_H
+#define KOLABCONVERSIONS_H
+
+#include "kolabcontainers.h"
+
+#include <XMLParserWrapper.h>
+#include <boost/shared_ptr.hpp>
+#include "global_definitions.h"
+#include "utils.h"
+
+
+#include <bindings/kolabformat.hxx>
+
+using namespace Kolab;
+
+std::string fromDateTime(const DateTime &dt)
+{
+ std::stringstream s;
+ s << dt.year() << dt.month() << dt.day() << "T" << dt.hour() << dt.minute()
+<< dt.second();
+ if (!dt.isUTC()) { //always UTC
+ std::cout << "Date is not UTC but it should be, UTC assumed." <<
+std::endl;
+ }
+ s << "Z";
+ return s.str();
+}
+
+template <typename T>
+boost::shared_ptr<T> readCard(const KolabXSD::Note ¬e);
+
+template <>
+boost::shared_ptr<Kolab::Note> readCard <Kolab::Note> (const
+KolabXSD::Note ¬e)
+{
+ //TODO
+ return boost::shared_ptr<Kolab::Note>();
+}
+
+template <>
+void writeCard (const
+KolabXSD::Note ¬e)
+{
+ //TODO
+
+}
+
+template <typename T>
+std::string serializeCard(const T ¬e, const std::string prod = std::string())
+{
+
+
+ try {
+ KolabXSD::Note::uid_type uid(getUID(note.uid()));
+ KolabXSD::Note::version1_type kolab_version(KOLAB_FORMAT_VERSION);
+ KolabXSD::Note::prodid_type prodid(prod+KOLAB_LIBNAME);
+ KolabXSD::Note::version1_type
+rev(fromDateTime(getCurrentTime()));
+
+
+ KolabXSD::Note note(uid, kolab_version, prodid, rev);
+ writeCard<T>(note);
+
+ std::ostringstream ostringstream;
+ KolabXSD::Note(ostringstream, note);
+ return ostringstream.str();
+ } catch (const xml_schema::exception& e) {
+ std::cerr << "failed to write Note";
+ return std::string();
+ }
+}
+
+template <typename T>
+boost::shared_ptr<T> deserializeCard(const std::string& s, bool isUrl)
+{
+ try {
+ std::auto_ptr<KolabXSD::Note> note;
+ if (isUrl) {
+ xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc =
+XMLParserWrapper::inst().parseFile(s);
+ if (doc.get()) {
+ note = KolabXSD::Note(doc);
+ }
+ } else {
+ xsd::cxx::xml::dom::auto_ptr <xercesc_3_1::DOMDocument > doc =
+XMLParserWrapper::inst().parseString(s);
+ if (doc.get()) {
+ note = KolabXSD::Note(doc);
+ }
+ }
+
+ if (!note.get()) {
+ std::cerr << "failed to parse card!" << std::endl;
+ return boost::shared_ptr<T>();
+ }
+ return readCard<T>(note);
+ } catch (const xml_schema::exception& e) {
+ std::cerr << e << std::endl;
+ std::cerr << "Failed to read card!" << std::endl;
+ }
+
+ return boost::shared_ptr<T>();
+}
+
+
+
+#endif
\ No newline at end of file
diff --git a/c++/tests/testfiles/testnote.xml b/c++/tests/testfiles/testnote.xml
new file mode 100644
index 0000000..f7ad5b0
--- /dev/null
+++ b/c++/tests/testfiles/testnote.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<note version="3.0dev1" xmlns="http://kolab.org">
+ <!-- Common fields -->
+ <uid>uid</uid>
+ <body></body>
+ <categories></categories>
+ <creation-date>2004-05-04T15:00:00Z</creation-date>
+ <last-modification-date>2004-05-04T15:00:00Z</last-modification-date>
+ <sensitivity>public</sensitivity>
+ <inline-attachment></inline-attachment>
+ <link-attachment></link-attachment>
+ <product-id></product-id>
+ <!-- Note specific fields -->
+ <summary>summarytext</summary>
+ <background-color>#000000</background-color>
+ <foreground-color>#ffff00</foreground-color>
+</note>
+
More information about the commits
mailing list