corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [62/92] [abbrv] incubator-corinthia git commit: API classes for concrete & abstract documents
Date Wed, 17 Dec 2014 13:29:12 GMT
API classes for concrete & abstract documents

On top of the simple API that specifies get, put, and create functions
based solely on filenames, we now have corresponding functions which
work on concrete and abstract document objects.

These objects are wrappers around a DFPackage, which in turn is a
wrapper around a zip file, directory, or in-memory hash table. They are
intended for where more "custom" conversion situations arise, such as
when you have the contents of a docx file extracted to a directory
(which is what UX Write currently does), or for the test cases where we
construct an in-memory DFPackage from a text-based representation of a
docx file.

Currently the DFGet, DFPut, and DFCreate functions are not yet
implemented. When they are, the DFGetFile, DFPutFile, and DFCreateFile
functions will become wrappers around them.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/c7099418
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/c7099418
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/c7099418

Branch: refs/heads/stable
Commit: c7099418c6da97d7fbbd0a3ba0aa6c1de132a729
Parents: 15cfc09
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Tue Dec 2 18:45:29 2014 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Tue Dec 2 19:10:18 2014 +0700

----------------------------------------------------------------------
 DocFormats/api/headers/DocFormats/Operations.h |  27 +++++
 DocFormats/api/src/Operations.c                | 122 ++++++++++++++++++++
 2 files changed, 149 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c7099418/DocFormats/api/headers/DocFormats/Operations.h
----------------------------------------------------------------------
diff --git a/DocFormats/api/headers/DocFormats/Operations.h b/DocFormats/api/headers/DocFormats/Operations.h
index abf6bfe..8574542 100644
--- a/DocFormats/api/headers/DocFormats/Operations.h
+++ b/DocFormats/api/headers/DocFormats/Operations.h
@@ -12,8 +12,35 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#ifndef DocFormats_Operations_h
+#define DocFormats_Operations_h
+
 #include "DFError.h"
+#include "DFPackage.h"
+
+// Abstraction level 1
 
 int DFGetFile(const char *concrete, const char *abstract, DFError **error);
 int DFPutFile(const char *concrete, const char *abstract, DFError **error);
 int DFCreateFile(const char *concrete, const char *abstract, DFError **error);
