corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [47/55] [abbrv] incubator-corinthia git commit: Use document hash as id prefix
Date Fri, 24 Apr 2015 16:18:14 GMT
Use document hash as id prefix

Instead of requiring the caller of the API to supply an id prefix, we
can simply use the hash of the concrete document that we now compute.
This means we can go back to the public API as it was three commits ago.


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

Branch: refs/heads/stable
Commit: 457ad856b73ac1248b996ef273f2e0e1a5c23ab2
Parents: c0d96a2
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Mon Apr 13 00:19:37 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Mon Apr 13 00:21:20 2015 +0700

----------------------------------------------------------------------
 DocFormats/api/headers/DocFormats/Operations.h  |  8 ++---
 DocFormats/api/src/Operations.c                 | 35 ++++++++++++++------
 DocFormats/filters/ooxml/tests/word/WordTests.c |  5 +--
 consumers/dfconvert/src/main.c                  | 21 +++++-------
 4 files changed, 39 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/457ad856/DocFormats/api/headers/DocFormats/Operations.h
----------------------------------------------------------------------
diff --git a/DocFormats/api/headers/DocFormats/Operations.h b/DocFormats/api/headers/DocFormats/Operations.h
index c84ad84..1bb6ee2 100644
--- a/DocFormats/api/headers/DocFormats/Operations.h
+++ b/DocFormats/api/headers/DocFormats/Operations.h
@@ -39,14 +39,14 @@ void DFAbstractDocumentRelease(DFAbstractDocument *abstract);
 DFDocument *DFAbstractDocumentGetHTML(DFAbstractDocument *abstract);
 void DFAbstractDocumentSetHTML(DFAbstractDocument *abstract, DFDocument *htmlDoc);
 
-int DFGet(DFConcreteDocument *concrete, DFAbstractDocument *abstract, const char *idPrefix,
DFError **error);
-int DFPut(DFConcreteDocument *concrete, DFAbstractDocument *abstract, const char *idPrefix,
DFError **error);
+int DFGet(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error);
+int DFPut(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error);
 int DFCreate(DFConcreteDocument *concrete, DFAbstractDocument *abstract, DFError **error);
 
 // Abstraction level 1
 
