corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [70/92] [abbrv] incubator-corinthia git commit: Avoid referencing WordPackage in dfutil
Date Wed, 17 Dec 2014 13:29:20 GMT
Avoid referencing WordPackage in dfutil

The WordPackage class should be private to the DocFormats library, and
accessed only via the public APIs. There were numerous places in the
test code where this was not the case. With this commit, we now have a
cleaner separation between the two, using the recently-added DFGet,
DFPut, and DFCreate APIs for performing bidirectional transformation on
documents.

The test functions in particular illustrate the utility of the DFPackage
abstraction, in that they create packages in memory only, without having
to write out to the filesystem. This simplifies the test code by in most
cases removing the need for temporary directories.

One place where we do sort-of break this abstraction is the tests for
expanding and collapsing bookmarks in a Word document. This isn't
something that should be part of the public API, but nonetheless needs
to be covered by the tests. Although we do bypass the API for this, we
use the new functions WordExpandBookmarks and WordCollapseBookmarks
declared in Word.h for this purpose, which take a DFPackage object, not
a WordPackage object parameters. It's likely there will be many other
similar cases like this in the future, and we still need to figure out a
way to address testing of purely internal functionality.


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

Branch: refs/heads/stable
Commit: 0b8b3288f2b6338b9ee456e7df600245c4e83fd5
Parents: 07ae5f1
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Sun Dec 7 19:13:45 2014 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Sun Dec 7 19:36:44 2014 +0700

----------------------------------------------------------------------
 DocFormats/filters/ooxml/src/word/Word.c        |  40 ++++
 DocFormats/filters/ooxml/src/word/Word.h        |   2 +
 DocFormats/filters/ooxml/src/word/WordPackage.c |   9 -
 DocFormats/filters/ooxml/src/word/WordPackage.h |   1 -
 consumers/dfutil/src/Commands.c                 |  23 +-
 consumers/dfutil/src/Plain.c                    | 133 +++--------
 consumers/dfutil/src/Plain.h                    |  11 +-
 consumers/dfutil/src/TestCase.c                 |  34 +--
 consumers/dfutil/src/TestCase.h                 |   8 +-
 consumers/dfutil/src/TestFunctions.c            | 234 +++++++++----------
 10 files changed, 210 insertions(+), 285 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/DocFormats/filters/ooxml/src/word/Word.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/Word.c b/DocFormats/filters/ooxml/src/word/Word.c
index ea4315f..7217073 100644
--- a/DocFormats/filters/ooxml/src/word/Word.c
+++ b/DocFormats/filters/ooxml/src/word/Word.c
@@ -125,3 +125,43 @@ end:
     DFBufferRelease(warnings);
     return ok;
 }
+
+int WordCollapseBookmarks(DFPackage *concretePackage, DFError **error)
+{
+    int ok = 0;
+    WordPackage *wordPackage = NULL;
+
+    wordPackage = WordPackageOpenFrom(concretePackage,error);
+    if (wordPackage == NULL)
+        goto end;
+
+    WordPackageCollapseBookmarks(wordPackage);
+
+    if (!WordPackageSave(wordPackage,error))
+        goto end;
+
+    ok = 1;
+end:
+    WordPackageRelease(wordPackage);
+    return ok;
+}
+
+int WordExpandBookmarks(DFPackage *concretePackage, DFError **error)
+{
+    int ok = 0;
+    WordPackage *wordPackage = NULL;
+
+    wordPackage = WordPackageOpenFrom(concretePackage,error);
+    if (wordPackage == NULL)
+        goto end;
+
+    WordPackageExpandBookmarks(wordPackage);
+
+    if (!WordPackageSave(wordPackage,error))
+        goto end;
+
+    ok = 1;
+end:
+    WordPackageRelease(wordPackage);
+    return ok;
+}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/DocFormats/filters/ooxml/src/word/Word.h
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/Word.h b/DocFormats/filters/ooxml/src/word/Word.h
index 43adb48..7554eb2 100644
--- a/DocFormats/filters/ooxml/src/word/Word.h
+++ b/DocFormats/filters/ooxml/src/word/Word.h
@@ -30,5 +30,7 @@ CSSStyle *WordSetupTableGridStyle(CSSSheet *styleSheet, int *changed);
 DFDocument *WordGet(DFPackage *concretePackage, DFPackage *abstractPackage, DFError **error);
 int WordPut(DFPackage *concretePackage, DFPackage *abstractPackage, DFDocument *htmlDoc,
DFError **error);
 int WordCreate(DFPackage *concretePackage, DFPackage *abstractPackage, DFDocument *htmlDoc,
DFError **error);
+int WordCollapseBookmarks(DFPackage *concretePackage, DFError **error);
+int WordExpandBookmarks(DFPackage *concretePackage, DFError **error);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/DocFormats/filters/ooxml/src/word/WordPackage.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/WordPackage.c b/DocFormats/filters/ooxml/src/word/WordPackage.c
index 2ba33eb..22660d5 100644
--- a/DocFormats/filters/ooxml/src/word/WordPackage.c
+++ b/DocFormats/filters/ooxml/src/word/WordPackage.c
@@ -417,15 +417,6 @@ static DFDocument *parsePart(WordPackage *package, OPCPart *part, DFError
**erro
     return doc;
 }
 
