2 commits - c++/CMakeLists.txt c++/lib c++/tests schemas/kolabformat.xsd
Christian Mollekopf
mollekopf at kolabsys.com
Thu Mar 8 22:30:47 CET 2012
c++/CMakeLists.txt | 5 -
c++/lib/CMakeLists.txt | 3
c++/lib/DEVELOPMENT | 4
c++/lib/kolabcontainers.h | 4
c++/lib/kolabconversions.h | 182 ++++++++++++++++++++++++++++++++++++++++++
c++/lib/kolabformat.cpp | 14 +--
c++/lib/kolabformat.h | 1
c++/lib/kolabnote.cpp | 185 +++++++++++++++++++++++++++++++++++++++++++
c++/lib/kolabnote.h | 75 +++++++++++++++++
c++/lib/shared_conversions.h | 72 ++++++++++++++++
c++/lib/xcalconversions.h | 79 +++++-------------
c++/tests/bindingstest.cpp | 31 ++++++-
c++/tests/bindingstest.h | 1
schemas/kolabformat.xsd | 108 ++++++++++++++-----------
14 files changed, 647 insertions(+), 117 deletions(-)
New commits:
commit 9fa9b0bead832c959c015a4c8489bea5a6571f1e
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu Mar 8 22:30:34 2012 +0100
first version of notes, plus some restructuring to share more code.
diff --git a/c++/CMakeLists.txt b/c++/CMakeLists.txt
index a2ac011..17c0bbe 100644
--- a/c++/CMakeLists.txt
+++ b/c++/CMakeLists.txt
@@ -69,6 +69,7 @@ file(GLOB SCHEMAS ${SCHEMA_DIR}/*.xsd)
set( SCHEMAS ${SCHEMAS} ${XCAL_SCHEMAS})
set( SCHEMA_SOURCEFILES
+ ${CMAKE_BUILD_DIR}/bindings/kolabformat.cxx
${CMAKE_BUILD_DIR}/bindings/xCard.cxx
${CMAKE_BUILD_DIR}/bindings/kolabformat-xcal.cxx
${CMAKE_BUILD_DIR}/bindings/kolabformat-xcard.cxx
@@ -84,7 +85,7 @@ set( SCHEMA_SOURCEFILES
# --generate-inline --extern-xml-schema xml-schema.xsd
# --cxx-suffix .cpp --hxx-suffix .h
add_custom_command(OUTPUT ${SCHEMA_SOURCEFILES}
- COMMAND ${XSDCXX} cxx-tree --generate-polymorphic --generate-serialization --namespace-map http://kolab.org=KolabXSD --root-element icalendar --root-element vcards --output-dir ${CMAKE_BUILD_DIR}/bindings ${SCHEMAS}
+ COMMAND ${XSDCXX} cxx-tree --generate-polymorphic --generate-serialization --namespace-map http://kolab.org=KolabXSD --root-element icalendar --root-element vcards --root-element note --output-dir ${CMAKE_BUILD_DIR}/bindings ${SCHEMAS}
COMMENT "Generating XSD bindings"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${SCHEMAS}
@@ -96,7 +97,7 @@ add_executable(xsdbin compiled/xsdbin.cxx)
target_link_libraries(xsdbin ${XERCES_C})
add_custom_command(OUTPUT kolabformat-xcal-schema.cxx
- COMMAND ${CMAKE_BUILD_DIR}/xsdbin --verbose --array-name iCalendar_schema --output-dir ${CMAKE_BUILD_DIR} ${SCHEMA_DIR}/ical/kolabformat-xcal.xsd ${SCHEMA_DIR}/ical/iCalendar-params.xsd ${SCHEMA_DIR}/ical/iCalendar-props.xsd ${SCHEMA_DIR}/ical/iCalendar-valtypes.xsd ${SCHEMA_DIR}/xCard.xsd ${SCHEMA_DIR}/kolabformat-xcard.xsd
+ COMMAND ${CMAKE_BUILD_DIR}/xsdbin --verbose --array-name iCalendar_schema --output-dir ${CMAKE_BUILD_DIR} ${SCHEMA_DIR}/ical/kolabformat-xcal.xsd ${SCHEMA_DIR}/ical/iCalendar-params.xsd ${SCHEMA_DIR}/ical/iCalendar-props.xsd ${SCHEMA_DIR}/ical/iCalendar-valtypes.xsd ${SCHEMA_DIR}/xCard.xsd ${SCHEMA_DIR}/kolabformat-xcard.xsd ${SCHEMA_DIR}/kolabformat.xsd
COMMENT "Compiling Kolab XSD schema"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${XCAL_SCHEMAS} xsdbin
diff --git a/c++/lib/CMakeLists.txt b/c++/lib/CMakeLists.txt
index cffaee2..b26fc0e 100644
--- a/c++/lib/CMakeLists.txt
+++ b/c++/lib/CMakeLists.txt
@@ -9,7 +9,7 @@ SET_SOURCE_FILES_PROPERTIES(${SCHEMA_SOURCEFILES} PROPERTIES GENERATED 1)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC " ) #always generate shared libraries with -fPIC
#Library with serialization/deserialization code and kolab-containers
-add_library(kolabxml SHARED kolabformat.cpp kolabcontainers.cpp kolabevent.cpp kolabtodo.cpp kolabjournal.cpp kolabcontact.cpp utils.cpp base64.cpp ../compiled/XMLParserWrapper.cpp ../compiled/grammar-input-stream.cxx ${SCHEMA_SOURCEFILES})
+add_library(kolabxml SHARED kolabformat.cpp kolabcontainers.cpp kolabnote.cpp kolabevent.cpp kolabtodo.cpp kolabjournal.cpp kolabcontact.cpp utils.cpp base64.cpp ../compiled/XMLParserWrapper.cpp ../compiled/grammar-input-stream.cxx ${SCHEMA_SOURCEFILES})
# boost
find_package(Boost COMPONENTS thread REQUIRED)
target_link_libraries(kolabxml ${XERCES_C} ${Boost_LIBRARIES})
@@ -25,6 +25,7 @@ install( FILES
kolabtodo.h
kolabjournal.h
kolabcontact.h
+ kolabnote.h
kolabcontainers.h
global_definitions.h
DESTINATION include/kolab COMPONENT Devel)
diff --git a/c++/lib/DEVELOPMENT b/c++/lib/DEVELOPMENT
index 08cab4d..d6730e1 100644
--- a/c++/lib/DEVELOPMENT
+++ b/c++/lib/DEVELOPMENT
@@ -99,4 +99,6 @@ Writing doesn't provide any validation (as it is hardly useful for the reason th
-Don't forget to add an element for each attribute in the style off: <xs:element name="pref" type="xcard:prefParamType" substitutionGroup="xcard:baseParameter"/>
Otherwise you won't get the serialization/deserialization code (or respectively just wrong code), which still compiles though and looks correct from the outside.
--If you have modified the xsd's make sure to run "make clean && make" in the toplevel make directory, otherwise the schema is not recompiles => parsing errors
\ No newline at end of file
+-If you have modified the xsd's make sure to run "make clean && make" in the toplevel make directory, otherwise the schema is not recompiles => parsing errors
+
+-Make sure you add new .xsd to the compiled schemas, otherwise you'll get "no declaration found" errors.
diff --git a/c++/lib/kolabcontainers.h b/c++/lib/kolabcontainers.h
index 98bea0e..3f8d1ba 100644
--- a/c++/lib/kolabcontainers.h
+++ b/c++/lib/kolabcontainers.h
@@ -353,10 +353,6 @@ std::vector<T> operator<< ( std::vector<T> v, const T &s)
//Prepared Kolab Objects
-class Note {
- //TODO
-};
-
class Configuration {
//TODO
};
diff --git a/c++/lib/kolabconversions.h b/c++/lib/kolabconversions.h
new file mode 100644
index 0000000..4414b49
--- /dev/null
+++ b/c++/lib/kolabconversions.h
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf 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 KOLABOBJECTCONVERSION_H
+#define KOLABOBJECTCONVERSION_H
+
+#include <bindings/kolabformat.hxx>
+#include "kolabcontainers.h"
+#include <XMLParserWrapper.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
+#include "global_definitions.h"
+#include "utils.h"
+#include "kolabnote.h"
+#include "shared_conversions.h"
+
+namespace Kolab {
+ namespace KolabObjects {
+
+const char* const KOLAB_NAMESPACE = "http://kolab.org";
+
+using namespace Kolab::Utils;
+using namespace Kolab::Shared;
+
+template <typename T>
+std::string serializeObject(const Kolab::Note ¬e, const std::string prod = std::string()) {
+
+ clearErrors();
+
+ try {
+
+ const std::string &uid = getUID(note.uid());
+ setCreatedUid(uid);
+
+ KolabXSD::Note::creation_date_type created = fromDateTime(note.created());
+ if (!note.created().isValid()) {
+ created = fromDateTime(getCurrentTime());
+ }
+
+ KolabXSD::Note n(getUID(note.uid()), prod+KOLAB_LIBNAME+KOLAB_LIB_VERSION, created, fromDateTime(getCurrentTime()));
+
+ if (!note.categories().empty()) {
+ KolabXSD::Note::categories_sequence categories;
+ BOOST_FOREACH(const std::string &c, note.categories()) {
+ categories.push_back(c);
+ }
+ n.categories(categories);
+ }
+ switch (note.classification()) {
+ case Kolab::ClassPublic:
+ n.classification(KolabXSD::Note::classification_type::PUBLIC);
+ break;
+ case Kolab::ClassPrivate:
+ n.classification(KolabXSD::Note::classification_type::PRIVATE);
+ break;
+ case Kolab::ClassConfidential:
+ n.classification(KolabXSD::Note::classification_type::CONFIDENTIAL);
+ break;
+ default:
+ ERROR("unknown classification");
+ }
+ //TODO
+// n.attachment();
+ n.summary(note.summary());
+ n.description(note.description());
+ n.color(note.color());
+
+ if (!note.customProperties().empty()) {
+ BOOST_FOREACH(const Kolab::CustomProperty &a, note.customProperties()) {
+ n.x_custom().push_back(KolabXSD::CustomType(a.identifier, a.value));
+ }
+ }
+
+ xml_schema::namespace_infomap map;
+ map[""].name = KOLAB_NAMESPACE;
+
+ std::ostringstream ostringstream;
+ KolabXSD::note(ostringstream, n, map);
+ return ostringstream.str();
+ } catch (const xml_schema::exception& e) {
+ CRITICAL("Unknown Exception: failed to write Note");
+ }
+ return std::string();
+}
+
+template <typename T>
+boost::shared_ptr<Kolab::Note> deserializeObject(const std::string& s, bool isUrl)
+{
+ clearErrors();
+ 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()) {
+ CRITICAL("failed to parse note!");
+ return boost::shared_ptr<Kolab::Note>();
+ }
+
+ boost::shared_ptr<Kolab::Note> n = boost::shared_ptr<Kolab::Note>(new Kolab::Note);
+ n->setUid(note->uid());
+ n->setCreated(*toDate(note->creation_date()));
+ n->setLastModified(*toDate(note->last_modification_date()));
+ std::vector<std::string> categories;
+ std::copy(note->categories().begin(), note->categories().end(), std::back_inserter(categories));
+ n->setCategories(categories);
+ if (note->classification()) {
+ switch (*note->classification()) {
+ case KolabXSD::Note::classification_type::PUBLIC:
+ n->setClassification(Kolab::ClassPublic);
+ break;
+ case KolabXSD::Note::classification_type::PRIVATE:
+ n->setClassification(Kolab::ClassPrivate);
+ break;
+ case KolabXSD::Note::classification_type::CONFIDENTIAL:
+ n->setClassification(Kolab::ClassConfidential);
+ break;
+ default:
+ ERROR("unknown classification");
+ }
+ }
+ //TODO
+// n->setAttachments();
+ if (note->summary()) {
+ n->setSummary(*note->summary());
+ }
+ if (note->description()) {
+ n->setDescription(*note->description());
+ }
+ if (note->color()) {
+ n->setColor(*note->color());
+ }
+
+ setProductId( note->prodid() );
+ // setFormatVersion( vcards->vcard().version().text() );
+ // global_xCardVersion = vcalendar.properties().version().text();
+ setKolabVersion( note->version() );
+
+ if (!note->x_custom().empty()) {
+ std::vector<Kolab::CustomProperty> customProperties;
+ BOOST_FOREACH(const KolabXSD::CustomType &p, note->x_custom()) {
+ customProperties.push_back(CustomProperty(p.identifier(), p.value()));
+ }
+ n->setCustomProperties(customProperties);
+ }
+ return n;
+ } catch (const xml_schema::exception& e) {
+ std::cerr << e << std::endl;
+ CRITICAL("Failed to read note!");
+ }
+
+ return boost::shared_ptr<T>();
+}
+
+ }//Namespace
+} //Namespace
+
+#endif
\ No newline at end of file
diff --git a/c++/lib/kolabformat.cpp b/c++/lib/kolabformat.cpp
index 51e97d0..d7ac396 100644
--- a/c++/lib/kolabformat.cpp
+++ b/c++/lib/kolabformat.cpp
@@ -22,6 +22,7 @@
#include "xcardconversions.h"
#include "utils.h"
+#include "kolabconversions.h"
namespace Kolab {
@@ -128,18 +129,17 @@ std::string writeDistlist(const DistList &list)
Note readNote(const std::string& s, bool isUrl)
{
-// boost::shared_ptr <Kolab::Note> ptr = deserializeNote(s, isUrl);
-// if (!ptr.get()) {
-// return Kolab::Note();
-// }
-// return *ptr;
+ boost::shared_ptr <Kolab::Note> ptr = Kolab::KolabObjects::deserializeObject<Kolab::Note>(s, isUrl);
+ if (!ptr.get()) {
+ return Kolab::Note();
+ }
+ return *ptr;
return Note();
}
std::string writeNote(const Note ¬e)
{
-// return serializeNote(note);
-return std::string();
+ return Kolab::KolabObjects::serializeObject<Kolab::Note>(note);
}
Configuration readConfiguration(const std::string& s, bool isUrl)
diff --git a/c++/lib/kolabformat.h b/c++/lib/kolabformat.h
index bd9782d..090650c 100644
--- a/c++/lib/kolabformat.h
+++ b/c++/lib/kolabformat.h
@@ -24,6 +24,7 @@
#include "kolabevent.h"
#include "kolabjournal.h"
#include "kolabcontact.h"
+#include "kolabnote.h"
#include "global_definitions.h"
namespace Kolab {
diff --git a/c++/lib/kolabnote.cpp b/c++/lib/kolabnote.cpp
new file mode 100644
index 0000000..c7931bb
--- /dev/null
+++ b/c++/lib/kolabnote.cpp
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf 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/>.
+ */
+
+#include "kolabnote.h"
+
+namespace Kolab {
+
+struct Note::Private
+{
+ Private()
+ : classification(ClassPublic){}
+
+ std::string uid;
+ cDateTime created;
+ cDateTime lastModified;
+ std::vector< std::string > categories;
+ Classification classification;
+
+ std::string summary;
+ std::string description;
+ std::string color;
+
+ std::vector<Attachment> attachments;
+ std::vector<CustomProperty> customProperties;
+};
+
+Note::Note()
+: d(new Note::Private())
+{
+}
+
+Note::Note(const Note &other)
+: d(new Note::Private())
+{
+ *d = *other.d;
+}
+
+Note::~Note()
+{
+}
+
+void Note::operator=(const Kolab::Note &other)
+{
+ *d = *other.d;
+}
+
+bool Note::operator==(const Kolab::Note& other) const
+{
+ return ( d->uid == other.uid() &&
+ d->created == other.created() &&
+ d->lastModified == other.lastModified() &&
+ d->categories == other.categories() &&
+ d->classification == other.classification() &&
+ d->summary == other.summary() &&
+ d->description == other.description() &&
+ d->color == other.color() &&
+ d->attachments == other.attachments() &&
+ d->customProperties == other.customProperties());
+}
+
+bool Note::isValid() const
+{
+ return !d->uid.empty();
+}
+
+void Note::setUid(const std::string &uid)
+{
+ d->uid = uid;
+}
+
+std::string Note::uid() const
+{
+ return d->uid;
+}
+
+void Note::setCreated(const Kolab::cDateTime &created)
+{
+ d->created = created;
+}
+
+cDateTime Note::created() const
+{
+ return d->created;
+}
+
+void Note::setLastModified(const Kolab::cDateTime &lastMod)
+{
+ d->lastModified = lastMod;
+}
+
+cDateTime Note::lastModified() const
+{
+ return d->lastModified;
+}
+
+void Note::setClassification(Classification class_)
+{
+ d->classification = class_;
+}
+
+Classification Note::classification() const
+{
+ return d->classification;
+}
+
+void Note::setCategories(const std::vector< std::string > &categories)
+{
+ d->categories = categories;
+}
+
+void Note::addCategory(const std::string &cat)
+{
+ d->categories.push_back(cat);
+}
+
+std::vector< std::string > Note::categories() const
+{
+ return d->categories;
+}
+
+void Note::setSummary(const std::string &summary)
+{
+ d->summary = summary;
+}
+
+std::string Note::summary() const
+{
+ return d->summary;
+}
+
+void Note::setDescription(const std::string &description)
+{
+ d->description = description;
+}
+
+std::string Note::description() const
+{
+ return d->description;
+}
+
+void Note::setColor(const std::string &color)
+{
+ d->color = color;
+}
+
+std::string Note::color() const
+{
+ return d->color;
+}
+
+void Note::setAttachments(const std::vector< Attachment > &attach)
+{
+ d->attachments = attach;
+}
+
+std::vector< Attachment > Note::attachments() const
+{
+ return d->attachments;
+}
+
+void Note::setCustomProperties(const std::vector< CustomProperty > &prop)
+{
+ d->customProperties = prop;
+}
+
+std::vector< CustomProperty > Note::customProperties() const
+{
+ return d->customProperties;
+}
+
+} //Note
diff --git a/c++/lib/kolabnote.h b/c++/lib/kolabnote.h
new file mode 100644
index 0000000..6edffb6
--- /dev/null
+++ b/c++/lib/kolabnote.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf 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 KOLABNOTE_H
+#define KOLABNOTE_H
+
+#include <string>
+#include <vector>
+#include <boost/scoped_ptr.hpp>
+#include "kolabcontainers.h"
+namespace Kolab {
+
+ class Note {
+ public:
+ Note();
+ ~Note();
+ Note(const Note &);
+ void operator=(const Note &);
+ bool operator==(const Note &) const;
+
+ bool isValid() const;
+
+ void setUid(const std::string &);
+ std::string uid() const;
+
+ void setCreated(const cDateTime &);
+ cDateTime created() const;
+
+ void setLastModified(const cDateTime &);
+ cDateTime lastModified() const;
+
+ void setClassification(Classification);
+ Classification classification() const;
+
+ void setCategories(const std::vector<std::string> &);
+ void addCategory(const std::string &);
+ std::vector<std::string> categories() const;
+
+ void setSummary(const std::string &);
+ std::string summary() const;
+
+ void setDescription(const std::string &);
+ std::string description() const;
+
+ void setColor(const std::string &);
+ std::string color() const;
+
+ void setAttachments(const std::vector<Attachment> &);
+ std::vector<Attachment> attachments() const;
+
+ void setCustomProperties(const std::vector<CustomProperty> &);
+ std::vector<CustomProperty> customProperties() const;
+ private:
+ struct Private;
+ boost::scoped_ptr<Private> d;
+ };
+
+}
+
+#endif
+
diff --git a/c++/lib/shared_conversions.h b/c++/lib/shared_conversions.h
new file mode 100644
index 0000000..253a8a8
--- /dev/null
+++ b/c++/lib/shared_conversions.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 Christian Mollekopf <mollekopf 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 SHAREDCONVERSIONS_H
+#define SHAREDCONVERSIONS_H
+
+#include <xsd/cxx/tree/date-time.hxx>
+#include "kolabcontainers.h"
+#include <boost/shared_ptr.hpp>
+
+namespace Kolab {
+ namespace Shared {
+typedef boost::shared_ptr<cDateTime> cDateTimePtr;
+
+typedef ::xsd::cxx::tree::type type;
+typedef ::xsd::cxx::tree::simple_type< type > simple_type;
+typedef ::xsd::cxx::tree::date< char, simple_type > date;
+typedef ::xsd::cxx::tree::date_time< char, simple_type > date_time;
+
+cDateTimePtr toDate(const date &dt)
+{
+ cDateTimePtr date(new cDateTime());
+ date->setDate(dt.year(), dt.month(), dt.day());
+ return date;
+}
+
+cDateTimePtr toDate(const date_time &dt)
+{
+ cDateTimePtr date(new cDateTime());
+ date->setDate(dt.year(), dt.month(), dt.day());
+ date->setTime(dt.hours(), dt.minutes(), dt.seconds());
+ if (dt.zone_present()) {
+ date->setUTC(true);
+ }
+ return date;
+}
+
+date_time fromDateTime(const cDateTime &d)
+{
+ date_time date(d.year(), d.month(), d.day(), d.hour(), d.minute(), d.second());
+ if (d.isUTC()) {
+ //Setting both zone hours/and zone minutes to zero results in a Z being appended to indicate UTC
+ date.zone_hours(0);
+ date.zone_minutes(0);
+ }
+ return date;
+}
+
+date fromDate(const cDateTime &d)
+{
+ date de(d.year(), d.month(), d.day());
+ return de;
+}
+
+ } //Namespace
+} //Namespace
+
+#endif
\ No newline at end of file
diff --git a/c++/lib/xcalconversions.h b/c++/lib/xcalconversions.h
index ea135ca..e92acf5 100644
--- a/c++/lib/xcalconversions.h
+++ b/c++/lib/xcalconversions.h
@@ -40,6 +40,7 @@
#include "kolabjournal.h"
#include "utils.h"
#include "base64.h"
+#include "shared_conversions.h"
namespace Kolab {
namespace XCAL {
@@ -99,6 +100,7 @@ const char* const START = "START";
const char* const END = "END";
using namespace Kolab::Utils;
+using namespace Kolab::Shared;
//=== Generic Conversions ===
@@ -422,44 +424,8 @@ icalendar_2_0::AttachPropType fromAttachment(const Kolab::Attachment &a)
//==== cDateTime ====
-typedef boost::shared_ptr<cDateTime> cDateTimePtr;
- static cDateTimePtr toDate(const xml_schema::date &dt)
- {
- cDateTimePtr date(new cDateTime());
- date->setDate(dt.year(), dt.month(), dt.day());
- return date;
- }
-
- static cDateTimePtr toDate(const xml_schema::date_time &dt)
- {
- cDateTimePtr date(new cDateTime());
- date->setDate(dt.year(), dt.month(), dt.day());
- date->setTime(dt.hours(), dt.minutes(), dt.seconds());
- if (dt.zone_present()) {
- date->setUTC(true);
- }
- return date;
- }
-
- static xml_schema::date_time fromDateTime(const cDateTime &d)
- {
- xml_schema::date_time date(d.year(), d.month(), d.day(), d.hour(), d.minute(), d.second());
- if (d.isUTC()) {
- //Setting both zone hours/and zone minutes to zero results in a Z being appended to indicate UTC
- date.zone_hours(0);
- date.zone_minutes(0);
- }
- return date;
- }
-
- static xml_schema::date fromDate(const cDateTime &d)
- {
- xml_schema::date date(d.year(), d.month(), d.day());
- return date;
- }
-
- std::string getTimezone(const icalendar_2_0::ArrayOfParameters ¶meters) {
+std::string getTimezone(const icalendar_2_0::ArrayOfParameters ¶meters) {
for (icalendar_2_0::DateDatetimePropertyType::parameters_type::baseParameter_const_iterator it(parameters.baseParameter().begin()); it != parameters.baseParameter().end(); it++) {
if (const icalendar_2_0::TzidParamType* tz = dynamic_cast<const icalendar_2_0::TzidParamType*> (&*it)) {
std::string tzid = tz->text();
@@ -478,9 +444,9 @@ cDateTimePtr toDate(const icalendar_2_0::DateDatetimePropertyType &dtProperty)
{
cDateTimePtr date;
if (dtProperty.date_time()) {
- date = toDate(*dtProperty.date_time());
+ date = Shared::toDate(*dtProperty.date_time());
} else if (dtProperty.date()) {
- date = toDate(*dtProperty.date());
+ date = Shared::toDate(*dtProperty.date());
}
if (dtProperty.parameters()) {
@@ -497,7 +463,7 @@ cDateTimePtr toDate(const icalendar_2_0::UtcDatetimePropertyType &dtProperty)
{
cDateTimePtr date;
if (dtProperty.date_time()) {
- date = toDate(*dtProperty.date_time());
+ date = Shared::toDate(*dtProperty.date_time());
} else { //The utc-date-time element shouldn't even exist
date = cDateTimePtr(new cDateTime());
ERROR("This element shouldn't even be existing");
@@ -513,9 +479,9 @@ std::auto_ptr<I> fromDate(const cDateTime &dt)
{
std::auto_ptr<I> ptr(new I);
if (dt.isDateOnly()) {
- ptr->date(fromDate(dt));
+ ptr->date(Shared::fromDate(dt));
} else {
- ptr->date_time(fromDateTime(dt));
+ ptr->date_time(Shared::fromDateTime(dt));
const std::string &timezone = dt.timezone();
if (timezone.size() != 0) {
@@ -542,11 +508,11 @@ std::vector<cDateTime> toDateTimeList(I datelistProperty)
}
if (!datelistProperty.date().empty()) {
BOOST_FOREACH(const xml_schema::date &d, datelistProperty.date()) {
- list.push_back(*toDate(d));
+ list.push_back(*Shared::toDate(d));
}
} else if (!datelistProperty.date_time().empty()) {
BOOST_FOREACH(const xml_schema::date_time &d, datelistProperty.date_time()) {
- cDateTimePtr date = toDate(d);
+ cDateTimePtr date = Shared::toDate(d);
if (tzid.size()) {
date->setTimezone(tzid);
}
@@ -563,9 +529,9 @@ std::auto_ptr<I> fromDateTimeList(const std::vector<cDateTime> &dtlist)
std::auto_ptr<I> ptr(new I);
BOOST_FOREACH(const cDateTime &dt, dtlist) {
if (dt.isDateOnly()) {
- ptr->date().push_back(fromDate(dt));
+ ptr->date().push_back(Shared::fromDate(dt));
} else {
- ptr->date_time().push_back(fromDateTime(dt));
+ ptr->date_time().push_back(Shared::fromDateTime(dt));
}
//TODO handle utc
//TODO check for equality of timezones?
@@ -586,14 +552,11 @@ std::auto_ptr<I> fromDateTimeList(const std::vector<cDateTime> &dtlist)
return ptr;
}
-
//---- cDateTime ----
-//----------------
-
//=== Attendee ===
std::string mapPartStat(PartStatus status)
@@ -783,9 +746,9 @@ RecurrencePtr toRRule(const icalendar_2_0::RecurType &rrule)
if (rrule.until()) {
cDateTimePtr date;
if ((*rrule.until()).date_time()) {
- date = toDate(*(*rrule.until()).date_time());
+ date = Shared::toDate(*(*rrule.until()).date_time());
} else if ((*rrule.until()).date()) {
- date = toDate(*(*rrule.until()).date());
+ date = Shared::toDate(*(*rrule.until()).date());
}
r->setEnd(*date);
} else if (rrule.count()) {
@@ -1003,9 +966,9 @@ std::auto_ptr< icalendar_2_0::RrulePropType > recurrenceProperty(const Recurrenc
if (endDate.isValid()) {
RecurPropertyType::recur_type::until_type until;
if (endDate.isDateOnly()) {
- until.date(fromDate(endDate));
+ until.date(Shared::fromDate(endDate));
} else {
- until.date_time(fromDateTime(endDate));
+ until.date_time(Shared::fromDateTime(endDate));
}
recur.until(until);
} else if (r.count() > 0) {
@@ -1334,7 +1297,7 @@ void getAlarms(IncidenceType &incidence, const typename KolabType::components_ty
}
if (prop.trigger().date_time()) {
- alarm.setStart(*toDate(*prop.trigger().date_time()));
+ alarm.setStart(*Shared::toDate(*prop.trigger().date_time()));
if (!alarm.start().isUTC()) {
ERROR("The start date time must be in UTC ");
continue;
diff --git a/c++/tests/bindingstest.cpp b/c++/tests/bindingstest.cpp
index 1d8877a..09dd294 100644
--- a/c++/tests/bindingstest.cpp
+++ b/c++/tests/bindingstest.cpp
@@ -23,6 +23,30 @@
+void BindingsTest::noteCompletness()
+{
+ Kolab::Note note;
+ note.setUid("UID");
+ note.setCreated(Kolab::cDateTime(2006,1,6,12,0,0)); //UTC
+ note.setClassification(Kolab::ClassConfidential);
+ note.addCategory("Category");
+ note.setSummary("summary");
+ note.setDescription("description");
+ note.setColor("color");
+ const std::string &result = Kolab::writeNote(note);
+ std::cout << result << std::endl;
+
+ const Kolab::Note &re = Kolab::readNote(result, false);
+ QCOMPARE(re.uid(), note.uid());
+ QCOMPARE(re.created(), note.created());
+ QCOMPARE(re.classification(), note.classification());
+ QCOMPARE(re.categories(), note.categories());
+ QCOMPARE(re.summary(), note.summary());
+ QCOMPARE(re.description(), note.description());
+ QCOMPARE(re.color(), note.color());
+}
+
+
// void BindingsTest::eventCompletness_data()
template <typename T>
void setIncidence(T &ev)
@@ -221,7 +245,7 @@ void BindingsTest::todoCompletness()
std::string result = Kolab::writeTodo(ev);
QVERIFY(Kolab::error() == Kolab::NoError);
- std::cout << result << endl;
+// std::cout << result << endl;
Kolab::Todo e = Kolab::readTodo(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
checkIncidence(ev, e);
@@ -289,7 +313,7 @@ void BindingsTest::journalCompletness()
std::string result = Kolab::writeJournal(ev);
QVERIFY(Kolab::error() == Kolab::NoError);
- std::cout << result << endl;
+// std::cout << result << endl;
Kolab::Journal re = Kolab::readJournal(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
@@ -446,7 +470,7 @@ void BindingsTest::distlistCompletness()
const std::string result = Kolab::writeDistlist(c);
QVERIFY(Kolab::error() == Kolab::NoError);
- std::cout << result << endl;
+// std::cout << result << endl;
Kolab::DistList e = Kolab::readDistlist(result, false);
QVERIFY(Kolab::error() == Kolab::NoError);
QCOMPARE(e.uid(), c.uid());
diff --git a/c++/tests/bindingstest.h b/c++/tests/bindingstest.h
index 7920b92..f62c0b8 100644
--- a/c++/tests/bindingstest.h
+++ b/c++/tests/bindingstest.h
@@ -22,6 +22,7 @@ class BindingsTest : public QObject
private slots:
//Kolabformat
+ void noteCompletness();
void eventCompletness();
void eventDuration();
void todoCompletness();
diff --git a/schemas/kolabformat.xsd b/schemas/kolabformat.xsd
index cacf52f..4549ed8 100644
--- a/schemas/kolabformat.xsd
+++ b/schemas/kolabformat.xsd
@@ -1,62 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xcal="urn:ietf:params:xml:ns:icalendar-2.0"
- xmlns:xcard="urn:ietf:params:xml:ns:vcard-4.0"
targetNamespace="http://kolab.org"
xmlns="http://kolab.org"
elementFormDefault="qualified">
-<!-- <xs:import schemaLocation="iCalendar.xsd" namespace="urn:ietf:params:xml:ns:icalendar-2.0"/>
- <xs:import schemaLocation="xCard.xsd" namespace="urn:ietf:params:xml:ns:vcard-4.0"/>-->
-
+
<xs:complexType name="KolabBase">
<xs:attribute name="version" type="xs:string" fixed="3.0dev1" />
</xs:complexType>
-<!-- <xs:element ref="xcal:vevent"/> -->
-
-<!-- <xs:complexType name="Event">
- <xs:complexContent mixed="false">
- <xs:extension base="KolabBase">
- <xs:sequence>
- <xs:element ref="xcal:vevent" minOccurs="1" maxOccurs="1"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>-->
-
-<!-- <xs:element name="todo" type="Todo"/>
- <xs:complexType name="Todo">
- <xs:complexContent mixed="false">
- <xs:extension base="KolabBase">
- <xs:sequence>
- <xs:element ref="xcal:vtodo" minOccurs="1" maxOccurs="1"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>-->
-
-<!-- <xs:element name="note" type="Note"/>
- <xs:complexType name="Note">
- <xs:complexContent mixed="false">
- <xs:extension base="KolabBase">
- <xs:sequence>
- <xs:element ref="xcal:vjournal" minOccurs="1" maxOccurs="1"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>-->
-
-
- <xs:complexType name="CustomType" >
+
+ <xs:complexType name="attachmentPropType">
+ <xs:sequence>
+ <xs:element name="parameters">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="fmttype" type="xs:string" />
+ <xs:element name="x-label" type="xs:string" minOccurs="0"/>
+ <xs:element name="encoding" type="xs:string" fixed="BASE64" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:choice>
+ <xs:element name="uri" type="xs:string" />
+ <xs:element name="binary" type="xs:string" />
+ </xs:choice>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="attachment" type="attachmentPropType" />
+
+
+ <xs:simpleType name="classifcationPropType">
+ <xs:restriction base="xs:token">
+ <xs:enumeration value="PUBLIC"/>
+ <xs:enumeration value="PRIVATE"/>
+ <xs:enumeration value="CONFIDENTIAL"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+ <xs:element name="classification" type="classifcationPropType" />
+
+
+ <xs:complexType name="CustomType" >
+ <xs:sequence>
+ <xs:element name="identifier" type="xs:string"/>
+ <xs:element name="value" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="x-custom" type="CustomType" />
+
+
+ <xs:complexType name="Note">
+ <xs:complexContent mixed="false">
+ <xs:extension base="KolabBase">
<xs:sequence>
- <xs:element name="identifier" type="xs:string"/>
- <xs:element name="value" type="xs:string"/>
+ <xs:element name="uid" type="xs:string"/>
+ <xs:element name="prodid" type="xs:string"/>
+ <xs:element name="creation-date" type="xs:dateTime"/>
+ <xs:element name="last-modification-date" type="xs:dateTime"/>
+ <xs:element name="categories" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="classification" type="classifcationPropType" minOccurs="0" />
+ <xs:element name="attachment" type="attachmentPropType" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="summary" type="xs:string" minOccurs="0" />
+ <xs:element name="description" type="xs:string" minOccurs="0" />
+ <xs:element name="color" type="xs:string" minOccurs="0" />
+ <xs:element name="x-custom" type="CustomType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
- </xs:complexType>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="note" type="Note"/>
- <xs:element name="x-kolab-custom" type="CustomType" />
</xs:schema>
\ No newline at end of file
commit b065f8a6f90f903a233d2533219bdcec1a67ea17
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu Mar 8 11:24:47 2012 +0100
The start date is mandatory for events.
diff --git a/c++/lib/xcalconversions.h b/c++/lib/xcalconversions.h
index 9259a81..ea135ca 100644
--- a/c++/lib/xcalconversions.h
+++ b/c++/lib/xcalconversions.h
@@ -1425,6 +1425,10 @@ template < > struct IncidenceTrait <Kolab::Event>
getIncidenceProperties<icalendar_2_0::KolabEvent::properties_type>(prop, event);
getTodoEventProperties<icalendar_2_0::KolabEvent::properties_type>(prop, event);
+ if (!event.start().isValid()) {
+ ERROR("Start date is missing, but is mandatory for events");
+ }
+
if (event.end().isValid()) {
prop.dtend(fromDate<icalendar_2_0::KolabEvent::properties_type::dtend_type>(event.end()));
} else if (event.duration().isValid()) {
@@ -1445,6 +1449,10 @@ template < > struct IncidenceTrait <Kolab::Event>
{
const icalendar_2_0::KolabEvent::properties_type &prop = vevent.properties();
+ if (!prop.dtstart()) {
+ ERROR("Start date is missing, but is mandatory for events");
+ }
+
setIncidenceProperties<Kolab::Event, icalendar_2_0::KolabEvent::properties_type>(event, prop);
setTodoEventProperties<Kolab::Event, icalendar_2_0::KolabEvent::properties_type>(event, prop);
diff --git a/c++/tests/bindingstest.cpp b/c++/tests/bindingstest.cpp
index 6493498..1d8877a 100644
--- a/c++/tests/bindingstest.cpp
+++ b/c++/tests/bindingstest.cpp
@@ -198,6 +198,7 @@ void BindingsTest::eventCompletness()
void BindingsTest::eventDuration()
{
Kolab::Event ev;
+ ev.setStart(Kolab::cDateTime("Europe/Zurich", 2006,1,8,12,0,0));
ev.setDuration(Kolab::Duration(11,22,33,44, true));
const std::string result = Kolab::writeEvent(ev);
More information about the commits
mailing list