7 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/kolabformatchecker.cpp

Christian Mollekopf mollekopf at kolabsys.com
Wed Feb 20 20:55:21 CET 2013


 CMakeLists.txt               |    2 
 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/kolabformatchecker.cpp |    3 
 12 files changed, 466 insertions(+), 1 deletion(-)

New commits:
commit f78618cf11a2ce7093c3ee8ad4dcbd264a9b1f26
Merge: b438eba c78d5fd
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date:   Wed Feb 20 20:50:56 2013 +0100

    Merge branch 'files'

diff --cc src/kolabformat.h
index b3192ad,cf78a50..d24f56f
--- a/src/kolabformat.h
+++ b/src/kolabformat.h
@@@ -27,31 -27,9 +27,32 @@@
  #include "kolabnote.h"
  #include "kolabconfiguration.h"
  #include "kolabfreebusy.h"
+ #include "kolabfile.h"
  #include "global_definitions.h"
  
 +/**
 + * Kolab Format v3 Implementation
 + *
 + * Note that this code is threadsafe, as it uses thread-local storage.
 + * 
 + * Example:
 + *
 + * Kolab::Event event;
 + * event.setStart(Kolab::cDateTime("Europe/Zurich",2011,10,10,12,1,1));
 + * event.setEnd(Kolab::cDateTime("Europe/Zurich",2012,5,5,3,4,4));
 + * event.setLastModified(Kolab::cDateTime(2011,10,11,12,1,2,true));
 + * event.setCreated(Kolab::cDateTime(2011,10,11,12,1,3,true));
 + * std::string serialization = Kolab::writeEvent(ev, "Product ID");
 + * std::string serializedUID = Kolab::getSerializedUID(); //returns the UID of the just serialized event
 + * if (Kolab::error() != Kolab::NoError) {
 + *     std::cout << "Error on write " << Kolab::errorMessage();
 + * }
 + * Kolab::Event e = Kolab::readEvent(serialization, false);
 + * if (Kolab::error() != Kolab::NoError) {
 + *     std::cout << "Error on read " << Kolab::errorMessage();
 + * }
 + *
 + */
  namespace Kolab {
  
  /**
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 &note)
+{
+    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 &note, 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 &note, 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();





More information about the commits mailing list