-void WordPackageRemovePointlessElements(WordPackage *package)
-{
-    if (package->styles != NULL) {
-        DFNode *latentStyles = DFChildWithTag(package->styles->root,WORD_LATENTSTYLES);
-        if (latentStyles != NULL)
-            DFRemoveNode(latentStyles);
-    }
-}
-
 const char *WordPackageTargetForDocumentRel(WordPackage *package, const char *relId)
 {
     OPCRelationship *rel = OPCRelationshipSetLookupById(package->documentPart->relationships,relId);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/DocFormats/filters/ooxml/src/word/WordPackage.h
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/WordPackage.h b/DocFormats/filters/ooxml/src/word/WordPackage.h
index 6255544..07528ab 100644
--- a/DocFormats/filters/ooxml/src/word/WordPackage.h
+++ b/DocFormats/filters/ooxml/src/word/WordPackage.h
@@ -50,7 +50,6 @@ void WordPackageSetEndnotes(WordPackage *package, DFDocument *endnotes);
 WordPackage *WordPackageRetain(WordPackage *package);
 void WordPackageRelease(WordPackage *package);
 
-void WordPackageRemovePointlessElements(WordPackage *package);
 const char *WordPackageTargetForDocumentRel(WordPackage *package, const char *relId);
 int WordPackageSimplifyFields(WordPackage *package);
 void WordPackageCollapseBookmarks(WordPackage *package);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/consumers/dfutil/src/Commands.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Commands.c b/consumers/dfutil/src/Commands.c
index f0c2895..0da466d 100644
--- a/consumers/dfutil/src/Commands.c
+++ b/consumers/dfutil/src/Commands.c
@@ -110,7 +110,6 @@ static int prettyPrintWordFile(const char *filename, DFError **error)
     int ok = 0;
     char *wordTempPath = DFAppendPathComponent(tempPath,"word");
     char *plain = NULL;
-    WordPackage *wordPackage = NULL;
     DFPackage *rawPackage = NULL;
 
     if (!DFEmptyDirectory(wordTempPath,error))
@@ -122,12 +121,7 @@ static int prettyPrintWordFile(const char *filename, DFError **error)
         goto end;
     }
 
-    wordPackage = WordPackageOpenFrom(rawPackage,error);
-    if (wordPackage == NULL)
-        goto end;
-
-    WordPackageRemovePointlessElements(wordPackage);
-    plain = Word_toPlain(wordPackage,rawPackage,NULL);
+    plain = Word_toPlain(rawPackage,NULL);
     printf("%s",plain);
 
     ok = 1;
@@ -137,7 +131,6 @@ end:
     free(wordTempPath);
     free(plain);
     DFPackageRelease(rawPackage);
-    WordPackageRelease(wordPackage);
     DFDeleteFile(tempPath,NULL);
     return ok;
 }
@@ -164,8 +157,6 @@ static int fromPlain2(const char *tempPath, const char *inStr, const char
*inPat
                       const char *outFilename, DFError **error)
 {
     char *outExtension = DFPathExtension(outFilename);
-    char *packagePath = DFAppendPathComponent(tempPath,"package");
-    char *zipPath = DFAppendPathComponent(tempPath,"zip");
     int isDocx = DFStringEqualsCI(outExtension,"docx");
     int ok = 0;
 
@@ -174,21 +165,17 @@ static int fromPlain2(const char *tempPath, const char *inStr, const
char *inPat
         goto end;
     }
 
-    WordPackage *wordPackage = NULL;
     DFPackage *rawPackage = NULL;
-    if (!Word_fromPlain(inStr,inPath,zipPath,&wordPackage,&rawPackage,error))
+
+    rawPackage = Word_fromPlain(inStr,inPath,error);
+    if (rawPackage == NULL)
         goto end;
 
-    ok = WordPackageSave(wordPackage,error);
-    if (!DFZip(outFilename,rawPackage,error))
-        ok = 0;
-    WordPackageRelease(wordPackage);
+    ok = DFZip(outFilename,rawPackage,error);
     DFPackageRelease(rawPackage);
 
     return ok;
 end:
-    free(packagePath);
-    free(zipPath);
     free(outExtension);
     return ok;
 }

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/consumers/dfutil/src/Plain.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Plain.c b/consumers/dfutil/src/Plain.c
index 5260255..8cb42e6 100644
--- a/consumers/dfutil/src/Plain.c
+++ b/consumers/dfutil/src/Plain.c
@@ -280,30 +280,10 @@ end:
     }
 }
 
