[gnumeric] xml: separate dom and sax code more.



commit 9548c0fbde1d2e97b9d5ee9c2e5522a3f502bd11
Author: Morten Welinder <terra gnome org>
Date:   Mon Sep 21 16:59:33 2009 -0400

    xml: separate dom and sax code more.

 src/gnm-so-filled.c       |    1 +
 src/gnm-so-line.c         |    1 +
 src/libgnumeric.c         |    5 +++-
 src/sheet-object-image.c  |    1 +
 src/sheet-object-widget.c |    1 +
 src/tools/solver/solver.c |    1 +
 src/xml-io.c              |   25 +++----------------
 src/xml-io.h              |   15 +-----------
 src/xml-sax-read.c        |   57 ++++++++++++++++++++++++++++++++++++++++++++-
 src/xml-sax-write.c       |   19 ++++++++++++++-
 src/xml-sax.h             |   19 ++++++++++++---
 11 files changed, 103 insertions(+), 42 deletions(-)
---
diff --git a/src/gnm-so-filled.c b/src/gnm-so-filled.c
index fc3248e..0e9a802 100644
--- a/src/gnm-so-filled.c
+++ b/src/gnm-so-filled.c
@@ -25,6 +25,7 @@
 #include "gnm-so-filled.h"
 #include "sheet-object-impl.h"
 #include "xml-io.h"
+#include "xml-sax.h"
 
 #include <goffice/goffice.h>
 #include <gsf/gsf-impl-utils.h>
diff --git a/src/gnm-so-line.c b/src/gnm-so-line.c
index ec0a20d..47d5203 100644
--- a/src/gnm-so-line.c
+++ b/src/gnm-so-line.c
@@ -25,6 +25,7 @@
 #include "gnm-so-line.h"
 #include "sheet-object-impl.h"
 #include "xml-io.h"
+#include "xml-sax.h"
 
 #include <goffice/goffice.h>
 #include <gsf/gsf-impl-utils.h>
diff --git a/src/libgnumeric.c b/src/libgnumeric.c
index ce19aa2..eb1d394 100644
--- a/src/libgnumeric.c
+++ b/src/libgnumeric.c
@@ -45,6 +45,7 @@
 #include "sheet-autofill.h"
 #include "sheet-private.h"
 #include "xml-io.h"
+#include "xml-sax.h"
 #include "clipboard.h"
 #include "value.h"
 #include "expr.h"
@@ -283,8 +284,10 @@ gnm_init (void)
 	gnm_hlink_external_get_type ();
 
 	/* The statically linked in file formats */
-	xml_init ();
+	gnm_xml_sax_read_init ();
+	gnm_xml_sax_write_init ();
 	stf_init ();
+	xml_dom_init ();
 
 	glade_init ();
 }
diff --git a/src/sheet-object-image.c b/src/sheet-object-image.c
index ce3dbad..a1dd841 100644
--- a/src/sheet-object-image.c
+++ b/src/sheet-object-image.c
@@ -18,6 +18,7 @@
 #include "gui-file.h"
 #include "application.h"
 #include "xml-io.h"
+#include "xml-sax.h"
 
 #include <goffice/goffice.h>
 #include <gsf/gsf-impl-utils.h>
diff --git a/src/sheet-object-widget.c b/src/sheet-object-widget.c
index 1b4f538..75240a6 100644
--- a/src/sheet-object-widget.c
+++ b/src/sheet-object-widget.c
@@ -45,6 +45,7 @@
 #include "dialogs.h"
 #include "dialogs/help.h"
 #include "xml-io.h"
+#include "xml-sax.h"
 #include "commands.h"
 #include "gnm-format.h"
 
diff --git a/src/tools/solver/solver.c b/src/tools/solver/solver.c
index 6b68158..11f247e 100644
--- a/src/tools/solver/solver.c
+++ b/src/tools/solver/solver.c
@@ -43,6 +43,7 @@
 #include "gutils.h"
 #include <goffice/goffice.h>
 #include "xml-io.h"
+#include "xml-sax.h"
 
 #include <math.h>
 #include <string.h>
diff --git a/src/xml-io.c b/src/xml-io.c
index a1bdf1b..30a4736 100644
--- a/src/xml-io.c
+++ b/src/xml-io.c
@@ -2580,7 +2580,6 @@ xml_dom_read_error (gpointer state, char const *fmt, ...)
 	else
 		go_io_error_info_set (io_context, ei);
 }
-
 /**************************************************************************/
 
 static gboolean
