[glom] Use an xmlns ID for the MIME-type registration.



commit f44537eea0918b84af77f69cee188972aa05100f
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Jul 17 18:57:30 2009 +0200

    Use an xmlns ID for the MIME-type registration.
    
    * glom/libglom/document/bakery/document_xml.[h|cc]: set_dtd_root_node_name():
    Take an optional xmlns ID and write this in the document.
    * glom/libglom/document/document.cc: Constructor: Specify a
    http://glom.org/glom_document xmlns ID. I don't think this needs to exist.
    This will make it easier for the MIME-type system to detect the file's MIME
    type.
    * glom.xml: (MIME-type detection rules): Add a root-XML rule, that checks
    for the xmlns and the root node name. We keep the string check too for
    legacy.

 ChangeLog                                    |   14 ++++++++++++++
 Makefile.am                                  |    1 +
 glom.xml                                     |    5 +++++
 glom/libglom/document/bakery/document_xml.cc |    5 +++--
 glom/libglom/document/bakery/document_xml.h  |    9 +++++++--
 glom/libglom/document/document.cc            |    6 +++++-
 6 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f3bfc6e..784c1a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-07-17  Murray Cumming  <murrayc murrayc com>
+
+	Use an xmlns ID for the MIME-type registration.
+	
+	* glom/libglom/document/bakery/document_xml.[h|cc]: set_dtd_root_node_name():
+	Take an optional xmlns ID and write this in the document.
+	* glom/libglom/document/document.cc: Constructor: Specify a 
+	http://glom.org/glom_document xmlns ID. I don't think this needs to exist.
+	This will make it easier for the MIME-type system to detect the file's MIME 
+	type.
+	* glom.xml: (MIME-type detection rules): Add a root-XML rule, that checks 
+	for the xmlns and the root node name. We keep the string check too for 
+	legacy.
+
 2009-07-10  Murray Cumming  <murrayc murrayc com>
 
 	Export: Don't open the format dialog behind the FileChooser dialog.
diff --git a/Makefile.am b/Makefile.am
index 8e9a15a..edfc3cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ desktop_DATA = $(desktop_in_files:.desktop.in.in=.desktop)
 
 # This is the old MIME-type system.
 # GNOME 2.6 seems to require that we register with both the old and the new MIME-type systems.
+# TODO: Try removing this?
 mimeinfodir = $(datadir)/mime-info
 mimeinfo_DATA = glom.keys glom.mime
 
diff --git a/glom.xml b/glom.xml
index f75dc8f..43f6f50 100644
--- a/glom.xml
+++ b/glom.xml
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- This is a MIME-type registration file.-->
 <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info";>
   <mime-type type="application/x-glom">
     <comment>Glom</comment>
@@ -6,9 +7,13 @@
 
     <glob pattern="*.glom"/>
 
+    <!-- We keep this string match for systems that maybe don't support root-XML, 
+         and for old .glom files that don't mention our xmlns ID. --> 
     <magic priority="80">
       <match type="string" value="&lt;glom_document" offset="0:100"/>
     </magic>
+    
+    <root-XML namespaceURI="http://glom.org/glom_document"; localName="glom_document"/>
 
   </mime-type>
 </mime-info>
diff --git a/glom/libglom/document/bakery/document_xml.cc b/glom/libglom/document/bakery/document_xml.cc
index 7ccef28..8692c84 100644
--- a/glom/libglom/document/bakery/document_xml.cc
+++ b/glom/libglom/document/bakery/document_xml.cc
@@ -214,9 +214,10 @@ std::string Document_XML::get_dtd_name() const
   return m_strDTD_Name;
 }
 
-void Document_XML::set_dtd_root_node_name(const Glib::ustring& strVal)
+void Document_XML::set_dtd_root_node_name(const Glib::ustring& strVal, const Glib::ustring& xmlns)
 {
   m_strRootNodeName = strVal;
+  m_root_xmlns = xmlns;
 }
 
 Glib::ustring Document_XML::get_dtd_root_node_name() const
@@ -240,7 +241,7 @@ xmlpp::Element* Document_XML::get_node_document()
   if(!nodeRoot)
   {
     //Add it if it isn't there already:
-    return m_pDOM_Document->create_root_node(m_strRootNodeName);
+    return m_pDOM_Document->create_root_node(m_strRootNodeName, m_root_xmlns);
   }
   else
     return nodeRoot;
diff --git a/glom/libglom/document/bakery/document_xml.h b/glom/libglom/document/bakery/document_xml.h
index 5ca2149..c079cac 100644
--- a/glom/libglom/document/bakery/document_xml.h
+++ b/glom/libglom/document/bakery/document_xml.h
@@ -44,7 +44,12 @@ public:
   void set_dtd_name(const std::string& strVal); //e.g. "glom.dtd"
   std::string get_dtd_name() const;
 
-  void set_dtd_root_node_name(const Glib::ustring& strVal);
+  /** Set the root node name and (optionally) the xmlns ID to be written 
+   * when writing the document.
+   * The root node name is also used when reading documents.
+   */
+  void set_dtd_root_node_name(const Glib::ustring& strVal, const Glib::ustring& xmlns = Glib::ustring());
+  
   Glib::ustring get_dtd_root_node_name() const;
 
   /** Whether to add extra whitespace when writing the XML to disk.
@@ -84,7 +89,7 @@ protected:
   xmlpp::Document* m_pDOM_Document; //1-to-1 with the m_DOM_Parser.
   
   std::string m_strDTD_Name;
-  Glib::ustring m_strRootNodeName;
+  Glib::ustring m_strRootNodeName, m_root_xmlns;
   bool m_write_formatted;
 };
 
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index e7073cd..146670d 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -256,7 +256,11 @@ Document::Document()
   set_dtd_name("glom_document.dtd");
   //set_DTD_Location(GLOM_DTD_INSTALL_DIR); //Determined at configure time. It still looks in the working directory first.
 
-  set_dtd_root_node_name("glom_document");
+  //The xmlns URI does not need to be something that actually exists.
+  //I think it is just a unique ID. murrayc.
+  //It helps the MIME-type system to recognize the file type.
+  set_dtd_root_node_name("glom_document", 
+    "http://glom.org/glom_document"; /* xmlns ID */);
 
   //We don't use set_write_formatted() because it doesn't handle text nodes well.
   //We use add_indenting_white_space_to_node() instead later.



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