-static char *Word_toPlainOrError(WordPackage *wordPackage, DFPackage *rawPackage, DFHashTable
*parts, DFError **error)
-{
-    char *result = NULL;
-    int ok = 0;
-
-    if (!WordPackageSave(wordPackage,error)) {
-        DFErrorFormat(error,"WordPackageSave: %s",DFErrorMessage(error));
-        goto end;
-    }
-
-    result = Word_toPlainFromDir(rawPackage,parts,error);
-    ok = 1;
-
-end:
-    if (ok)
-        return result;
-    free(result);
-    return 0;
-}
-
-char *Word_toPlain(WordPackage *wordPackage, DFPackage *rawPackage, DFHashTable *parts)
+char *Word_toPlain(DFPackage *rawPackage, DFHashTable *parts)
 {
     DFError *error = NULL;
-    char *result = Word_toPlainOrError(wordPackage,rawPackage,parts,&error);
+    char *result = Word_toPlainFromDir(rawPackage,parts,&error);
     if (result == NULL) {
         result = DFFormatString("%s\n",DFErrorMessage(&error));
         DFErrorRelease(error);
@@ -576,76 +556,37 @@ end:
     return ok;
 }
 
-int Word_fromPlain(const char *plain, const char *plainPath, const char *zipTempPath,
-                   WordPackage **outWordPackage, DFPackage **outRawPackage, DFError **error)
+DFPackage *Word_fromPlain(const char *plain, const char *plainPath, DFError **error)
 {
     int ok = 0;
-    char *docxPath = DFAppendPathComponent(zipTempPath,"document.docx");
-    DFPackage *firstStore = NULL;
-    DFPackage *secondStore = NULL;
-    WordPackage *wp = NULL;
-    TextPackage *tp = NULL;
-
-    tp = TextPackageNewWithString(plain,plainPath,error);
-    if (tp == NULL)
-        goto end;
-
-    if (DFFileExists(zipTempPath) && !DFDeleteFile(zipTempPath,error)) {
-        DFErrorFormat(error,"delete %s: %s",zipTempPath,DFErrorMessage(error));
-        goto end;
-    }
+    DFPackage *concretePackage = NULL;
+    TextPackage *textPackage = NULL;
 
-    if (!DFCreateDirectory(zipTempPath,1,error)) {
-        DFErrorFormat(error,"create %s: %s",zipTempPath,DFErrorMessage(error));
+    textPackage = TextPackageNewWithString(plain,plainPath,error);
+    if (textPackage == NULL)
         goto end;
-    }
 
-    firstStore = DFPackageCreateZip(docxPath,error);
-    if (firstStore == NULL) {
-        DFErrorFormat(error,"%s: %s",docxPath,DFErrorMessage(error));
-        goto end;
-    }
+    concretePackage = DFPackageNewMemory(DFFileFormatDocx);
 
-    if (!Word_fromPackage(tp,firstStore,error)) {
-        DFErrorFormat(error,"Word_fromPackageNew: %s",DFErrorMessage(error));
+    if (!Word_fromPackage(textPackage,concretePackage,error)) {
+        DFErrorFormat(error,"Word_fromPackage: %s",DFErrorMessage(error));
         printf("%s\n",DFErrorMessage(error));
         goto end;
     }
 
-    if (!DFPackageSave(firstStore,error)) {
-        DFErrorFormat(error,"zip %s: %s",docxPath,DFErrorMessage(error));
+    if (!DFPackageSave(concretePackage,error))
         goto end;
-    }
 
-    // Now we have a .docx file; access it using what will be the new way (this API will
change so we just say
-    // "open a word document from here", without having to separately create the package
object first.
-    secondStore = DFPackageOpenZip(docxPath,error);
-    if (secondStore == NULL) {
-        DFErrorFormat(error,"%s: %s\n",docxPath,DFErrorMessage(error));
-        goto end;
-    }
-    wp = WordPackageOpenFrom(secondStore,error);
-    if (wp == NULL) {
-        DFErrorFormat(error,"WordPackageStartFrom %s: %s",docxPath,DFErrorMessage(error));
-        goto end;
-    }
     ok = 1;
 
 end:
-    free(docxPath);
-    DFPackageRelease(firstStore);
-    TextPackageRelease(tp);
+    TextPackageRelease(textPackage);
     if (ok) {
-        *outWordPackage = wp;
-        *outRawPackage = secondStore;
-        return 1;
+        return concretePackage;
     }
     else {
-        WordPackageRelease(wp);
-        DFPackageRelease(secondStore);
-        *outWordPackage = NULL;
-        *outRawPackage = NULL;
-        return 0;
+        DFPackageRelease(concretePackage);
+        return NULL;
     }
 }
 
@@ -670,7 +611,7 @@ static const char **HTML_getImageSources(DFDocument *doc)
     return result;
 }
 
-char *HTML_toPlain(DFDocument *doc, const char *imagePath, DFError **error)
+char *HTML_toPlain(DFDocument *doc, DFPackage *package, DFError **error)
 {
     DFBuffer *output = DFBufferNew();
     char *docStr = DFSerializeXMLString(doc,0,0);
@@ -684,16 +625,13 @@ char *HTML_toPlain(DFDocument *doc, const char *imagePath, DFError **error)
             DFBufferFormat(output,"#item %s\n",src);
         else
             DFBufferFormat(output,"#item images/%s\n",src);
-        char *srcPath = DFAppendPathComponent(imagePath,src);
-        DFBuffer *imageData = DFBufferReadFromFile(srcPath,error);
+        DFBuffer *imageData = DFBufferReadFromPackage(package,src,error);
         if (imageData == NULL) {
-            DFErrorFormat(error,"%s: %s",srcPath,DFErrorMessage(error));
-            free(srcPath);
+            DFErrorFormat(error,"%s: %s",src,DFErrorMessage(error));
             return NULL;
         }
         char *imageStr = binaryToString(imageData);
         DFBufferFormat(output,"%s",imageStr);
-        free(srcPath);
         free(imageStr);
         DFBufferRelease(imageData);
     }
@@ -704,9 +642,9 @@ char *HTML_toPlain(DFDocument *doc, const char *imagePath, DFError **error)
     return str;
 }
 