@@ -2619,8 +2618,8 @@ xml_probe (GOFileOpener const *fo, GsfInput *input, GOFileProbeLevel pl)
 	/* probe by content */
 	return gsf_xml_probe (input, &gnm_xml_probe_element);
 }
-/**************************************************************************/
 
+/**************************************************************************/
 /*
  * Open an XML file and read a Workbook
  * One parse the XML file, getting a tree, then analyze the tree to build
@@ -2709,32 +2708,16 @@ gnumeric_xml_read_workbook (GOFileOpener const *fo,
 	xmlFreeDoc (res);
 }
 
+
+#warning "REMOVE for 2.0"
 void
-xml_init (void)
+xml_dom_init (void)
 {
-	GOFileSaver *saver;
 	GSList *suffixes = go_slist_create (g_strdup ("gnumeric"), g_strdup ("xml"), NULL);
 	GSList *mimes = go_slist_create (g_strdup ("application/x-gnumeric"), NULL);
-#warning REMOVE for 2.0
 	go_file_opener_register (go_file_opener_new (
 		"Gnumeric_XmlIO:dom",
 		_("Gnumeric XML (*.gnumeric) Old slow importer"),
 		suffixes, mimes,
 		xml_probe, gnumeric_xml_read_workbook), 40);
-
-	go_file_opener_register (go_file_opener_new (
-		"Gnumeric_XmlIO:sax",
-		_("Gnumeric XML (*.gnumeric)"),
-		suffixes, mimes,
-		xml_probe, gnm_xml_file_open), 50);
-
-	saver = go_file_saver_new ("Gnumeric_XmlIO:sax",
-				   "gnumeric",
-				   _("Gnumeric XML (*.gnumeric)"),
-				   GO_FILE_FL_AUTO, gnm_xml_file_save);
-	g_object_set (G_OBJECT (saver),
-		      "mime-type", "application/x-gnumeric",
-		      NULL);
-
-	go_file_saver_register_as_default (saver, 50);
 }
diff --git a/src/xml-io.h b/src/xml-io.h
index e669be4..8c03f14 100644
--- a/src/xml-io.h
+++ b/src/xml-io.h
@@ -48,20 +48,7 @@ void       xml_node_set_color	(xmlNodePtr node, char const *name, GnmColor const
 GnmStyle      *xml_read_style     (XmlParseContext *ctxt, xmlNodePtr tree,
 				   gboolean leave_empty);
 
-void      xml_init (void);
-/* Gnumeric specific SAX utilities */
-void gnm_xml_out_add_gocolor (GsfXMLOut *o, char const *id, GOColor c);
-
-/* Gnumeric specific SAX import */
-gboolean gnm_xml_attr_int     (xmlChar const * const *attrs,
-			       char const *name, int * res);
-gboolean gnm_xml_attr_double  (xmlChar const * const *attrs,
-			       char const *name, double * res);
-gboolean gnm_xml_attr_bool    (xmlChar const * const *attrs,
-			       char const *name, gboolean *res);
-
-SheetObject *gnm_xml_in_cur_obj   (GsfXMLIn const *xin);
-Sheet	    *gnm_xml_in_cur_sheet (GsfXMLIn const *xin);
+void      xml_dom_init (void);
 
 GnmConventions *gnm_xml_io_conventions (void);
 
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index 11ddd64..af7fa1c 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -67,6 +67,7 @@
 #include <gsf/gsf-input-memory.h>
 #include <gsf/gsf-input-gzip.h>
 #include <gsf/gsf-opendoc-utils.h>
+#include <gsf/gsf-utils.h>
 #include <glib/gi18n-lib.h>
 #include <libxml/tree.h>
 #include <libxml/parser.h>
@@ -2670,7 +2671,7 @@ maybe_convert (GsfInput *input, gboolean quiet)
 	}
 }
 
