corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject incubator-corinthia git commit: Add ODFTextConverter and TODOs for ODFTextGet
Date Sat, 25 Apr 2015 15:54:00 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/master 8a9efd124 -> ccd08368b


Add ODFTextConverter and TODOs for ODFTextGet


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

Branch: refs/heads/master
Commit: ccd08368b033293c3607341ad4d25038e349bf9e
Parents: 8a9efd1
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Sat Apr 25 22:53:19 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Sat Apr 25 22:53:19 2015 +0700

----------------------------------------------------------------------
 DocFormats/filters/odf/CMakeLists.txt           |  4 +-
 DocFormats/filters/odf/src/text/ODFText.c       | 59 +++++++++++++++++++-
 .../filters/odf/src/text/ODFTextConverter.c     | 53 ++++++++++++++++++
 .../filters/odf/src/text/ODFTextConverter.h     | 42 ++++++++++++++
 4 files changed, 155 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ccd08368/DocFormats/filters/odf/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/DocFormats/filters/odf/CMakeLists.txt b/DocFormats/filters/odf/CMakeLists.txt
index b38a965..9658f49 100644
--- a/DocFormats/filters/odf/CMakeLists.txt
+++ b/DocFormats/filters/odf/CMakeLists.txt
@@ -27,7 +27,9 @@ set(GroupSrc
 
 set(GroupSrcText
     src/text/ODFText.h
-    src/text/ODFText.c)
+    src/text/ODFText.c
+    src/text/ODFTextConverter.h
+    src/text/ODFTextConverter.c)
 
 set(GroupTests
     tests/ODFTests.c)

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ccd08368/DocFormats/filters/odf/src/text/ODFText.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/odf/src/text/ODFText.c b/DocFormats/filters/odf/src/text/ODFText.c
index 0e13531..495df4e 100644
--- a/DocFormats/filters/odf/src/text/ODFText.c
+++ b/DocFormats/filters/odf/src/text/ODFText.c
@@ -17,11 +17,66 @@
 
 #include "DFPlatform.h"
 #include "ODFText.h"