-static DFDocument *HTML_fromPackage(TextPackage *tp, const char *path, const char *htmlPath,
DFError **error)
+static DFDocument *HTML_fromTextPackage(TextPackage *textPackage, DFPackage *htmlPackage,
DFError **error)
 {
-    const char *html = DFHashTableLookup(tp->items,"");
+    const char *html = DFHashTableLookup(textPackage->items,"");
     if (html == NULL) {
         DFErrorFormat(error,"No HTML data");
         return NULL;
@@ -716,33 +654,22 @@ static DFDocument *HTML_fromPackage(TextPackage *tp, const char *path,
const cha
     if (doc == NULL)
         return NULL;
 
-    for (size_t ki = 0; ki < tp->nkeys; ki++) {
-        const char *key = tp->keys[ki];
+    for (size_t ki = 0; ki < textPackage->nkeys; ki++) {
+        const char *key = textPackage->keys[ki];
         if (strlen(key) == 0)
             continue;
 
-        char *thisFullPath = DFAppendPathComponent(htmlPath,key);
-        char *thisFullParentPath = DFPathDirName(thisFullPath);
-
         int ok = 1;
 
-        if (!DFFileExists(thisFullParentPath) && !DFCreateDirectory(thisFullParentPath,1,error))
{
-            DFErrorFormat(error,"%s: %s",thisFullParentPath,DFErrorMessage(error));
-            DFDocumentRelease(doc);
-            ok = 0;
-        }
-
-        const char *str = DFHashTableLookup(tp->items,key);
+        const char *str = DFHashTableLookup(textPackage->items,key);
         DFBuffer *data = stringToBinary(str);
-        if (!DFBufferWriteToFile(data,thisFullPath,error)) {
-            DFErrorFormat(error,"%s: %s",thisFullPath,DFErrorMessage(error));
+        if (!DFBufferWriteToPackage(data,htmlPackage,key,error)) {
+            DFErrorFormat(error,"%s: %s",key,DFErrorMessage(error));
             DFDocumentRelease(doc);
             ok = 0;
         }
 
         DFBufferRelease(data);
-        free(thisFullPath);
-        free(thisFullParentPath);
 
         if (!ok)
             return NULL;
@@ -751,12 +678,12 @@ static DFDocument *HTML_fromPackage(TextPackage *tp, const char *path,
const cha
     return doc;
 }
 
-DFDocument *HTML_fromPlain(const char *plain, const char *path, const char *htmlPath, DFError
**error)
+DFDocument *HTML_fromPlain(const char *plain, const char *path, DFPackage *htmlPackage, DFError
**error)
 {
-    TextPackage *tp = TextPackageNewWithString(plain,path,error);
-    if (tp == NULL)
+    TextPackage *textPackage = TextPackageNewWithString(plain,path,error);
+    if (textPackage == NULL)
         return NULL;;
-    DFDocument *result = HTML_fromPackage(tp,path,htmlPath,error);
-    TextPackageRelease(tp);
+    DFDocument *result = HTML_fromTextPackage(textPackage,htmlPackage,error);
+    TextPackageRelease(textPackage);
     return result;
 }

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/consumers/dfutil/src/Plain.h
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Plain.h b/consumers/dfutil/src/Plain.h
index edb6de5..f81e809 100644
--- a/consumers/dfutil/src/Plain.h
+++ b/consumers/dfutil/src/Plain.h
@@ -18,12 +18,11 @@
 #include "DFError.h"
 #include "DFHashTable.h"
 #include "DFDOM.h"
-#include "WordPackage.h"
+#include "DFPackage.h"
 
-char *Word_toPlain(WordPackage *wordPackage, DFPackage *rawPackage, DFHashTable *parts);
-int Word_fromPlain(const char *plain, const char *plainPath, const char *zipTempPath,
-                   WordPackage **outWordPackage, DFPackage **outRawPackage, DFError **error);
-char *HTML_toPlain(DFDocument *doc, const char *imagePath, DFError **error);
-DFDocument *HTML_fromPlain(const char *plain, const char *path, const char *htmlPath, DFError
**error);
+char *Word_toPlain(DFPackage *rawPackage, DFHashTable *parts);
+DFPackage *Word_fromPlain(const char *plain, const char *plainPath, DFError **error);
+char *HTML_toPlain(DFDocument *doc, DFPackage *package, DFError **error);
+DFDocument *HTML_fromPlain(const char *plain, const char *path, DFPackage *htmlPackage, DFError
**error);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/consumers/dfutil/src/TestCase.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/TestCase.c b/consumers/dfutil/src/TestCase.c
index 5ffb821..848db6f 100644
--- a/consumers/dfutil/src/TestCase.c
+++ b/consumers/dfutil/src/TestCase.c
@@ -46,45 +46,23 @@ void TestCaseFree(TestCase *tc)
     free(tc);
 }
 
-int TestCaseOpenWordPackage(TestCase *tc, WordPackage **outWordPackage, DFPackage **outRawPackage,
DFError **error)
+DFPackage *TestCaseOpenPackage(TestCase *tc, DFError **error)
 {
     const char *inputDocx = DFHashTableLookup(tc->input,"input.docx");
     if (inputDocx == NULL) {
         DFErrorFormat(error,"input.docx not defined");
-        return 0;
+        return NULL;
     }
 
-    char *zipPath = DFAppendPathComponent(tc->tempPath,"zip");
-    WordPackage *wordPackage = NULL;
-    DFPackage *rawPackage = NULL;
-    int ok = Word_fromPlain(inputDocx,tc->path,zipPath,&wordPackage,&rawPackage,error);
-    free(zipPath);
-    if (!ok)
-        return 0;
-
-    if (wordPackage->document == NULL) {
-        DFErrorFormat(error,"document.xml not found");
-        WordPackageRelease(wordPackage);
-        DFPackageRelease(rawPackage);
-        return 0;
-    }
-    *outWordPackage = wordPackage;
-    *outRawPackage = rawPackage;
-    return 1;
+    return Word_fromPlain(inputDocx,tc->path,error);
 }
 
-DFDocument *TestCaseGetHTML(TestCase *tc)
+DFDocument *TestCaseGetHTML(TestCase *tc, DFPackage *htmlPackage, DFError **error)
 {
     const char *inputHtml = DFHashTableLookup(tc->input,"input.html");
     if (inputHtml == NULL) {
-        DFBufferFormat(tc->output,"input.html not defined\n");
+        DFErrorFormat(error,"input.html not defined");
         return NULL;
     }
-    DFError *error = NULL;
-    DFDocument *htmlDoc = HTML_fromPlain(inputHtml,tc->path,tc->abstractPath,&error);
-    if (htmlDoc == NULL) {
-        DFBufferFormat(tc->output,"%s\n",DFErrorMessage(&error));
-        DFErrorRelease(error);
-    }
-    return htmlDoc;
+    return HTML_fromPlain(inputHtml,tc->path,htmlPackage,error);
 }

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/consumers/dfutil/src/TestCase.h
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/TestCase.h b/consumers/dfutil/src/TestCase.h
index fe29512..e79a12e 100644
--- a/consumers/dfutil/src/TestCase.h
+++ b/consumers/dfutil/src/TestCase.h
@@ -16,7 +16,9 @@
 #define dfutil_TestCase_h
 
 #include "DFHashTable.h"
-#include "WordPackage.h"
+#include "DFBuffer.h"
+#include "DFPackage.h"
+#include "DFXMLForward.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 //                                                                                      
         //
@@ -36,7 +38,7 @@ struct TestCase {
 
 TestCase *TestCaseNew(const char *path, DFHashTable *input);
 void TestCaseFree(TestCase *tc);
-int TestCaseOpenWordPackage(TestCase *tc, WordPackage **outWordPackage, DFPackage **outRawPackage,
DFError **error);
-DFDocument *TestCaseGetHTML(TestCase *script);
+DFPackage *TestCaseOpenPackage(TestCase *tc, DFError **error);
+DFDocument *TestCaseGetHTML(TestCase *tc, DFPackage *htmlPackage, DFError **error);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/0b8b3288/consumers/dfutil/src/TestFunctions.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/TestFunctions.c b/consumers/dfutil/src/TestFunctions.c
index e8b47e6..02ccbe7 100644
--- a/consumers/dfutil/src/TestFunctions.c
+++ b/consumers/dfutil/src/TestFunctions.c
@@ -19,6 +19,7 @@
 #include "Commands.h"
 #include "DFChanges.h"
 #include "WordConverter.h"
+#include "Word.h"
 #include "DFHTML.h"
 #include "DFHTMLNormalization.h"
 #include "DFFilesystem.h"
@@ -26,6 +27,7 @@
 #include "HTMLToLaTeX.h"
 #include "DFXML.h"
 #include "DFCommon.h"
+#include <DocFormats/DocFormats.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -91,25 +93,28 @@ static void CSS_setHeadingNumbering(TestCase *script, int argc, const
char **arg
 static void Word_testCollapseBookmarks(TestCase *script, int argc, const char **argv)
 {
     DFError *error = NULL;
-    WordPackage *wordPackage = NULL;
-    DFPackage *rawPackage = NULL;
-    if (!TestCaseOpenWordPackage(script,&wordPackage,&rawPackage,&error)) { //
Logs error itself on failure
+    DFPackage *rawPackage = TestCaseOpenPackage(script,&error);
+    if (rawPackage == NULL) {
         DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
         DFErrorRelease(error);
         return;
     }
 
-    WordPackageCollapseBookmarks(wordPackage);
+    if (!WordCollapseBookmarks(rawPackage,&error)) {
+        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
+        DFErrorRelease(error);
+        DFPackageRelease(rawPackage);
+        return;
+    }
 
     DFHashTable *parts = DFHashTableNew((DFCopyFunction)strdup,free);
     DFHashTableAdd(parts,"document","");
 
     // Output the docx file
-    char *plain = Word_toPlain(wordPackage,rawPackage,parts);
+    char *plain = Word_toPlain(rawPackage,parts);
     DFBufferFormat(script->output,"%s",plain);
     free(plain);
     DFHashTableRelease(parts);
-    WordPackageRelease(wordPackage);
     DFPackageRelease(rawPackage);
 }
 
@@ -117,71 +122,71 @@ static void Word_testCollapseBookmarks(TestCase *script, int argc, const
char **
 static void Word_testExpandBookmarks(TestCase *script, int argc, const char **argv)
 {
     DFError *error = NULL;
-    WordPackage *wordPackage = NULL;
-    DFPackage *rawPackage = NULL;
-    if (!TestCaseOpenWordPackage(script,&wordPackage,&rawPackage,&error)) { //
Logs error itself on failure
+    DFPackage *rawPackage = TestCaseOpenPackage(script,&error);
+    if (rawPackage == NULL) {
         DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
         DFErrorRelease(error);
         return;
     }
 
-    WordPackageExpandBookmarks(wordPackage);
+    if (!WordExpandBookmarks(rawPackage,&error)) {
+        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
+        DFErrorRelease(error);
+        DFPackageRelease(rawPackage);
+        return;
+    }
 
     DFHashTable *parts = DFHashTableNew((DFCopyFunction)strdup,free);
     DFHashTableAdd(parts,"document","");
 
     // Output the docx file
-    char *plain = Word_toPlain(wordPackage,rawPackage,parts);
+    char *plain = Word_toPlain(rawPackage,parts);
     DFBufferFormat(script->output,"%s",plain);
     free(plain);
     DFHashTableRelease(parts);
-    WordPackageRelease(wordPackage);
     DFPackageRelease(rawPackage);
 }
 
-static void Word_testGet2(TestCase *script, WordPackage *package, int argc, const char **argv)
+static void Word_testGet(TestCase *script, int argc, const char **argv)
 {
     DFError *error = NULL;
-    // Create the HTML file
-    // FIXME: maybe use a temporary directory for the image path?
-    DFPackage *abstractPackage = DFPackageNewFilesystem(script->abstractPath,DFFileFormatHTML);
-    DFDocument *htmlDoc = WordPackageGenerateHTML(package,abstractPackage,"word",&error,NULL);
-    DFPackageRelease(abstractPackage);
-    if (htmlDoc == NULL) {
-        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
-        DFErrorRelease(error);
-        return;
-    }
+    DFPackage *abstractPackage = NULL;
+    DFPackage *concretePackage = NULL;
+    DFAbstractDocument *abstractDoc = NULL;
+    DFConcreteDocument *concreteDoc = NULL;
+    char *htmlPlain = NULL;
 
-    // Output the HTML file
-    HTML_safeIndent(htmlDoc->docNode,0);
+    concretePackage = TestCaseOpenPackage(script,&error);
+    if (concretePackage == NULL)
+        goto end;
 
-    char *htmlPlain = HTML_toPlain(htmlDoc,script->abstractPath,&error);
-    DFDocumentRelease(htmlDoc);
+    concreteDoc = DFConcreteDocumentNew(concretePackage);
+    abstractPackage = DFPackageNewMemory(DFFileFormatHTML);
+    abstractDoc = DFAbstractDocumentNew(abstractPackage);
 
-    if (htmlPlain == NULL) {
-        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
-        DFErrorRelease(error);
-        return;
+    if (!DFGet(concreteDoc,abstractDoc,&error))
+        goto end;;
+
+    DFDocument *htmlDoc = DFAbstractDocumentGetHTML(abstractDoc);
+    if (htmlDoc == NULL) {
+        DFErrorFormat(&error,"Abstract document has no HTML");
+        goto end;
     }
-    DFBufferFormat(script->output,"%s",htmlPlain);
-    free(htmlPlain);
-}
 
-static void Word_testGet(TestCase *script, int argc, const char **argv)
-{
-    DFError *error = NULL;
-    WordPackage *wordPackage = NULL;
-    DFPackage *rawPackage = NULL;
-    if (!TestCaseOpenWordPackage(script,&wordPackage,&rawPackage,&error)) { //
Logs error itself on failure
+    htmlPlain = HTML_toPlain(htmlDoc,abstractPackage,&error);
+
+end:
+    if (htmlPlain != NULL)
+        DFBufferFormat(script->output,"%s",htmlPlain);
+    else
         DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
-        DFErrorRelease(error);
-        return;
-    }
 
-    Word_testGet2(script,wordPackage,argc,argv);
-    WordPackageRelease(wordPackage);
-    DFPackageRelease(rawPackage);
+    DFErrorRelease(error);
+    DFPackageRelease(abstractPackage);
+    DFPackageRelease(concretePackage);
+    DFAbstractDocumentRelease(abstractDoc);
+    DFConcreteDocumentRelease(concreteDoc);
+    free(htmlPlain);
 }
 
 static DFHashTable *getFlags(int argc, const char **argv)
@@ -211,111 +216,106 @@ static DFHashTable *getFlags(int argc, const char **argv)
 
 static void Word_testCreate(TestCase *script, int argc, const char **argv)
 {
-    DFPackage *rawPackage = DFPackageNewMemory(DFFileFormatDocx);
-    WordPackage *wordPackage = NULL;
-
+    DFError *error = NULL;
     DFDocument *htmlDoc = NULL;
+    DFPackage *abstractPackage = DFPackageNewMemory(DFFileFormatHTML);
+    DFPackage *concretePackage = DFPackageNewMemory(DFFileFormatDocx);
+    DFAbstractDocument *abstractDoc = DFAbstractDocumentNew(abstractPackage);
+    DFConcreteDocument *concreteDoc = DFConcreteDocumentNew(concretePackage);
     DFHashTable *parts = NULL;
-    char *plain = NULL;
-    DFError *error = NULL;
-    DFPackage *abstractPackage = NULL;
+    char *wordPlain = NULL;
 
     // Read input.html
-    htmlDoc = TestCaseGetHTML(script);
+    htmlDoc = TestCaseGetHTML(script,abstractPackage,&error);
     if (htmlDoc == NULL)
-        goto end;;
-
-    // Create the docx file
-    wordPackage = WordPackageOpenNew(rawPackage,&error);
-    if (wordPackage == NULL) {
-        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
         goto end;
-    }
 
-    DFBuffer *warnings = DFBufferNew();
-    abstractPackage = DFPackageNewFilesystem(script->abstractPath,DFFileFormatHTML);
-    if (!WordPackageUpdateFromHTML(wordPackage,htmlDoc,abstractPackage,"word",&error,warnings))
{
-        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
-        goto end;
-    }
+    DFAbstractDocumentSetHTML(abstractDoc,htmlDoc);
 
-    if (warnings->len > 0) {
-        DFBufferFormat(script->output,"%s",warnings->data);
-        DFBufferRelease(warnings);
+    if (!DFCreate(concreteDoc,abstractDoc,&error))
         goto end;
-    }
-    DFBufferRelease(warnings);
-
-    // We don't actually "save" the package as such; this is just to ensure the missing OPC
parts are added
-    WordPackageSave(wordPackage,NULL);
 
-    // Output the docx file
     parts = getFlags(argc,argv);
-    plain = Word_toPlain(wordPackage,rawPackage,parts);
-    DFBufferFormat(script->output,"%s",plain);
+    wordPlain = Word_toPlain(concretePackage,parts);
 
 end:
-    DFDocumentRelease(htmlDoc);
-    free(plain);
-    DFHashTableRelease(parts);
+    if (wordPlain != NULL)
+        DFBufferFormat(script->output,"%s",wordPlain);
+    else
+        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
+
     DFErrorRelease(error);
-    DFPackageRelease(rawPackage);
-    WordPackageRelease(wordPackage);
+    DFDocumentRelease(htmlDoc);
     DFPackageRelease(abstractPackage);
+    DFPackageRelease(concretePackage);
+    DFAbstractDocumentRelease(abstractDoc);
+    DFConcreteDocumentRelease(concreteDoc);
+    DFHashTableRelease(parts);
+    free(wordPlain);
 }
 
-static void Word_testUpdate2(TestCase *script, WordPackage *wordPackage, DFPackage *rawPackage,
int argc, const char **argv)
+static void Word_testUpdate(TestCase *script, int argc, const char **argv)
 {
+    DFError *error = NULL;
+    DFDocument *htmlDoc = NULL;
+    DFPackage *abstractPackage = NULL;
+    DFPackage *concretePackage = NULL;
+    DFAbstractDocument *abstractDoc = NULL;
+    DFConcreteDocument *concreteDoc = NULL;
+    DFHashTable *parts = NULL;
+    char *wordPlain = NULL;
+
+    concretePackage = TestCaseOpenPackage(script,&error);
+    if (concretePackage == NULL)
+        goto end;
+
+    abstractPackage = DFPackageNewMemory(DFFileFormatHTML);
+    abstractDoc = DFAbstractDocumentNew(abstractPackage);
+    concreteDoc = DFConcreteDocumentNew(concretePackage);
+
     // Read input.html
-    DFDocument *htmlDoc = TestCaseGetHTML(script);
+    htmlDoc = TestCaseGetHTML(script,abstractPackage,&error);
     if (htmlDoc == NULL)
-        return;;
+        goto end;
 
-    // Update the docx file based on the contents of the HTML file
-    DFError *error = NULL;
-    DFPackage *abstractPackage = DFPackageNewFilesystem(script->abstractPath,DFFileFormatHTML);
-    if (!WordPackageUpdateFromHTML(wordPackage,htmlDoc,abstractPackage,"word",&error,NULL))
{
-        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
-        DFErrorRelease(error);
-        DFPackageRelease(abstractPackage);
-        return;
-    }
-    DFPackageRelease(abstractPackage);
+    DFAbstractDocumentSetHTML(abstractDoc,htmlDoc);
 
-    // We don't actually "save" the package as such; this is just to ensure the missing OPC
parts are added
-    WordPackageSave(wordPackage,NULL);
+    // Update the docx file based on the contents of the HTML file
+    if (!DFPut(concreteDoc,abstractDoc,&error))
+        goto end;
 
     // Output the updated docx file
-    DFHashTable *parts = getFlags(argc,argv);
-    char *plain = Word_toPlain(wordPackage,rawPackage,parts);
-    DFBufferFormat(script->output,"%s",plain);
-    free(plain);
-    DFHashTableRelease(parts);
+    parts = getFlags(argc,argv);
+    wordPlain = Word_toPlain(concretePackage,parts);
+
+end:
+    if (wordPlain != NULL)
+        DFBufferFormat(script->output,"%s",wordPlain);
+    else
+        DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
+
+    DFErrorRelease(error);
     DFDocumentRelease(htmlDoc);
+    DFPackageRelease(abstractPackage);
+    DFPackageRelease(concretePackage);
+    DFAbstractDocumentRelease(abstractDoc);
+    DFConcreteDocumentRelease(concreteDoc);
+    DFHashTableRelease(parts);
+    free(wordPlain);
 }
 
-static void Word_testUpdate(TestCase *script, int argc, const char **argv)
+static void LaTeX_testCreate(TestCase *script, int argc, const char **argv)
 {
     DFError *error = NULL;
-    WordPackage *wordPackage = NULL;
-    DFPackage *rawPackage = NULL;
-    if (!TestCaseOpenWordPackage(script,&wordPackage,&rawPackage,&error)) { //
Logs error itself on failure
+    DFPackage *htmlPackage = DFPackageNewFilesystem(script->abstractPath,DFFileFormatHTML);
+    DFDocument *htmlDoc = TestCaseGetHTML(script,htmlPackage,&error);
+    DFPackageRelease(htmlPackage);
+    if (htmlDoc == NULL) {
         DFBufferFormat(script->output,"%s\n",DFErrorMessage(&error));
         DFErrorRelease(error);
         return;
     }
 
-    Word_testUpdate2(script,wordPackage,rawPackage,argc,argv);
-    WordPackageRelease(wordPackage);
-    DFPackageRelease(rawPackage);
-}
-
-static void LaTeX_testCreate(TestCase *script, int argc, const char **argv)
-{
-    DFDocument *htmlDoc = TestCaseGetHTML(script);
-    if (htmlDoc == NULL)
-        return;
-
     HTML_normalizeDocument(htmlDoc);
     char *latex = HTMLToLaTeX(htmlDoc);
     DFBufferFormat(script->output,"%s",latex);


Mime
View raw message