-int DFGetFile(const char *concrete, const char *abstract, const char *idPrefix, DFError **error);
-int DFPutFile(const char *concrete, const char *abstract, const char *idPrefix, DFError **error);
+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);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/457ad856/DocFormats/api/src/Operations.c
----------------------------------------------------------------------
diff --git a/DocFormats/api/src/Operations.c b/DocFormats/api/src/Operations.c
index 328e1a5..a9f9bb2 100644
--- a/DocFormats/api/src/Operations.c
+++ b/DocFormats/api/src/Operations.c
@@ -210,7 +210,6 @@ void DFAbstractDocumentSetHTML(DFAbstractDocument *abstract,
 
 int DFGet(DFConcreteDocument *concrete,
           DFAbstractDocument *abstract,
-          const char *idPrefix,
           DFError **error)
 {
     if (DFStorageFormat(abstract->storage) != DFFileFormatHTML) {
@@ -219,6 +218,20 @@ int DFGet(DFConcreteDocument *concrete,
         return 0;
     }
 
+    DFHashCode hash = 0;
+    if (!computeXMLHash(concrete->storage,&hash,error))
+        return 0;
+    char hashstr[100];
+    snprintf(hashstr,100,"%X",hash);
+
+    char hashprefix[100];
+    snprintf(hashprefix,100,"%s-",hashstr);
+    const char *idPrefix;
+    if (DFStorageExists(abstract->storage,"test-mode"))
+        idPrefix = NULL;
+    else
+        idPrefix = hashprefix;
+
     DFDocument *htmlDoc = NULL;
     switch (DFStorageFormat(concrete->storage)) {
         case DFFileFormatDocx:
@@ -242,11 +255,6 @@ int DFGet(DFConcreteDocument *concrete,
         return 0;;
 
     // Store a hash of the concrete document in the HTML file, so we can check it in DFPut()
-    DFHashCode hash = 0;
-    if (!computeXMLHash(concrete->storage,&hash,error))
-        return 0;
-    char hashstr[100];
-    snprintf(hashstr,100,"%X",hash);
     HTMLMetaSet(htmlDoc,"corinthia-document-hash",hashstr);
 
     DFDocumentRelease(abstract->htmlDoc);
@@ -256,7 +264,6 @@ int DFGet(DFConcreteDocument *concrete,
 
 int DFPut(DFConcreteDocument *concreteDoc,
           DFAbstractDocument *abstractDoc,
-          const char *idPrefix,
           DFError **error)
 {
     if (DFStorageFormat(abstractDoc->storage) != DFFileFormatHTML) {
@@ -282,6 +289,14 @@ int DFPut(DFConcreteDocument *concreteDoc,
         return 0;
     }
 
+    char hashprefix[100];
+    snprintf(hashprefix,100,"%s-",hashstr);
+    const char *idPrefix;
+    if (DFStringEquals(hashstr,"ignore"))
+        idPrefix = NULL;
+    else
+        idPrefix = hashprefix;
+
     int ok = 0;
     switch (DFStorageFormat(concreteDoc->storage)) {
         case DFFileFormatDocx:
@@ -338,7 +353,6 @@ int DFCreate(DFConcreteDocument *concreteDoc,
 
 int DFGetFile(const char *concreteFilename,
               const char *abstractFilename,
-              const char *idPrefix,
               DFError **error)
 {
     int r = 0;
@@ -358,7 +372,7 @@ int DFGetFile(const char *concreteFilename,
 
     abstractDoc = DFAbstractDocumentNew(abstractStorage);
 
-    if (!DFGet(concreteDoc, abstractDoc, idPrefix, error)
+    if (!DFGet(concreteDoc, abstractDoc, error)
         || (abstractDoc->htmlDoc == NULL)) {
         DFErrorFormat(error, "%s: %s",
                       concreteFilename,
@@ -394,7 +408,6 @@ end:
 
 int DFPutFile(const char *concreteFilename,
               const char *abstractFilename,
-              const char *idPrefix,
               DFError **error)
 {
     int ok = 0;
@@ -424,7 +437,7 @@ int DFPutFile(const char *concreteFilename,
     abstractDoc = DFAbstractDocumentNew(abstractStorage2);
     abstractDoc->htmlDoc = DFDocumentRetain(htmlDoc2);
 
-    ok = DFPut(concreteDoc, abstractDoc, idPrefix, error);
+    ok = DFPut(concreteDoc, abstractDoc, error);
 
 end:
     DFDocumentRelease(htmlDoc2);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/457ad856/DocFormats/filters/ooxml/tests/word/WordTests.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/tests/word/WordTests.c b/DocFormats/filters/ooxml/tests/word/WordTests.c
index dd85701..e32aef8 100644
--- a/DocFormats/filters/ooxml/tests/word/WordTests.c
+++ b/DocFormats/filters/ooxml/tests/word/WordTests.c
@@ -99,9 +99,10 @@ static void test_get(void)
 
     concreteDoc = DFConcreteDocumentNew(concreteStorage);
     abstractStorage = DFStorageNewMemory(DFFileFormatHTML);
+    DFStorageWrite(abstractStorage,"test-mode",NULL,0,NULL);
     abstractDoc = DFAbstractDocumentNew(abstractStorage);
 
-    if (!DFGet(concreteDoc,abstractDoc,NULL,&error))
+    if (!DFGet(concreteDoc,abstractDoc,&error))
         goto end;;
 
     DFDocument *htmlDoc = DFAbstractDocumentGetHTML(abstractDoc);
@@ -220,7 +221,7 @@ static void test_put(void)
     DFAbstractDocumentSetHTML(abstractDoc,htmlDoc);
 
     // Update the docx file based on the contents of the HTML file
-    if (!DFPut(concreteDoc,abstractDoc,NULL,&error))
+    if (!DFPut(concreteDoc,abstractDoc,&error))
         goto end;
 
     // Output the updated docx file

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/457ad856/consumers/dfconvert/src/main.c
----------------------------------------------------------------------
diff --git a/consumers/dfconvert/src/main.c b/consumers/dfconvert/src/main.c
index 2790a25..2d47e40 100644
--- a/consumers/dfconvert/src/main.c
+++ b/consumers/dfconvert/src/main.c
@@ -24,19 +24,16 @@ void usage(void)
 {
     printf("Usage:\n"
            "\n"
-           "dfconvert get concrete.docx abstract.html [idprefix]\n"
+           "dfconvert get concrete.docx abstract.html\n"
            "\n"
            "    Create a new HTML file from a Word document. The HTML file must not\n"
-           "    already exist. If idprefix is specified, this will be used for all\n"
-           "    id attributes in the HTML file.\n"
+           "    already exist.\n"
            "\n"
-           "dfconvert put concrete.docx abstract.html [idprefix]\n"
+           "dfconvert put concrete.docx abstract.html\n"
            "\n"
            "    Update an existing Word document based on a modified HTML file. The\n"
            "    Word document must already exist, and must be same document from\n"
-           "    which the HTML file was originally generated. If idprefix is specified,\n"
-           "    only those id attributes in the HTML file which have this same prefix\n"
-           "    will be treated as corresponding to existing elements in the docx file.\n"
+           "    which the HTML file was originally generated.\n"
            "\n"
            "    The put operation cannot be executed twice on the same Word\n"
            "    document, because after the first time, the fact that the document\n"
@@ -54,14 +51,12 @@ void usage(void)
 int main(int argc, const char **argv)
 {
     DFError *error = NULL;
-    if ((argc >= 4) && !strcmp(argv[1],"get")) {
-        const char *idPrefix = (argc >= 5) ? argv[4] : NULL;
-        if (DFGetFile(argv[2],argv[3],idPrefix,&error))
+    if ((argc == 4) && !strcmp(argv[1],"get")) {
+        if (DFGetFile(argv[2],argv[3],&error))
             return 0;
     }
-    else if ((argc >= 4) && !strcmp(argv[1],"put")) {
-        const char *idPrefix = (argc >= 5) ? argv[4] : NULL;
-        if (DFPutFile(argv[2],argv[3],idPrefix,&error))
+    else if ((argc == 4) && !strcmp(argv[1],"put")) {
+        if (DFPutFile(argv[2],argv[3],&error))
             return 0;
     }
     else if ((argc == 4) && !strcmp(argv[1],"create")) {


Mime
View raw message