+#include "ODFPackage.h"
+#include "ODFTextConverter.h"
+#include "DFDOM.h"
+#include <stdio.h>
+
+static void traverseContent(ODFTextConverter *conv, DFNode *odfNode, DFNode *htmlNode)
+{
+    printf("ODF element: %s\n",DFNodeName(odfNode));
+    for (DFNode *odfChild = odfNode->first; odfChild != NULL; odfChild = odfChild->next)
+        traverseContent(conv,odfChild,htmlNode);
+
+    // TODO: Add a switch statement here to check the type of ODF element, and use
+    // DFCreateChildElement to create a new element in the HTML document as a child of htmlNode
+    // based on the type. As this function gets more complicated, it will likely be useful
to
+    // split it up into several functions
+}
 
 DFDocument *ODFTextGet(DFStorage *concreteStorage, DFStorage *abstractStorage, const char
*idPrefix, DFError **error)
 {
-    DFErrorFormat(error,"ODFTextGet: Not yet implemented");
-    return NULL;
+    int ok = 0;
+    DFDocument *html = NULL;
+    ODFPackage *package = NULL;
+    ODFTextConverter *conv = NULL;
+    DFNode *body = NULL;
+
+    package = ODFPackageOpenFrom(concreteStorage,error);
+    if (package == NULL)
+        goto end;
+
+    html = DFDocumentNewWithRoot(HTML_HTML);
+    body = DFCreateChildElement(html->root,HTML_BODY);
+    conv = ODFTextConverterNew(html,abstractStorage,package,idPrefix);
+
+    // TODO: Traverse the DOM tree of package->contentDoc, adding elements to the HTML
document.
+    // contentDoc is loaded from content.xml, and represents the most important information
in
+    // the document, i.e. the text, tables, lists, etc.
+    traverseContent(conv,package->contentDoc->root,body);
+
+    // TODO: Once this basic traversal is implemented and is capable of producing paragraphs,
+    // tables, lists, and spans, add ids to the HTML elements as they are created. That is,
set
+    // the id attribute of each new HTML element to a string containing the idPrefix followed
by
+    // the seqNo field of the node in contentDoc from which the HTML element was generated.
+    //
+    // These id attributes can then later be used in ODFTextPut to figure out which elements
in an
+    // updated HTML file correspond to existing elements in the ODF content document, which
lets us
+    // retain information in the ODF file that could not be translated to HTML during the
get.
+    //
+    // See WordConverterCreateAbstract and WordConverterGetConcrete for how this is done
in the
+    // Word filter.
+
+    ok = 1;
+
+end:
+    ODFPackageRelease(package);
+    ODFTextConverterRelease(conv);
+    if (!ok) {
+        DFDocumentRelease(html);
+        return NULL;
+    }
+    return html;
 }
 
 int ODFTextPut(DFStorage *concreteStorage, DFStorage *abstractStorage, DFDocument *htmlDoc,
const char *idPrefix, DFError **error)

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ccd08368/DocFormats/filters/odf/src/text/ODFTextConverter.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/odf/src/text/ODFTextConverter.c b/DocFormats/filters/odf/src/text/ODFTextConverter.c
new file mode 100644
index 0000000..760576a
--- /dev/null
+++ b/DocFormats/filters/odf/src/text/ODFTextConverter.c
@@ -0,0 +1,53 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "DFPlatform.h"
+#include "ODFTextConverter.h"
+#include "DFString.h"
+#include <stdlib.h>
+
+ODFTextConverter *ODFTextConverterNew(DFDocument *html,
+                                      DFStorage *abstractStorage,
+                                      ODFPackage *package,
+                                      const char *idPrefix)
+{
+    ODFTextConverter *conv = (ODFTextConverter *)calloc(1,sizeof(ODFTextConverter));
+    conv->retainCount = 1;
+    conv->html = DFDocumentRetain(html);
+    conv->abstractStorage = DFStorageRetain(abstractStorage);
+    conv->idPrefix = (idPrefix != NULL) ? xstrdup(idPrefix) : xstrdup("odf");
+    conv->package = ODFPackageRetain(package);
+    return conv;
+}
+
+ODFTextConverter *ODFTextConverterRetain(ODFTextConverter *conv)
+{
+    if (conv != NULL)
+        conv->retainCount++;
+    return conv;
+}
+
+void ODFTextConverterRelease(ODFTextConverter *conv)
+{
+    if ((conv == NULL) || (--conv->retainCount > 0))
+        return;
+    DFDocumentRelease(conv->html);
+    DFStorageRelease(conv->abstractStorage);
+    free(conv->idPrefix);
+    ODFPackageRelease(conv->package);
+    free(conv);
+}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ccd08368/DocFormats/filters/odf/src/text/ODFTextConverter.h
----------------------------------------------------------------------
diff --git a/DocFormats/filters/odf/src/text/ODFTextConverter.h b/DocFormats/filters/odf/src/text/ODFTextConverter.h
new file mode 100644
index 0000000..dfd97d6
--- /dev/null
+++ b/DocFormats/filters/odf/src/text/ODFTextConverter.h
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#ifndef DocFormats_ODFTextConverter_h
+#define DocFormats_ODFTextConverter_h
+
+#include <DocFormats/DFStorage.h>
+#include "DFDOM.h"
+#include "ODFPackage.h"
+
+typedef struct ODFTextConverter ODFTextConverter;
+
+struct ODFTextConverter {
+    size_t retainCount;
+    DFDocument *html;
+    DFStorage *abstractStorage;
+    ODFPackage *package;
+    char *idPrefix;
+};
+
+ODFTextConverter *ODFTextConverterNew(DFDocument *html,
+                                      DFStorage *abstractStorage,
+                                      ODFPackage *package,
+                                      const char *idPrefix);
+ODFTextConverter *ODFTextConverterRetain(ODFTextConverter *conv);
+void ODFTextConverterRelease(ODFTextConverter *conv);
+
+#endif


Mime
View raw message