+
+// Abstraction level 2
+
+typedef struct DFConcreteDocument DFConcreteDocument;
+typedef struct DFAbstractDocument DFAbstractDocument;
+
+DFConcreteDocument *DFConcreteDocumentNew(DFPackage *package);
+DFConcreteDocument *DFConcreteDocumentCreateFile(const char *filename, DFError **error);
+DFConcreteDocument *DFConcreteDocumentOpenFile(const char *filename, DFError **error);
+DFConcreteDocument *DFConcreteDocumentRetain(DFConcreteDocument *concrete);
+void DFConcreteDocumentRelease(DFConcreteDocument *concrete);
+
+DFAbstractDocument *DFAbstractDocumentNew(DFPackage *package);
+DFAbstractDocument *DFAbstractDocumentRetain(DFAbstractDocument *abstract);
+void DFAbstractDocumentRelease(DFAbstractDocument *abstract);
+
+int DFGet(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error);
+int DFPut(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error);
+int DFCreate(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c7099418/DocFormats/api/src/Operations.c
----------------------------------------------------------------------
diff --git a/DocFormats/api/src/Operations.c b/DocFormats/api/src/Operations.c
index f8e23e3..ecca6ac 100644
--- a/DocFormats/api/src/Operations.c
+++ b/DocFormats/api/src/Operations.c
@@ -23,6 +23,16 @@
 #include "DFZipFile.h"
 #include <stdlib.h>
 
+struct DFConcreteDocument {
+    size_t retainCount;
+    DFPackage *package;
+};
+
+struct DFAbstractDocument {
+    size_t retainCount;
+    DFPackage *package;
+};
+
 static int generateHTML(const char *packageFilename, const char *htmlFilename, DFError **error)
 {
     int ok = 0;
@@ -188,3 +198,115 @@ end:
     free(absExt);
     return r;
 }
+
+DFConcreteDocument *DFConcreteDocumentNew(DFPackage *package)
+{
+    DFConcreteDocument *concrete = (DFConcreteDocument *)calloc(1,sizeof(DFConcreteDocument));
+    concrete->retainCount = 1;
+    concrete->package = DFPackageRetain(package);
+    return concrete;
+}
+
+DFConcreteDocument *DFConcreteDocumentCreateFile(const char *filename, DFError **error)
+{
+    DFFileFormat format = DFFileFormatFromFilename(filename);
+    switch (format) {
+        case DFFileFormatDocx:
+        case DFFileFormatXlsx:
+        case DFFileFormatPptx:
+        case DFFileFormatOdt:
+        case DFFileFormatOds:
+        case DFFileFormatOdp: {
+            DFPackage *package = DFPackageCreateZip(filename,error);
+            if (package == NULL)
+                return NULL;;
+            DFConcreteDocument *concrete = DFConcreteDocumentNew(package);
+            DFPackageRelease(package);
+            return concrete;
+        }
+        default:
+            DFErrorFormat(error,"Unsupported format for DFConcreteDocumentCreateFile");
+            return NULL;
+    }
+}
+
+DFConcreteDocument *DFConcreteDocumentOpenFile(const char *filename, DFError **error)
+{
+    DFFileFormat format = DFFileFormatFromFilename(filename);
+    switch (format) {
+        case DFFileFormatDocx:
+        case DFFileFormatXlsx:
+        case DFFileFormatPptx:
+        case DFFileFormatOdt:
+        case DFFileFormatOds:
+        case DFFileFormatOdp: {
+            DFPackage *package = DFPackageOpenZip(filename,error);
+            if (package == NULL)
+                return NULL;;
+            DFConcreteDocument *concrete = DFConcreteDocumentNew(package);
+            DFPackageRelease(package);
+            return concrete;
+        }
+        default:
+            DFErrorFormat(error,"Unsupported format for DFConcreteDocumentCreateFile");
+            return NULL;
+    }
+}
+
+DFConcreteDocument *DFConcreteDocumentRetain(DFConcreteDocument *concrete)
+{
+    if (concrete != NULL)
+        concrete->retainCount++;
+    return concrete;
+}
+
+void DFConcreteDocumentRelease(DFConcreteDocument *concrete)
+{
+    if ((concrete == NULL) || (--concrete->retainCount > 0))
+        return;
+
+    DFPackageRelease(concrete->package);
+    free(concrete);
+}
+
+DFAbstractDocument *DFAbstractDocumentNew(DFPackage *package)
+{
+    DFAbstractDocument *abstract = (DFAbstractDocument *)calloc(1,sizeof(DFAbstractDocument));
+    abstract->retainCount = 1;
+    abstract->package = DFPackageRetain(package);
+    return abstract;
+}
+
+DFAbstractDocument *DFAbstractDocumentRetain(DFAbstractDocument *abstract)
+{
+    if (abstract != NULL)
+        abstract->retainCount++;
+    return abstract;
+}
+
+void DFAbstractDocumentRelease(DFAbstractDocument *abstract)
+{
+    if ((abstract == NULL) || (--abstract->retainCount > 0))
+        return;
+
+    DFPackageRelease(abstract->package);
+    free(abstract);
+}
+
+int DFGet(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error)
+{
+    DFErrorFormat(error,"DFGet not yet implemented");
+    return 0;
+}
+
+int DFPut(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error)
+{
+    DFErrorFormat(error,"DFPut not yet implemented");
+    return 0;
+}
+
+int DFCreate(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error)
+{
+    DFErrorFormat(error,"DFCreate not yet implemented");
+    return 0;
+}


Mime
View raw message