-void
+static void
 gnm_xml_file_open (GOFileOpener const *fo, GOIOContext *io_context,
 		   gpointer wb_view, GsfInput *input)
 {
@@ -2752,3 +2753,57 @@ gnm_xml_file_open (GOFileOpener const *fo, GOIOContext *io_context,
 
 	gsf_xml_in_doc_free (doc);
 }
+
+static gboolean
+gnm_xml_probe_element (const xmlChar *name,
+		       G_GNUC_UNUSED const xmlChar *prefix,
+		       const xmlChar *URI,
+		       G_GNUC_UNUSED int nb_namespaces,
+		       G_GNUC_UNUSED const xmlChar **namespaces,
+		       G_GNUC_UNUSED int nb_attributes,
+		       G_GNUC_UNUSED int nb_defaulted,
+		       G_GNUC_UNUSED const xmlChar **attributes)
+{
+	return 0 == strcmp (name, "Workbook") &&
+		NULL != URI && NULL != strstr (URI, "gnumeric");
+}
+
+static gboolean
+xml_probe (GOFileOpener const *fo, GsfInput *input, GOFileProbeLevel pl)
+{
+	if (pl == GO_FILE_PROBE_FILE_NAME) {
+		char const *name = gsf_input_name (input);
+		int len;
+
+		if (name == NULL)
+			return FALSE;
+
+		len = strlen (name);
+		if (len >= 7 && !g_ascii_strcasecmp (name+len-7, ".xml.gz"))
+			return TRUE;
+
+		name = gsf_extension_pointer (name);
+
+		return (name != NULL &&
+			(g_ascii_strcasecmp (name, "gnumeric") == 0 ||
+			 g_ascii_strcasecmp (name, "xml") == 0));
+	}
+	/* probe by content */
+	return gsf_xml_probe (input, &gnm_xml_probe_element);
+}
+
+void
+gnm_xml_sax_read_init (void)
+{
+	GSList *suffixes = go_slist_create (g_strdup ("gnumeric"),
+					    g_strdup ("xml"),
+					    NULL);
+	GSList *mimes = go_slist_create (g_strdup ("application/x-gnumeric"),
+					 NULL);
+
+	go_file_opener_register (go_file_opener_new (
+		"Gnumeric_XmlIO:sax",
+		_("Gnumeric XML (*.gnumeric)"),
+		suffixes, mimes,
+		xml_probe, gnm_xml_file_open), 50);
+}
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index f708362..6686530 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -25,6 +25,7 @@
 
 #include <gnumeric-config.h>
 #include <gnumeric.h>
+#include <glib/gi18n-lib.h>
 #include <xml-sax.h>
 #include <workbook-view.h>
 #include <gnm-format.h>
@@ -1287,7 +1288,7 @@ gnm_xml_io_conventions (void)
 	return res;
 }
 
-void
+static void
 gnm_xml_file_save (GOFileSaver const *fs, GOIOContext *io_context,
 		   gconstpointer wb_view, GsfOutput *output)
 {
@@ -1483,3 +1484,19 @@ gnm_cellregion_to_xml (GnmCellRegion const *cr)
 
 	return GSF_OUTPUT_MEMORY (buf);
 }
+
+
+void
+gnm_xml_sax_write_init (void)
+{
+	GOFileSaver *saver = go_file_saver_new
+		("Gnumeric_XmlIO:sax",
+		 "gnumeric",
+		 _("Gnumeric XML (*.gnumeric)"),
+		 GO_FILE_FL_AUTO, gnm_xml_file_save);
+	g_object_set (G_OBJECT (saver),
+		      "mime-type", "application/x-gnumeric",
+		      NULL);
+
+	go_file_saver_register_as_default (saver, 50);
+}
diff --git a/src/xml-sax.h b/src/xml-sax.h
index 3205139..86c49db 100644
--- a/src/xml-sax.h
+++ b/src/xml-sax.h
@@ -8,14 +8,25 @@
 
 G_BEGIN_DECLS
 
-void	gnm_xml_file_open	(GOFileOpener const *fo, GOIOContext *io_context,
-				 gpointer wb_view, GsfInput *input);
+/* Gnumeric specific SAX utilities */
+void gnm_xml_out_add_gocolor (GsfXMLOut *o, char const *id, GOColor c);
+gboolean gnm_xml_attr_int     (xmlChar const * const *attrs,
+			       char const *name, int * res);
+gboolean gnm_xml_attr_double  (xmlChar const * const *attrs,
+			       char const *name, double * res);
+gboolean gnm_xml_attr_bool    (xmlChar const * const *attrs,
+			       char const *name, gboolean *res);
+
+SheetObject *gnm_xml_in_cur_obj   (GsfXMLIn const *xin);
+Sheet	    *gnm_xml_in_cur_sheet (GsfXMLIn const *xin);
+
 
-void	gnm_xml_file_save	(GOFileSaver const *fs, GOIOContext *io_context,
-				 gconstpointer wb_view, GsfOutput *output);
 GsfOutputMemory *
 	gnm_cellregion_to_xml	(GnmCellRegion const *cr);
 
+void      gnm_xml_sax_read_init (void);
+void      gnm_xml_sax_write_init (void);
+
 G_END_DECLS
 
 #endif /* _GNM_XML_SAX_H_ */



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