Branch 'libkolabxml-0.8' - 11 commits - CMakeLists.txt schemas/kolabformat.xsd src/CMakeLists.txt src/containers src/kolabconversions.h src/kolabformat.cpp src/kolabformat.h src/kolabformat.i tests/bindingstest.cpp tests/bindingstest.h utils/CMakeLists.txt utils/kolabformatchecker.cpp
Christian Mollekopf
mollekopf at kolabsys.com
Wed Feb 20 20:55:10 CET 2013
CMakeLists.txt | 11 ++
schemas/kolabformat.xsd | 20 +++++
src/CMakeLists.txt | 2
src/containers/kolabfile.cpp | 161 +++++++++++++++++++++++++++++++++++++++++++
src/containers/kolabfile.h | 69 ++++++++++++++++++
src/kolabconversions.h | 155 +++++++++++++++++++++++++++++++++++++++++
src/kolabformat.cpp | 14 +++
src/kolabformat.h | 4 +
src/kolabformat.i | 7 +
tests/bindingstest.cpp | 29 +++++++
tests/bindingstest.h | 1
utils/CMakeLists.txt | 5 +
utils/kolabformatchecker.cpp | 99 ++++++++++++++++++++++++++
13 files changed, 574 insertions(+), 3 deletions(-)
New commits:
commit 1488ec0ed67ab30db7e0bbf2216c0133a091fa82
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Feb 20 20:54:49 2013 +0100
Prepare for release of 0.8.3
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f5cae5..2d869e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,7 +43,7 @@ endif()
set (Libkolabxml_VERSION_MAJOR 0)
set (Libkolabxml_VERSION_MINOR 9)
# Enable the full x.y.z version only for release versions
-set (Libkolabxml_VERSION_PATCH 2)
+set (Libkolabxml_VERSION_PATCH 3)
set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}.${Libkolabxml_VERSION_PATCH}" )
# set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}" )
commit 0d52cded025e019290534e4046fe639bca2ca296
Merge: f484d10 c78d5fd
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Feb 20 20:46:27 2013 +0100
Merge branch 'files' into 0.8
Conflicts:
CMakeLists.txt
diff --cc CMakeLists.txt
index 5ab195a,7c002c8..8f5cae5
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@@ -40,11 -41,11 +41,11 @@@ endif(
# 0.2 (0.2 development version)
set (Libkolabxml_VERSION_MAJOR 0)
- set (Libkolabxml_VERSION_MINOR 8)
+ set (Libkolabxml_VERSION_MINOR 9)
# Enable the full x.y.z version only for release versions
-#set (Libkolabxml_VERSION_PATCH 1)
-#set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}.${Libkolabxml_VERSION_PATCH}" )
-set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}" )
+set (Libkolabxml_VERSION_PATCH 2)
+set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}.${Libkolabxml_VERSION_PATCH}" )
+# set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}" )
set (Libkolabxml_VERSION_STRING ${CMAKE_PROJECT_NAME}-${Libkolabxml_VERSION})
set (KOLAB_FORMAT_VERSION "3.0dev1")
diff --cc tests/bindingstest.h
index dbd2c76,685167b..a920818
--- a/tests/bindingstest.h
+++ b/tests/bindingstest.h
@@@ -25,9 -25,9 +25,10 @@@ class BindingsTest : public QObjec
void categorycolorConfigurationCompletness();
void dictionaryConfigurationCompletness();
void noteCompletness();
+ void fileCompletness();
void eventCompletness();
void eventDuration();
+ void eventExceptions();
void todoCompletness();
void dueDateDateOnly();
void journalCompletness();
commit c78d5fdca2b1c292baf472dce4478dd24519e391
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Mon Jan 14 19:19:37 2013 +0100
support file objects in kolabformatchecker.
diff --git a/utils/kolabformatchecker.cpp b/utils/kolabformatchecker.cpp
index fc7df21..da1ff63 100644
--- a/utils/kolabformatchecker.cpp
+++ b/utils/kolabformatchecker.cpp
@@ -38,6 +38,7 @@ int main(int argc, char *argv[])
("freebusy", "parse freebusy")
("note", "parse note")
("configuration", "parse configuration")
+ ("file", "parse file")
("input-file", po::value<std::vector<std::string> >(), "input files of given type")
;
@@ -81,6 +82,8 @@ int main(int argc, char *argv[])
Kolab::readNote(*it, true);
} else if (vm.count("configuration")) {
Kolab::readConfiguration(*it, true);
+ } else if (vm.count("file")) {
+ Kolab::readFile(*it, true);
} else {
cout << "Specify type";
return -1;
commit 3f281f354248eb90694af82f344021f5c27e6f9f
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Nov 2 00:37:54 2012 +0100
Renamed the attachment property to file, to stress the difference between the xcal attachment property and this one.
diff --git a/schemas/kolabformat.xsd b/schemas/kolabformat.xsd
index 56ed6b8..0e8c8d8 100644
--- a/schemas/kolabformat.xsd
+++ b/schemas/kolabformat.xsd
@@ -86,7 +86,7 @@
<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" />
+ <xs:element name="file" type="attachmentPropType" />
<xs:element name="note" type="xs:string" minOccurs="0" />
<xs:element name="x-custom" type="CustomType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
diff --git a/src/containers/kolabfile.cpp b/src/containers/kolabfile.cpp
index 556ef04..cc4ec8e 100644
--- a/src/containers/kolabfile.cpp
+++ b/src/containers/kolabfile.cpp
@@ -64,7 +64,7 @@ bool File::operator==(const Kolab::File& other) const
d->categories == other.categories() &&
d->classification == other.classification() &&
d->note == other.note() &&
- d->attachment == other.attachment() &&
+ d->attachment == other.file() &&
d->customProperties == other.customProperties());
}
@@ -138,12 +138,12 @@ std::string File::note() const
return d->note;
}
-void File::setAttachment(const Attachment &attach)
+void File::setFile(const Attachment &attach)
{
d->attachment = attach;
}
-Attachment File::attachment() const
+Attachment File::file() const
{
return d->attachment;
}
diff --git a/src/containers/kolabfile.h b/src/containers/kolabfile.h
index 90e7750..767893e 100644
--- a/src/containers/kolabfile.h
+++ b/src/containers/kolabfile.h
@@ -53,8 +53,8 @@ namespace Kolab {
void setNote(const std::string &);
std::string note() const;
- void setAttachment(const Attachment &);
- Attachment attachment() const;
+ void setFile(const Attachment &);
+ Attachment file() const;
void setCustomProperties(const std::vector<CustomProperty> &);
std::vector<CustomProperty> customProperties() const;
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 583f56f..3fffa1b 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -295,7 +295,7 @@ std::string serializeObject <Kolab::File> (const Kolab::File &file, const std::s
ERROR("missing filename");
}
- KolabXSD::File n(uid, getProductId(prod), created, lastModificationDate, fromAttachment(file.attachment()));
+ KolabXSD::File n(uid, getProductId(prod), created, lastModificationDate, fromAttachment(file.file()));
if (!file.categories().empty()) {
KolabXSD::File::categories_sequence categories;
@@ -549,14 +549,14 @@ boost::shared_ptr<Kolab::File> deserializeObject <Kolab::File> (const std::strin
}
}
- const Kolab::Attachment &attachment = toAttachment(file->attachment());
+ const Kolab::Attachment &attachment = toAttachment(file->file());
if (attachment.label().empty()) {
ERROR("Missing filename");
}
if (!attachment.isValid()) {
ERROR("invalid attachment");
}
- n->setAttachment(attachment);
+ n->setFile(attachment);
if (file->note()) {
n->setNote(*file->note());
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index 5b5e196..468bce9 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -128,7 +128,7 @@ void BindingsTest::fileCompletness()
Kolab::Attachment attachment;
attachment.setData("data", "mimetype");
attachment.setLabel("label");
- file.setAttachment(attachment);
+ file.setFile(attachment);
const std::string &result = Kolab::writeFile(file);
QCOMPARE(Kolab::error(), Kolab::NoError);
@@ -142,7 +142,7 @@ void BindingsTest::fileCompletness()
QCOMPARE(re.classification(), file.classification());
QCOMPARE(re.categories(), file.categories());
QCOMPARE(re.note(), file.note());
- QCOMPARE(re.attachment(), file.attachment());
+ QCOMPARE(re.file(), file.file());
}
commit 95061b30ccc2e63e162e3510e6de5c0292c0a7dd
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Nov 2 00:36:31 2012 +0100
Made the filename mandatory.
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 210cd20..583f56f 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -291,6 +291,9 @@ std::string serializeObject <Kolab::File> (const Kolab::File &file, const std::s
// WARNING("missing last_modification_date, fallback to current timestamp");
lastModificationDate = fromDateTime(timestamp());
}
+ if (file.file().label().empty()) {
+ ERROR("missing filename");
+ }
KolabXSD::File n(uid, getProductId(prod), created, lastModificationDate, fromAttachment(file.attachment()));
@@ -547,6 +550,9 @@ boost::shared_ptr<Kolab::File> deserializeObject <Kolab::File> (const std::strin
}
const Kolab::Attachment &attachment = toAttachment(file->attachment());
+ if (attachment.label().empty()) {
+ ERROR("Missing filename");
+ }
if (!attachment.isValid()) {
ERROR("invalid attachment");
}
commit f3abd08a4134c550179e485b98260a1d72ea032f
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Oct 26 18:22:44 2012 +0200
php already has a function called readfile.
diff --git a/src/kolabformat.i b/src/kolabformat.i
index ed3499c..c266df0 100644
--- a/src/kolabformat.i
+++ b/src/kolabformat.i
@@ -42,6 +42,9 @@ namespace std {
/* %template(vectorevent2) vector< vector<Kolab::Event> >;*/
};
+%rename(readKolabFile) Kolab::readFile;
+%rename(writeKolabFile) Kolab::writeFile;
+
%include "global_definitions.h"
%include "kolabformat.h"
%include "containers/kolabcontainers.h"
commit 5a08f620229570def2b04f386673d210afdcc6b4
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Oct 26 17:53:34 2012 +0200
Forgot to install the header file.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index db09949..3527408 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -55,6 +55,7 @@ install( FILES
containers/kolabcontainers.h
containers/kolabconfiguration.h
containers/kolabfreebusy.h
+ containers/kolabfile.h
global_definitions.h
DESTINATION ${INCLUDE_INSTALL_DIR})
commit c59639ac956c3a8468c30b3d858526dbd280e168
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Wed Oct 24 18:51:49 2012 +0200
Added implementation of the File format.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1d32e5f..7c002c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -136,7 +136,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 --root-element note --root-element configuration --output-dir ${CMAKE_BINARY_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 --root-element configuration --root-element file --output-dir ${CMAKE_BINARY_DIR}/bindings ${SCHEMAS}
COMMENT "Generating XSD bindings"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${SCHEMAS}
diff --git a/schemas/kolabformat.xsd b/schemas/kolabformat.xsd
index 4edaafb..56ed6b8 100644
--- a/schemas/kolabformat.xsd
+++ b/schemas/kolabformat.xsd
@@ -75,6 +75,26 @@
</xs:complexType>
<xs:element name="note" type="Note"/>
+
+ <xs:complexType name="File">
+ <xs:complexContent mixed="false">
+ <xs:extension base="KolabBase">
+ <xs:sequence>
+ <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" />
+ <xs:element name="note" type="xs:string" minOccurs="0" />
+ <xs:element name="x-custom" type="CustomType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="file" type="File"/>
<xs:simpleType name="ConfigurationType">
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 94a3de0..db09949 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -15,6 +15,7 @@ add_library(kolabxml SHARED
containers/kolabcontact.cpp
containers/kolabconfiguration.cpp
containers/kolabfreebusy.cpp
+ containers/kolabfile.cpp
utils.cpp base64.cpp uriencode.cpp
../compiled/XMLParserWrapper.cpp
../compiled/grammar-input-stream.cxx
diff --git a/src/containers/kolabfile.cpp b/src/containers/kolabfile.cpp
new file mode 100644
index 0000000..556ef04
--- /dev/null
+++ b/src/containers/kolabfile.cpp
@@ -0,0 +1,161 @@
+/*
+ * 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 "kolabfile.h"
+
+namespace Kolab {
+
+struct File::Private
+{
+ Private()
+ : classification(ClassPublic){}
+
+ std::string uid;
+ cDateTime created;
+ cDateTime lastModified;
+ std::vector< std::string > categories;
+ Classification classification;
+
+ std::string note;
+
+ Attachment attachment;
+ std::vector<CustomProperty> customProperties;
+};
+
+File::File()
+: d(new File::Private())
+{
+}
+
+File::File(const File &other)
+: d(new File::Private())
+{
+ *d = *other.d;
+}
+
+File::~File()
+{
+}
+
+void File::operator=(const Kolab::File &other)
+{
+ *d = *other.d;
+}
+
+bool File::operator==(const Kolab::File& other) const
+{
+ return ( d->uid == other.uid() &&
+ d->created == other.created() &&
+ d->lastModified == other.lastModified() &&
+ d->categories == other.categories() &&
+ d->classification == other.classification() &&
+ d->note == other.note() &&
+ d->attachment == other.attachment() &&
+ d->customProperties == other.customProperties());
+}
+
+bool File::isValid() const
+{
+ return !d->uid.empty();
+}
+
+void File::setUid(const std::string &uid)
+{
+ d->uid = uid;
+}
+
+std::string File::uid() const
+{
+ return d->uid;
+}
+
+void File::setCreated(const Kolab::cDateTime &created)
+{
+ d->created = created;
+}
+
+cDateTime File::created() const
+{
+ return d->created;
+}
+
+void File::setLastModified(const Kolab::cDateTime &lastMod)
+{
+ d->lastModified = lastMod;
+}
+
+cDateTime File::lastModified() const
+{
+ return d->lastModified;
+}
+
+void File::setClassification(Classification class_)
+{
+ d->classification = class_;
+}
+
+Classification File::classification() const
+{
+ return d->classification;
+}
+
+void File::setCategories(const std::vector< std::string > &categories)
+{
+ d->categories = categories;
+}
+
+void File::addCategory(const std::string &cat)
+{
+ d->categories.push_back(cat);
+}
+
+std::vector< std::string > File::categories() const
+{
+ return d->categories;
+}
+
+void File::setNote(const std::string ¬e)
+{
+ d->note = note;
+}
+
+std::string File::note() const
+{
+ return d->note;
+}
+
+void File::setAttachment(const Attachment &attach)
+{
+ d->attachment = attach;
+}
+
+Attachment File::attachment() const
+{
+ return d->attachment;
+}
+
+void File::setCustomProperties(const std::vector< CustomProperty > &prop)
+{
+ d->customProperties = prop;
+}
+
+std::vector< CustomProperty > File::customProperties() const
+{
+ return d->customProperties;
+}
+
+} //File
diff --git a/src/containers/kolabfile.h b/src/containers/kolabfile.h
new file mode 100644
index 0000000..90e7750
--- /dev/null
+++ b/src/containers/kolabfile.h
@@ -0,0 +1,69 @@
+/*
+ * 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 KOLABFILE_H
+#define KOLABFILE_H
+
+#include <string>
+#include <vector>
+#include <boost/scoped_ptr.hpp>
+#include "kolabcontainers.h"
+namespace Kolab {
+
+ class File {
+ public:
+ File();
+ ~File();
+ File(const File &);
+ void operator=(const File &);
+ bool operator==(const File &) 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 setNote(const std::string &);
+ std::string note() const;
+
+ void setAttachment(const Attachment &);
+ Attachment attachment() const;
+
+ void setCustomProperties(const std::vector<CustomProperty> &);
+ std::vector<CustomProperty> customProperties() const;
+ private:
+ struct Private;
+ boost::scoped_ptr<Private> d;
+ };
+
+}
+
+#endif
+
diff --git a/src/kolabconversions.h b/src/kolabconversions.h
index 1a9eb86..210cd20 100644
--- a/src/kolabconversions.h
+++ b/src/kolabconversions.h
@@ -33,6 +33,7 @@
#include "kolabnote.h"
#include "shared_conversions.h"
#include "kolabconfiguration.h"
+#include "kolabfile.h"
#include "base64.h"
namespace Kolab {
@@ -269,6 +270,76 @@ std::string serializeObject <Kolab::Note> (const Kolab::Note ¬e, const std::s
return std::string();
}
+template <>
+std::string serializeObject <Kolab::File> (const Kolab::File &file, const std::string prod)
+{
+ clearErrors();
+ try {
+ const std::string &uid = getUID(file.uid());
+ setCreatedUid(uid);
+
+ KolabXSD::File::creation_date_type created(0,0,0,0,0,0);
+ if (file.created().isValid()) {
+ created = fromDateTime(file.created());
+ } else {
+ created = fromDateTime(timestamp());
+ }
+ KolabXSD::File::last_modification_date_type lastModificationDate(0,0,0,0,0,0);
+ if (file.lastModified().isValid()) {
+ lastModificationDate = fromDateTime(file.lastModified());
+ } else {
+// WARNING("missing last_modification_date, fallback to current timestamp");
+ lastModificationDate = fromDateTime(timestamp());
+ }
+
+ KolabXSD::File n(uid, getProductId(prod), created, lastModificationDate, fromAttachment(file.attachment()));
+
+ if (!file.categories().empty()) {
+ KolabXSD::File::categories_sequence categories;
+ const std::vector<std::string> &l = file.categories();
+ BOOST_FOREACH(const std::string &c, l) {
+ categories.push_back(c);
+ }
+ n.categories(categories);
+ }
+ switch (file.classification()) {
+ case Kolab::ClassPublic:
+ n.classification(KolabXSD::File::classification_type::PUBLIC);
+ break;
+ case Kolab::ClassPrivate:
+ n.classification(KolabXSD::File::classification_type::PRIVATE);
+ break;
+ case Kolab::ClassConfidential:
+ n.classification(KolabXSD::File::classification_type::CONFIDENTIAL);
+ break;
+ default:
+ ERROR("unknown classification");
+ }
+
+ n.note(file.note());
+
+ if (!file.customProperties().empty()) {
+ const std::vector<Kolab::CustomProperty> &l = file.customProperties();
+ BOOST_FOREACH(const Kolab::CustomProperty &a, l) {
+ n.x_custom().push_back(KolabXSD::CustomType(a.identifier, a.value));
+ }
+ }
+
+ xml_schema::namespace_infomap map;
+ map[""].name = KOLAB_NAMESPACE;
+
+ std::ostringstream ostringstream;
+ KolabXSD::file(ostringstream, n, map);
+ return ostringstream.str();
+ } catch (const xml_schema::exception& e) {
+ std::cerr << e << std::endl;
+ } catch (...) {
+ CRITICAL("Unhandled exception");
+ }
+ CRITICAL("Failed to write file!");
+ return std::string();
+}
+
template <typename T>
boost::shared_ptr<T> deserializeObject(const std::string& s, bool isUrl);
@@ -428,6 +499,84 @@ boost::shared_ptr<Kolab::Configuration> deserializeObject <Kolab::Configuration>
CRITICAL("Failed to read configuration!");
return boost::shared_ptr<Kolab::Configuration>();
}
+
+template <>
+boost::shared_ptr<Kolab::File> deserializeObject <Kolab::File> (const std::string& s, bool isUrl)
+{
+ clearErrors();
+ try {
+ std::auto_ptr<KolabXSD::File> file;
+ if (isUrl) {
+ xsd::cxx::xml::dom::auto_ptr <xercesc::DOMDocument > doc = XMLParserWrapper::inst().parseFile(s);
+ if (doc.get()) {
+ file = KolabXSD::file(doc);
+ }
+ } else {
+ xsd::cxx::xml::dom::auto_ptr <xercesc::DOMDocument > doc = XMLParserWrapper::inst().parseString(s);
+ if (doc.get()) {
+ file = KolabXSD::file(doc);
+ }
+ }
+
+ if (!file.get()) {
+ CRITICAL("failed to parse file!");
+ return boost::shared_ptr<Kolab::File>();
+ }
+
+ boost::shared_ptr<Kolab::File> n = boost::shared_ptr<Kolab::File>(new Kolab::File);
+ n->setUid(file->uid());
+ n->setCreated(*toDate(file->creation_date()));
+ n->setLastModified(*toDate(file->last_modification_date()));
+ std::vector<std::string> categories;
+ std::copy(file->categories().begin(), file->categories().end(), std::back_inserter(categories));
+ n->setCategories(categories);
+ if (file->classification()) {
+ switch (*file->classification()) {
+ case KolabXSD::File::classification_type::PUBLIC:
+ n->setClassification(Kolab::ClassPublic);
+ break;
+ case KolabXSD::File::classification_type::PRIVATE:
+ n->setClassification(Kolab::ClassPrivate);
+ break;
+ case KolabXSD::File::classification_type::CONFIDENTIAL:
+ n->setClassification(Kolab::ClassConfidential);
+ break;
+ default:
+ ERROR("unknown classification");
+ }
+ }
+
+ const Kolab::Attachment &attachment = toAttachment(file->attachment());
+ if (!attachment.isValid()) {
+ ERROR("invalid attachment");
+ }
+ n->setAttachment(attachment);
+
+ if (file->note()) {
+ n->setNote(*file->note());
+ }
+
+ setProductId( file->prodid() );
+ // setFormatVersion( vcards->vcard().version().text() );
+ // global_xCardVersion = vcalendar.properties().version().text();
+ setKolabVersion( file->version() );
+
+ if (!file->x_custom().empty()) {
+ std::vector<Kolab::CustomProperty> customProperties;
+ BOOST_FOREACH(const KolabXSD::CustomType &p, file->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;
+ } catch (...) {
+ CRITICAL("Unhandled exception");
+ }
+ CRITICAL("Failed to read file!");
+ return boost::shared_ptr<Kolab::File>();
+}
}//Namespace
} //Namespace
diff --git a/src/kolabformat.cpp b/src/kolabformat.cpp
index 20eb11d..90c7ead 100644
--- a/src/kolabformat.cpp
+++ b/src/kolabformat.cpp
@@ -169,6 +169,20 @@ std::string writeNote(const Note ¬e, const std::string& productId)
return Kolab::KolabObjects::serializeObject<Kolab::Note>(note, productId);
}
+File readFile(const std::string& s, bool isUrl)
+{
+ boost::shared_ptr <Kolab::File> ptr = Kolab::KolabObjects::deserializeObject<Kolab::File>(s, isUrl);
+ if (!ptr.get()) {
+ return Kolab::File();
+ }
+ return *ptr;
+}
+
+std::string writeFile(const File &file, const std::string& productId)
+{
+ return Kolab::KolabObjects::serializeObject<Kolab::File>(file, productId);
+}
+
Configuration readConfiguration(const std::string& s, bool isUrl)
{
boost::shared_ptr <Kolab::Configuration> ptr = Kolab::KolabObjects::deserializeObject<Kolab::Configuration>(s, isUrl);
diff --git a/src/kolabformat.h b/src/kolabformat.h
index 3ed55e8..cf78a50 100644
--- a/src/kolabformat.h
+++ b/src/kolabformat.h
@@ -27,6 +27,7 @@
#include "kolabnote.h"
#include "kolabconfiguration.h"
#include "kolabfreebusy.h"
+#include "kolabfile.h"
#include "global_definitions.h"
namespace Kolab {
@@ -122,6 +123,9 @@ std::string writeNote(const Kolab::Note &, const std::string& productId = std::s
Kolab::Configuration readConfiguration(const std::string& s, bool isUrl);
std::string writeConfiguration(const Kolab::Configuration &, const std::string& productId = std::string());
+Kolab::File readFile(const std::string& s, bool isUrl);
+std::string writeFile(const Kolab::File &, const std::string& productId = std::string());
+
}
#endif // KOLABFORMAT_H
diff --git a/src/kolabformat.i b/src/kolabformat.i
index 5776f96..ed3499c 100644
--- a/src/kolabformat.i
+++ b/src/kolabformat.i
@@ -14,6 +14,7 @@
#include "containers/kolabcontact.h"
#include "containers/kolabnote.h"
#include "containers/kolabconfiguration.h"
+ #include "containers/kolabfile.h"
%}
%include "std_string.i"
@@ -37,6 +38,8 @@ namespace std {
%template(vectorurl) vector<Kolab::Url>;
%template(vectorkey) vector<Kolab::Key>;
%template(vectorcategorycolor) vector<Kolab::CategoryColor>;
+/* %template(vectorevent) vector<Kolab::Event>;*/
+/* %template(vectorevent2) vector< vector<Kolab::Event> >;*/
};
%include "global_definitions.h"
@@ -48,3 +51,4 @@ namespace std {
%include "containers/kolabcontact.h"
%include "containers/kolabnote.h"
%include "containers/kolabconfiguration.h"
+%include "containers/kolabfile.h"
diff --git a/tests/bindingstest.cpp b/tests/bindingstest.cpp
index 912e5c6..5b5e196 100644
--- a/tests/bindingstest.cpp
+++ b/tests/bindingstest.cpp
@@ -116,6 +116,35 @@ void BindingsTest::noteCompletness()
QCOMPARE(re.attachments(), note.attachments());
}
+void BindingsTest::fileCompletness()
+{
+ Kolab::File file;
+ file.setUid("UID");
+ file.setCreated(Kolab::cDateTime(2006,1,6,12,0,0,true)); //UTC
+ file.setLastModified(Kolab::cDateTime(2006,1,6,12,0,0,true)); //UTC
+ file.setClassification(Kolab::ClassConfidential);
+ file.addCategory("Category");
+ file.setNote("summary");
+ Kolab::Attachment attachment;
+ attachment.setData("data", "mimetype");
+ attachment.setLabel("label");
+ file.setAttachment(attachment);
+
+ const std::string &result = Kolab::writeFile(file);
+ QCOMPARE(Kolab::error(), Kolab::NoError);
+// std::cout << result << std::endl;
+
+ const Kolab::File &re = Kolab::readFile(result, false);
+ QCOMPARE(Kolab::error(), Kolab::NoError);
+ QCOMPARE(re.uid(), file.uid());
+ QCOMPARE(re.created(), file.created());
+ QCOMPARE(re.lastModified(), file.lastModified());
+ QCOMPARE(re.classification(), file.classification());
+ QCOMPARE(re.categories(), file.categories());
+ QCOMPARE(re.note(), file.note());
+ QCOMPARE(re.attachment(), file.attachment());
+}
+
// void BindingsTest::eventCompletness_data()
template <typename T>
diff --git a/tests/bindingstest.h b/tests/bindingstest.h
index 86fd7d7..685167b 100644
--- a/tests/bindingstest.h
+++ b/tests/bindingstest.h
@@ -25,6 +25,7 @@ class BindingsTest : public QObject
void categorycolorConfigurationCompletness();
void dictionaryConfigurationCompletness();
void noteCompletness();
+ void fileCompletness();
void eventCompletness();
void eventDuration();
void todoCompletness();
commit bf38efb1ab1efffd30afe39b0807ed77f9bbe279
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu Oct 11 12:40:29 2012 +0200
Added format checker to validate xml files.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8ff9af1..1d32e5f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,7 @@ endif()
cmake_minimum_required(VERSION 2.6)
option( BUILD_TESTS "Build the tests" TRUE )
+option( BUILD_UTILS "Build optional utils" FALSE )
option( DIST_ONLY "Build dist targets only (does not require a compiler)" FALSE )
option( PYTHON_BINDINGS "Build bindings for python" FALSE )
option( PHP_BINDINGS "Build bindings for php" FALSE )
@@ -179,6 +180,10 @@ include_directories(
add_subdirectory(src)
+if (BUILD_UTILS)
+ add_subdirectory(utils)
+endif()
+
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
new file mode 100644
index 0000000..762cf86
--- /dev/null
+++ b/utils/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+find_package(Boost REQUIRED COMPONENTS program_options)
+
+add_executable(kolabformatchecker kolabformatchecker.cpp)
+target_link_libraries(kolabformatchecker kolabxml ${Boost_LIBRARIES})
diff --git a/utils/kolabformatchecker.cpp b/utils/kolabformatchecker.cpp
new file mode 100644
index 0000000..fc7df21
--- /dev/null
+++ b/utils/kolabformatchecker.cpp
@@ -0,0 +1,96 @@
+/*
+ * 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/>.
+*/
+
+#include <boost/program_options.hpp>
+#include <iostream>
+#include <string>
+#include <vector>
+#include "src/kolabformat.h"
+
+namespace po = boost::program_options;
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+ // Declare the supported options.
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "produce help message")
+ ("contact", "parse contact")
+ ("distlist", "parse distlist")
+ ("event", "parse event")
+ ("todo", "parse todo")
+ ("journal", "parse journal")
+ ("freebusy", "parse freebusy")
+ ("note", "parse note")
+ ("configuration", "parse configuration")
+ ("input-file", po::value<std::vector<std::string> >(), "input files of given type")
+ ;
+
+ po::positional_options_description p;
+ p.add("input-file", -1);
+
+ po::variables_map vm;
+ po::store(po::command_line_parser(argc, argv).
+ options(desc).positional(p).run(), vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ cout << desc << "\n";
+ return 1;
+ }
+
+ vector<string> inputFiles;
+ if (vm.count("input-file")) {
+ inputFiles = vm["input-file"].as< vector<string> >();
+ } else {
+ cout << "Specify input-file";
+ return -1;
+ }
+
+ for(vector<string>::const_iterator it = inputFiles.begin();
+ it != inputFiles.end(); it++){
+
+ if (vm.count("contact")) {
+ Kolab::readContact(*it, true);
+ } else if (vm.count("distlist")) {
+ Kolab::readDistlist(*it, true);
+ } else if (vm.count("event")) {
+ Kolab::readEvent(*it, true);
+ } else if (vm.count("todo")) {
+ Kolab::readTodo(*it, true);
+ } else if (vm.count("journal")) {
+ Kolab::readJournal(*it, true);
+ } else if (vm.count("freebusy")) {
+ Kolab::readFreebusy(*it, true);
+ } else if (vm.count("note")) {
+ Kolab::readNote(*it, true);
+ } else if (vm.count("configuration")) {
+ Kolab::readConfiguration(*it, true);
+ } else {
+ cout << "Specify type";
+ return -1;
+ }
+ if (Kolab::error()) {
+ cout << "Error: " << Kolab::errorMessage() << endl;
+ return -1;
+ } else {
+ cout << "Parsed message without error." << endl;
+ }
+ }
+ return 0;
+}
\ No newline at end of file
commit ece1bff700ecd01d476c276cd493c2041ac14379
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Fri Sep 21 14:11:58 2012 +0200
fixed version number
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea890bd..8ff9af1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,8 +43,8 @@ set (Libkolabxml_VERSION_MAJOR 0)
set (Libkolabxml_VERSION_MINOR 9)
# Enable the full x.y.z version only for release versions
#set (Libkolabxml_VERSION_PATCH 1)
-set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}.${Libkolabxml_VERSION_PATCH}" )
-# set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}" )
+#set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}.${Libkolabxml_VERSION_PATCH}" )
+set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}" )
set (Libkolabxml_VERSION_STRING ${CMAKE_PROJECT_NAME}-${Libkolabxml_VERSION})
set (KOLAB_FORMAT_VERSION "3.0dev1")
commit f80c5832673c6dee783780bb40a58b0af0cb5c1d
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Mon Sep 17 17:18:59 2012 +0100
Set release to 0.9 the stable version can be found in the 0.8 branch
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 48ce987..ea890bd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,9 +40,9 @@ endif()
# 0.2 (0.2 development version)
set (Libkolabxml_VERSION_MAJOR 0)
-set (Libkolabxml_VERSION_MINOR 8)
+set (Libkolabxml_VERSION_MINOR 9)
# Enable the full x.y.z version only for release versions
-set (Libkolabxml_VERSION_PATCH 1)
+#set (Libkolabxml_VERSION_PATCH 1)
set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}.${Libkolabxml_VERSION_PATCH}" )
# set (Libkolabxml_VERSION "${Libkolabxml_VERSION_MAJOR}.${Libkolabxml_VERSION_MINOR}" )
More information about the commits
mailing list