OpenDocument_support



Hi all,

A few weeks ago my team leader, Rodrigo Novo, sent an email asking about
your interest to have OpenDocument support in Gnumeric. We had some
delay due to another projects, but now I finished a first patch. This
one includes:
-support to redirect data from clipboard to the correct filter (OOo1 or
OpenDocument) (tanks for the people that help me through IRC channel);
-support to read OpenDocument meta.xml and to fill the File->Properties
dialog of Gnumeric, when openning OpenDocument spreadsheets (e.g.: OOo2.0)
-support to all meta xml tags of OpenDocument v1.0 format

As this is my first patch, any sugestions/questions will be welcome.


best regards,

Luciano M. Wolf
INdT

--- ../openoffice-read.c        2005-07-20 17:45:47.000000000 -0300
+++ openoffice-read.c   2005-08-03 10:49:34.447734872 -0300
@@ -55,6 +55,13 @@
 
 GNM_PLUGIN_MODULE_HEADER;
 
+/* Filter Type */
+#define mime_openofficeorg1 "application/vnd.sun.xml.calc"
+#define mime_opendocument "application/vnd.oasis.opendocument.spreadsheet"
+#define UNKNOWN -1
+#define OPENOFFICEORG1 0
+#define OPENDOCUMENT 1
+
 typedef enum {
        OO_STYLE_UNKNOWN,
        OO_STYLE_CELL,
@@ -1203,7 +1210,7 @@
                }
        }
 }
-
+/* --------------- OpenOffice.org 1.0 --------------- */
 static GsfXMLInNode opencalc_styles_dtd[] = {
 GSF_XML_IN_NODE_FULL (START, START, -1, NULL, FALSE, FALSE, TRUE, NULL, NULL, 0),
 GSF_XML_IN_NODE (START, OFFICE_FONTS, OO_NS_OFFICE, "font-decls", FALSE, NULL, NULL),
@@ -1391,6 +1398,362 @@
   { NULL }
 };
 
