[gxml] GOM: Removed Parser in Gom classes
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] GOM: Removed Parser in Gom classes
- Date: Fri, 4 Nov 2016 21:16:02 +0000 (UTC)
commit 55df440bc2aba296f42e8482e517f63584346689
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Nov 4 13:08:12 2016 -0600
GOM: Removed Parser in Gom classes
To serialize to string/stream, you now
requires to create a parser giving the
DomNode you want to write/read then
call read/write functions over parser
gxml/GomDocument.vala | 24 ++++++++++--------------
test/GomDocumentTest.vala | 18 ++++++++++++------
test/GomElementTest.vala | 9 ++++++---
test/GomSerializationTest.vala | 19 +++++++++++++++----
4 files changed, 43 insertions(+), 27 deletions(-)
---
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 09cefeb..fe30e42 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -35,7 +35,6 @@ public class GXml.GomDocument : GomNode,
protected string _compat_mode;
protected string _character_set;
protected string _content_type;
- protected Parser _parser;
protected GXml.DomEvent _constructor;
public DomImplementation implementation { get { return _implementation; } }
public string url { get { return _url; } }
@@ -60,8 +59,6 @@ public class GXml.GomDocument : GomNode,
}
}
- public GXml.Parser parser { get { return _parser; } set { _parser = value; } }
-
construct {
_local_name = "#document";
_node_type = DomNode.NodeType.DOCUMENT_NODE;
@@ -70,7 +67,6 @@ public class GXml.GomDocument : GomNode,
_compat_mode = "";
_character_set = "utf-8";
_content_type = "application/xml";
- _parser = new XParser (this);
}
public GomDocument () {}
public GomDocument.from_path (string path) throws GLib.Error {
@@ -83,28 +79,28 @@ public class GXml.GomDocument : GomNode,
}
public GomDocument.from_file (GLib.File file) throws GLib.Error {
- _parser.read_file (file, null);
+ var parser = new XParser (this);
+ parser.read_file (file, null);
}
public GomDocument.from_stream (GLib.InputStream stream) throws GLib.Error {
- _parser.read_stream (stream, null);
+ var parser = new XParser (this);
+ parser.read_stream (stream, null);
}
public GomDocument.from_string (string str) throws GLib.Error {
- _parser.read_string (str, null);
- }
-
-
- public string to_string () {
- return _parser.write_string ();
+ var parser = new XParser (this);
+ parser.read_string (str, null);
}
public void write_file (GLib.File file) throws GLib.Error {
- _parser.write_file (file, null);
+ var parser = new XParser (this);
+ parser.write_file (file, null);
}
public void write_stream (GLib.OutputStream stream) throws GLib.Error {
- _parser.write_stream (stream, null);
+ var parser = new XParser (this);
+ parser.write_stream (stream, null);
}
public DomElement create_element (string local_name) throws GLib.Error {
diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala
index 32dce89..6ed027d 100644
--- a/test/GomDocumentTest.vala
+++ b/test/GomDocumentTest.vala
@@ -79,7 +79,8 @@ class GomDocumentTest : GXmlTest {
var s = new GLib.StringBuilder ();
s.append ("""<document_element />""");
var d = new GomDocument.from_string (s.str);
- Test.message ("Saving to file: "+f.get_uri ()+d.to_string ());
+ var parser = new XParser (d);
+ Test.message ("Saving to file: "+f.get_uri ()+parser.write_string ());
d.write_file (f);
assert (f.query_exists ());
var d2 = new GomDocument.from_file (f);
@@ -134,7 +135,8 @@ class GomDocumentTest : GXmlTest {
var d = new GomDocument.from_file (rf);
assert (d != null);
assert (d.document_element != null);
- string s = d.to_string ();
+ var parser = new XParser (d);
+ string s = parser.write_string ();
GLib.message ("File read: "+s);
assert ("<name xml:lang=\"en\">GXml</name>" in s);
assert ("<shortdesc xml:lang=\"en\">GObject XML and Serialization
API</shortdesc>"
@@ -154,7 +156,8 @@ class GomDocumentTest : GXmlTest {
doc.append_child (r);
assert (r.prefix == null);
assert (r.namespace_uri == "http://live.gnome.org/GXml");
- string s = doc.to_string ();
+ var parser = new XParser (doc);
+ string s = parser.write_string ();
GLib.message (@"DOC: "+s);
assert ("<root xmlns=\"http://live.gnome.org/GXml\"/>" in s);
doc.document_element.set_attribute_ns ("http://www.w3.org/2000/xmlns/",
@@ -296,7 +299,8 @@ class GomDocumentTest : GXmlTest {
assert (doc.document_element != null);
((DomElement) doc.document_element).set_attribute ("attrname", "attrvalue");
assert (doc.document_element.attributes.size == 1);
- //Test.message ("DOC:"+doc.to_string ());
+ var parser = new XParser (doc);
+ //Test.message ("DOC:"+parser.write_string ());
var attr = ((DomElement) doc.document_element).get_attribute ("attrname");
Test.message ("Attr value: "+attr);
assert (attr != null);
@@ -310,7 +314,8 @@ class GomDocumentTest : GXmlTest {
DomDocument doc = new GomDocument.from_string ("<?xml version=\"1.0\"?>
<Sentences><Sentence lang=\"en\">I like the colour blue.</Sentence><Sentence lang=\"de\">Ich liebe die
Tür.</Sentence><Authors><Author><Name>Fred</Name><Email>fweasley hogwarts co
uk</Email></Author><Author><Name>George</Name><Email>gweasley hogwarts co
uk</Email></Author></Authors></Sentences>");
- string s1 = (doc as GomDocument).to_string ();
+ var parser = new XParser (doc);
+ string s1 = parser.write_string ();
assert (s1 != null);
GLib.message ("Document Read:"+s1);
string[] cs1 = s1.split ("\n");
@@ -322,7 +327,8 @@ class GomDocumentTest : GXmlTest {
Test.add_func ("/gxml/gom-document/to_string/extended", () => {
try {
var d = new GomDocument.from_path
(GXmlTestConfig.TEST_DIR+"/gdocument-read.xml");
- GLib.message ("Document Read:"+d.to_string ());
+ var parser = new XParser (d);
+ GLib.message ("Document Read:"+parser.write_string ());
assert (d.document_element != null);
assert (d.document_element.node_name == "DataTypeTemplates");
Test.message (d.document_element.child_nodes.size.to_string ());
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index dca6aab..9cce090 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -103,7 +103,8 @@ class GomElementTest : GXmlTest {
elem.set_attribute ("alley", "Diagon");
elem.set_attribute ("train", "Hogwarts Express");
assert (elem.attributes.size == 2);
- Test.message ("Getting attributes value alley... Node: "+doc.to_string ());
+ var parser = new XParser (doc);
+ Test.message ("Getting attributes value alley... Node: "+parser.write_string
());
assert (elem.attributes.get_named_item ("alley").node_value == "Diagon");
assert (elem.attributes.get_named_item ("train").node_value == "Hogwarts
Express");
@@ -150,7 +151,8 @@ class GomElementTest : GXmlTest {
root.child_nodes.add (n);
var t = doc.create_text_node ("TEXT1");
root.child_nodes.add (t);
- string s = doc.to_string ().split ("\n")[1];
+ var parser = new XParser (doc);
+ string s = parser.write_string ().split ("\n")[1];
assert (s == "<root><child/>TEXT1</root>");
} catch (GLib.Error e) {
Test.message (e.message);
@@ -166,7 +168,8 @@ class GomElementTest : GXmlTest {
root.child_nodes.add (n);
var t = doc.create_text_node ("TEXT1") as DomText;
root.child_nodes.add (t);
- string s = doc.to_string ().split ("\n")[1];
+ var parser = new XParser (doc);
+ string s = parser.write_string ().split ("\n")[1];
assert (s == "<root><child/>TEXT1</root>");
} catch (GLib.Error e) {
Test.message (e.message);
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index ec216ae..55cb6a2 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -29,7 +29,10 @@ class GomSerializationTest : GXmlTest {
construct {
_local_name = "Book";
}
- public string to_string () { return (_document as GomDocument).to_string (); }
+ public string to_string () {
+ var parser = new XParser (this);
+ return parser.write_string ();
+ }
}
public class Computer : GomElement {
[Description (nick="::Model")]
@@ -38,7 +41,10 @@ class GomSerializationTest : GXmlTest {
construct {
_local_name = "Computer";
}
- public string to_string () { return (_document as GomDocument).to_string (); }
+ public string to_string () {
+ var parser = new XParser (this);
+ return parser.write_string ();
+ }
}
public class Taxes : GomElement {
[Description (nick="::monthRate")]
@@ -50,7 +56,10 @@ class GomSerializationTest : GXmlTest {
construct {
_local_name = "Taxes";
}
- public string to_string () { return (_document as GomDocument).to_string (); }
+ public string to_string () {
+ var parser = new XParser (this);
+ return parser.write_string ();
+ }
public enum Month {
JANUARY,
FEBRUARY
@@ -59,7 +68,8 @@ class GomSerializationTest : GXmlTest {
public static void add_tests () {
Test.add_func ("/gxml/gom-serialization/write/properties", () => {
var b = new Book ();
- string s = b.to_string ();
+ var parser = new XParser (b);
+ string s = parser.write_string ();
assert (s != null);
assert ("<Book/>" in s);
b.name = "My Book";
@@ -105,6 +115,7 @@ class GomSerializationTest : GXmlTest {
string s = (b.owner_document as GomDocument).to_string ();
assert (s != null);
assert ("<Book Name=\"Loco\"/>" in s);
+ GLib.message ("Doc:"+s);
b.name = "My Book";
assert (b.get_attribute ("name") == "My Book");
s = b.to_string ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]