[gxml] Implementation.vala: add error checking to create_document



commit ce5433944fc9b42746755e723b73add8264ff8c8
Author: Richard Schwarting <aquarichy gmail com>
Date:   Sat Jul 27 00:01:53 2013 -0400

    Implementation.vala: add error checking to create_document

 gxml/Implementation.vala |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/gxml/Implementation.vala b/gxml/Implementation.vala
index 21387b4..10e0064 100644
--- a/gxml/Implementation.vala
+++ b/gxml/Implementation.vala
@@ -52,6 +52,38 @@ namespace GXml {
                 * @return The new document.
                 */
                public Document create_document (string? namespace_uri, string? qualified_name, DocumentType? 
doctype) {
+                       if (qualified_name == null && namespace_uri != null) {
+                               GLib.warning ("NAMESPACE_ERR: qualified_name is null but namespace_uri [%s] 
is not.  Both should either be null or not null.", namespace_uri);
+                       }
+                       if (qualified_name != null) {
+                               Document.check_invalid_characters (qualified_name, "new Document's root");
+
+                               string[] parts = qualified_name.split (":");
+                               if (parts.length == 2) {
+                                       // we have a prefix!
+                                       if (namespace_uri == null) {
+                                               // but we don't have a namespace :|
+                                               GLib.warning ("NAMESPACE_ERR: qualified_name is null but 
namespace_uri [%s] is not.  Both should either be null or not null.", namespace_uri);
+                                       }
+
+                                       string expected_uri = "http://www.w3.org/XML/1998/namespace";;
+                                       if (parts[0] == "xml" && namespace_uri != expected_uri) {
+                                               GLib.warning ("NAMESPACE_ERR: qualified_name '%s' specifies 
namespace 'xml' but namespace_uri is '%s' and not '%s'",
+                                                             qualified_name, namespace_uri, expected_uri);
+                                       }
+                               }
+                       }
+                       // TODO: We should apparently also report a NAMESPACE_ERR if "the qualifiedName is 
malformed"; find out what that means
+                       if (namespace_uri != null && ! this.has_feature ("XML")) {
+                               // Right now, has_feature should always return true for 'XML' so we shouldn't 
trip this error
+                               GLib.warning ("NAMESPACE_ERR: Implementation lacks feature 'XML' but a 
namespace_uri ('%s') was specified anyway.", namespace_uri);
+                       }
+
+                       if (doctype.owner_document != null) {
+                               GLib.warning ("WRONG_DOCUMENT_ERR: The supplied doctype is already connected 
to an existing document.");
+                       }
+                       // TODO: also want to report if the doctype was created by a different 
implementation; of which we have no way of determining right now
+
                        Document doc = new Document.with_implementation (this, namespace_uri, qualified_name, 
doctype);
                        return doc;
                }


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