+/* --------------- OpenDocument --------------- */
+/* Gnumeric */
+static void
+od_meta_category (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("category", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_character_count (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("character_count", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_codepage (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("codepage", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_company (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("company", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_last_saved (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("last_saved", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_links_uptodate (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("application", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_manager (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("manager", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_number_of_bytes (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("number_of_bytes", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_number_of_hidden_slides (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("number_of_hidden_slides", state->base.content->str, 
TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_number_of_lines (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("number_of_lines", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_number_of_pages_with_notes (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("number_of_pages_with_notes", state->base.content->str, 
TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_number_of_paragraphs (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("number_of_paragraphs", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_number_of_slides (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("number_of_slides", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_number_of_sound_or_video_clips (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("number_of_sound_or_video_clips", 
state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_presentation_format (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("presentation_format", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_revision_number (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("revision_number", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_security (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("security", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_thumbnail_scaling (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("thumbnail_scaling", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_word_count (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("word_count", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+/* OASIS */
+static void
+od_meta_generator (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("application", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_meta_initial_creator (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("author", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_dc_description (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("comments", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_meta_creation_date (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("created", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_print_date (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("last_printed", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+static void
+od_meta_keyword (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("keywords", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_dc_creator (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("last_author", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_meta_page_count (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("page_count", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_dc_subject (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("subject", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_meta_template (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("template", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+static void
+od_dc_title (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
+{
+       OOParseState *state = (OOParseState *)xin;
+       SummaryItem *sit = summary_item_new_string ("title", state->base.content->str, TRUE);
+       SummaryInfo *sin = workbook_metadata(state->pos.wb);
+       summary_info_add(sin, sit);
+       summary_info_default(sin);
+}
+
+/* Generated based on:
+ * http://www.oasis-open.org/committees/download.php/12572/OpenDocument-v1.0-os.pdf */
+static GsfXMLInNode oasis_meta_dtd[] = {
+ GSF_XML_IN_NODE_FULL (START, START, -1, NULL, FALSE, FALSE, TRUE, NULL, NULL, 0),
+       GSF_XML_IN_NODE (START, META, OO_NS_OFFICE, "meta", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_GENERATOR, OO_NS_META, "generator", FALSE, NULL, 
&od_meta_generator),
+               GSF_XML_IN_NODE (META, META_KEYWORD, OO_NS_META, "keyword", TRUE, NULL, &od_meta_keyword),
+               GSF_XML_IN_NODE (META, META_INITIAL_CREATOR, OO_NS_META, "initial-creator", FALSE, NULL, 
&od_meta_initial_creator),
+               GSF_XML_IN_NODE (META, META_PRINTED_BY, OO_NS_META, "printed-by", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_CREATION_DATE, OO_NS_META, "creation-date", FALSE, NULL, 
&od_meta_creation_date),
+               GSF_XML_IN_NODE (META, META_PRINT_DATE, OO_NS_META, "print-date", FALSE, NULL, 
&od_meta_print_date),
+               GSF_XML_IN_NODE (META, META_TEMPLATE, OO_NS_META, "template", FALSE, NULL, &od_meta_template),
+
+               GSF_XML_IN_NODE (META, XLINK_HREF, OO_NS_XLINK, "href", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, XLINK_TITLE, OO_NS_XLINK, "title", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_DATE, OO_NS_META, "date", FALSE, NULL, NULL),
+
+               GSF_XML_IN_NODE (META, XLINK_AUTO_RELOAD, OO_NS_META, "auto-reload", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, XLINK_DELAY, OO_NS_META, "delay", FALSE, NULL, NULL),                  
  
+               GSF_XML_IN_NODE (META, XLINK_HYPERLINK_BEHAVIOUR, OO_NS_META, "hyperlink-behaviour", FALSE, 
NULL, NULL),
+               GSF_XML_IN_NODE (META, XLINK_TARGET_FRAME_NAME, OO_NS_META, "target-frame-name", FALSE, NULL, 
NULL),
+               GSF_XML_IN_NODE (META, META_EDITING_CYCLES, OO_NS_META, "editing-cycles", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_EDITING_DURATION, OO_NS_META, "editing-duration", FALSE, NULL, 
NULL),
+               GSF_XML_IN_NODE (META, META_DOCUMENT_STATISTIC, OO_NS_META, "document-statistic", FALSE, 
NULL, NULL),
+               GSF_XML_IN_NODE (META, META_PAGE_COUNT, OO_NS_META, "page-count", FALSE, NULL, 
&od_meta_page_count),
+               GSF_XML_IN_NODE (META, META_TABLE_COUNT, OO_NS_META, "table-count", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_IMAGE_COUNT, OO_NS_META, "image-count", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_CELL_COUNT, OO_NS_META, "cell-count", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_OBJECT_COUNT, OO_NS_META, "object-count", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, META_USER_DEFINED, OO_NS_META, "user-defined", FALSE, NULL, NULL),
+               
+               GSF_XML_IN_NODE (META, DC_TITLE, OO_NS_DC, "title", TRUE, NULL, &od_dc_title),
+               GSF_XML_IN_NODE (META, DC_DESCRIPTION, OO_NS_DC, "description", TRUE, NULL, 
&od_dc_description),
+               GSF_XML_IN_NODE (META, DC_SUBJECT, OO_NS_DC, "subject", FALSE, NULL, &od_dc_subject),
+               GSF_XML_IN_NODE (META, DC_CREATOR, OO_NS_DC, "creator", FALSE, NULL, &od_dc_creator),
+               GSF_XML_IN_NODE (META, DC_DATE, OO_NS_DC, "date", FALSE, NULL, NULL),
+               GSF_XML_IN_NODE (META, DC_LANGUAGE, OO_NS_DC, "language", FALSE, NULL, NULL),
+
+               /* Gnumeric TAGS */
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_CATEGORY, OO_NS_META, "category", FALSE, NULL, 
&od_meta_category),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_CHARACTER_COUNT, OO_NS_META, "character_count", 
FALSE, NULL, &od_meta_character_count),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_CODEPAGE, OO_NS_META, "codepage", FALSE, NULL, 
&od_meta_codepage),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_COMPANY, OO_NS_META, "company", FALSE, NULL, 
&od_meta_company),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_LAST_SAVED, OO_NS_META, "last_saved", FALSE, NULL, 
&od_meta_last_saved),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_LINKS_UPTODATE, OO_NS_META, "links_uptodate", FALSE, 
NULL, &od_meta_links_uptodate),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_MANAGER, OO_NS_META, "manager", FALSE, NULL, 
&od_meta_manager),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_NUMBER_OF_BYTES, OO_NS_META, "number_of_bytes", 
FALSE, NULL, &od_meta_number_of_bytes),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_NUMBER_OF_HIDDEN_SLIDES, OO_NS_META, 
"number_of_hidden_slides", FALSE, NULL, &od_meta_number_of_hidden_slides),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_NUMBER_OF_LINES, OO_NS_META, "number_of_lines", 
FALSE, NULL, &od_meta_number_of_lines),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_NUMBER_OF_PAGES_WITH_NOTES, OO_NS_META, 
"number_of_pages_with_notes", FALSE, NULL, &od_meta_number_of_pages_with_notes),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_NUMBER_OF_PARAGRAPHS, OO_NS_META, 
"number_of_paragraphs", FALSE, NULL, &od_meta_number_of_paragraphs),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_NUMBER_OF_SLIDES, OO_NS_META, "number_of_slides", 
FALSE, NULL, &od_meta_number_of_slides),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_NUMBER_OF_SOUND_OR_VIDEO_CLIPS, OO_NS_META, 
"number_of_sound_or_video_clips", FALSE, NULL, &od_meta_number_of_sound_or_video_clips),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_PRESENTATION_FORMAT, OO_NS_META, 
"presentation_format", FALSE, NULL, &od_meta_presentation_format),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_REVISION_NUMBER, OO_NS_META, "revision_number", 
FALSE, NULL, &od_meta_revision_number),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_SECURITY, OO_NS_META, "security", FALSE, NULL, 
&od_meta_security),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_THUMBNAIL_SCALING, OO_NS_META, "thumbnail_scaling", 
FALSE, NULL, &od_meta_thumbnail_scaling),
+               GSF_XML_IN_NODE (META_USER_DEFINED, META_WORD_COUNT, OO_NS_META, "word_count", FALSE, NULL, 
&od_meta_word_count),
+       { NULL },
+};
+
 /****************************************************************************/
 
 static GnmExpr const *
@@ -1441,6 +1804,7 @@
 }
 
 static GsfXMLInDoc *content_doc, *settings_doc, *styles_doc;
+static GsfXMLInDoc *meta_oasis;
 
 void
 openoffice_file_open (GOFileOpener const *fo, IOContext *io_context,
@@ -1451,11 +1815,15 @@
 {
        char *old_num_locale, *old_monetary_locale;
        OOParseState state;
+       GsfInput *mimetype = NULL;
+       GsfInput *meta = NULL;
        GsfInput *content = NULL;
        GsfInput *styles = NULL;
        GError   *err = NULL;
        GsfInfile *zip;
        int i;
+       guint8 *header = NULL;
+       gint filter = UNKNOWN;
 
        g_return_if_fail (IS_WORKBOOK_VIEW (wb_view));
        g_return_if_fail (GSF_IS_INPUT (input));
@@ -1469,6 +1837,30 @@
                return;
        }
 
+       mimetype = gsf_infile_child_by_name (zip, "mimetype");
+       if (mimetype == NULL) {
+               go_cmd_context_error_import (GO_CMD_CONTEXT (io_context),
+                        _("No stream named mimetype found."));
+               g_object_unref (G_OBJECT (zip));
+               return;
+       }
+
+       if (!gsf_input_seek (mimetype, 0, G_SEEK_SET))
+               header = gsf_input_read (mimetype, gsf_input_size (mimetype), NULL);
+
+       if (!strncmp (mime_openofficeorg1, header, gsf_input_size (mimetype)))
+               filter = OPENOFFICEORG1;
+       else if (!strncmp (mime_opendocument, header, gsf_input_size (mimetype)))
+               filter = OPENDOCUMENT;
+       else{
+               g_object_unref (G_OBJECT (zip));
+               return;
+       }
+       
+       if (filter == OPENDOCUMENT)
+               meta = gsf_infile_child_by_name (zip, "meta.xml");
+       /* meta==NULL is not tested. The function 'paste' doesn't generate this file. */
+
        content = gsf_infile_child_by_name (zip, "content.xml");
        if (content == NULL) {
                go_cmd_context_error_import (GO_CMD_CONTEXT (io_context),
@@ -1512,13 +1904,20 @@
        state.exprconv = oo_conventions ();
        state.accum_fmt = NULL;
 
-       if (styles != NULL) {
+       if (meta != NULL) {
+               state.base.doc = meta_oasis;
+               gsf_xml_in_parse (&state.base, meta);
+               g_object_unref (meta);
+       }
+
+       if ((styles != NULL) && (filter == OPENOFFICEORG1)) {
                state.base.doc = styles_doc;
                gsf_xml_in_parse (&state.base, styles);
                g_object_unref (styles);
        }
 
        state.base.doc = content_doc;
+               
        if (gsf_xml_in_parse (&state.base, content)) {
                GsfInput *settings;
 
@@ -1530,7 +1929,7 @@
 
                /* look for the view settings */
                settings = gsf_infile_child_by_name (zip, "settings.xml");
-               if (settings != NULL) {
+               if ((settings != NULL) && (filter == OPENOFFICEORG1)) {
                        state.base.doc = settings_doc;
                        gsf_xml_in_parse (&state.base, settings);
                        g_object_unref (G_OBJECT (settings));
@@ -1563,6 +1962,8 @@
        styles_doc   = gsf_xml_in_doc_new (opencalc_styles_dtd, ooo_ns);
        content_doc  = gsf_xml_in_doc_new (opencalc_content_dtd, ooo_ns);
        settings_doc = gsf_xml_in_doc_new (opencalc_settings_dtd, ooo_ns);
+
+       meta_oasis   = gsf_xml_in_doc_new (oasis_meta_dtd, ooo_ns);
 }
 G_MODULE_EXPORT void
 go_plugin_shutdown (GOPlugin *plugin, GOCmdContext *cc)
@@ -1570,4 +1971,6 @@
        gsf_xml_in_doc_free (styles_doc);
        gsf_xml_in_doc_free (content_doc);
        gsf_xml_in_doc_free (settings_doc);
+
+       gsf_xml_in_doc_free (meta_oasis);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]