[gxml] DomElement: added serialization methods
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] DomElement: added serialization methods
- Date: Wed, 20 Mar 2019 17:45:36 +0000 (UTC)
commit 231583e32a26990090d5de6ef7f89ef398d9f682
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Mar 20 11:19:58 2019 -0600
DomElement: added serialization methods
Got from GomElement to be implemented by other
classes and to avoid cast to GomElement when they
are needed.
Fix https://gitlab.gnome.org/GNOME/gxml/issues/15
NEWS | 1 +
gxml/DomDocument.vala | 60 +++++++++++++++++++++++++++++++++++
gxml/DomElement.vala | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
gxml/GomDocument.vala | 12 +++----
gxml/GomElement.vala | 22 +++----------
5 files changed, 159 insertions(+), 23 deletions(-)
---
diff --git a/NEWS b/NEWS
index e7261fe..03a907d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
===============
Version 0.18.0
===============
+* New serialization methods for DomElement and DomDocument interfaces
* Now all GomElement attributes are available from 'attributes' property,
this include basic and Object's implementing GomProperty
* New CSS Selector machinery thanks to Yannick Inizan <inizan yannick gmail com>
diff --git a/gxml/DomDocument.vala b/gxml/DomDocument.vala
index 9837331..a671132 100644
--- a/gxml/DomDocument.vala
+++ b/gxml/DomDocument.vala
@@ -70,6 +70,66 @@ public interface GXml.DomDocument : GLib.Object,
* No implemented jet. This can lead to API changes in future versions.
*/
public abstract DomTreeWalker create_tree_walker (DomNode root, int what_to_show = (int) 0xFFFFFFFF,
DomNodeFilter? filter = null);
+
+
+ /**
+ * Writes a dump XML representation of document to a file.
+ */
+ public virtual void write_file (GLib.File file) throws GLib.Error {}
+ /**
+ * Writes asynchronically a dump XML representation of document to a file.
+ */
+ public virtual async void write_file_async (GLib.File file,
+ Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Writes a dump XML representation of document to a stream.
+ */
+ public virtual void write_stream (GLib.OutputStream stream) throws GLib.Error {}
+ /**
+ * Writes a dump XML representation of document to a stream.
+ */
+ public virtual async void write_stream_async (GLib.OutputStream stream,
+ Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Creates an {@link GLib.InputStream} to write a string representation
+ * in XML of {@link GomDocument}
+ */
+ public virtual InputStream create_stream () throws GLib.Error {
+ return new MemoryInputStream ();
+ }
+ /**
+ * Creates an {@link GLib.InputStream} to write a string representation
+ * in XML of {@link GomDocument}
+ */
+ public virtual async InputStream create_stream_async (Cancellable? cancellable = null) throws GLib.Error {
+ return new MemoryInputStream ();
+ }
+ /**
+ * Serialize {@link GomDocument} to a string.
+ */
+ public virtual string write_string () throws GLib.Error { return ""; }
+ /**
+ * Serialize {@link GomDocument} to a string.
+ */
+ public virtual async string write_string_async (Cancellable? cancellable = null) throws GLib.Error {
return ""; }
+ /**
+ * Reads a file contents and parse it to document.
+ */
+ public virtual void read_from_file (GLib.File file) throws GLib.Error {}
+ /**
+ * Reads a file contents and parse it to document.
+ */
+ public virtual async void read_from_file_async (GLib.File file,
+ Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Reads a string and parse it to document.
+ */
+ public virtual void read_from_string (string str) throws GLib.Error {}
+ /**
+ * Reads a string and parse it to document.
+ */
+ public virtual async void read_from_string_async (string str,
+ Cancellable? cancellable = null) throws GLib.Error {}
}
public interface GXml.DomXMLDocument : GLib.Object, GXml.DomDocument {}
diff --git a/gxml/DomElement.vala b/gxml/DomElement.vala
index 975aa1e..6d80dfc 100644
--- a/gxml/DomElement.vala
+++ b/gxml/DomElement.vala
@@ -73,6 +73,93 @@ public interface GXml.DomElement : GLib.Object,
parser.parse (selectors);
return parser.match (this);
}
+ /**
+ * Parsing a URI file.
+ */
+ public virtual void read_from_uri (string uri) throws GLib.Error {
+ this.read_from_file (File.new_for_uri (uri));
+ }
+ /**
+ * Parsing asinchronically a URI file.
+ */
+ public async virtual void read_from_uri_async (string uri, Cancellable? cancellable = null) throws
GLib.Error {
+ yield this.read_from_file_async (File.new_for_uri (uri));
+ }
+ /**
+ * Parses an XML file, deserializing it over {@link GomElement}.
+ */
+ public virtual void read_from_file (GLib.File f,
+ GLib.Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Parses asinchronically an XML file, deserializing it over {@link GomElement}.
+ */
+ public virtual async void read_from_file_async (GLib.File f,
+ GLib.Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Parses an XML over a {@link GLib.InputStream}, deserializing it over {@link GomElement}.
+ */
+ public virtual void read_from_stream (GLib.InputStream istream,
+ GLib.Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Parses asynchronically an XML over a {@link GLib.InputStream}, deserializing it over {@link GomElement}.
+ */
+ public virtual async void read_from_stream_async (GLib.InputStream istream,
+ GLib.Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Parses an XML string, deserializing it over {@link GomElement}.
+ */
+ public virtual void read_from_string (string str) throws GLib.Error {}
+ /**
+ * Parses an XML string, deserializing it over {@link GomElement}.
+ */
+ public virtual async void read_from_string_async (string str,
+ Cancellable? cancellable = null) throws GLib.Error {}
+ /**
+ * Serialize {@link GomElement} to a string.
+ */
+ public virtual string write_string () throws GLib.Error { return ""; }
+ /**
+ * Serialize asinchronically {@link GomElement} to a string.
+ */
+ public virtual async string write_string_async (Cancellable? cancellable = null) throws GLib.Error {
return ""; }
+ /**
+ * Uses element's {@link GomDocument} to write an XML to a file, serializing it.
+ */
+ public virtual void write_file (GLib.File f) throws GLib.Error {
+ owner_document.write_file (f);
+ }
+ /**
+ * Uses element's {@link GomDocument} to write asynchronically an XML to a file, serializing it.
+ */
+ public virtual async void write_file_async (GLib.File f, Cancellable? cancellable = null) throws
GLib.Error {
+ yield this.owner_document.write_file_async (f);
+ }
+ /**
+ * Uses element's {@link GomDocument} to write an XML to a stream, serializing it.
+ */
+ public virtual void write_stream (GLib.OutputStream stream) throws GLib.Error {
+ owner_document.write_stream (stream);
+ }
+ /**
+ * Uses element's {@link GomDocument} to write an XML to a stream, serializing it.
+ */
+ public virtual async void write_stream_async (GLib.OutputStream stream, Cancellable? cancellable = null)
throws GLib.Error {
+ yield this.owner_document.write_stream_async (stream);
+ }
+ /**
+ * Creates an {@link GLib.InputStream} to write a string representation
+ * in XML of {@link GomElement} using node's {@link GomDocument}
+ */
+ public virtual InputStream create_stream () throws GLib.Error {
+ return this.owner_document.create_stream ();
+ }
+ /**
+ * Creates an {@link GLib.InputStream} to write a string representation
+ * in XML of {@link GomElement} using node's {@link GomDocument}
+ */
+ public virtual async InputStream create_stream_async (Cancellable? cancellable = null) throws GLib.Error {
+ return yield this.owner_document.create_stream_async ();
+ }
}
public class GXml.DomElementList : Gee.ArrayList<DomElement>, GXml.DomHTMLCollection {
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index dc90a7a..fb46a57 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -121,7 +121,7 @@ public class GXml.GomDocument : GomNode,
/**
* Writes asynchronically a dump XML representation of document to a file.
*/
- public async void write_file_async (GLib.File file) throws GLib.Error {
+ public async void write_file_async (GLib.File file, Cancellable? cancellable = null) throws GLib.Error {
var parser = new XParser (this);
yield parser.write_file_async (file, null);
}
@@ -135,7 +135,7 @@ public class GXml.GomDocument : GomNode,
/**
* Writes a dump XML representation of document to a stream.
*/
- public async void write_stream_async (GLib.OutputStream stream) throws GLib.Error {
+ public async void write_stream_async (GLib.OutputStream stream, Cancellable? cancellable = null) throws
GLib.Error {
var parser = new XParser (this);
parser.write_stream (stream, null);
}
@@ -151,7 +151,7 @@ public class GXml.GomDocument : GomNode,
* Creates an {@link GLib.InputStream} to write a string representation
* in XML of {@link GomDocument}
*/
- public async InputStream create_stream_async () throws GLib.Error {
+ public async InputStream create_stream_async (Cancellable? cancellable = null) throws GLib.Error {
var parser = new XParser (this);
return yield parser.create_stream_async (null);
}
@@ -165,7 +165,7 @@ public class GXml.GomDocument : GomNode,
/**
* Serialize {@link GomDocument} to a string.
*/
- public async string write_string_async () throws GLib.Error {
+ public async string write_string_async (Cancellable? cancellable = null) throws GLib.Error {
var parser = new XParser (this);
return yield parser.write_string_async ();
}
@@ -179,7 +179,7 @@ public class GXml.GomDocument : GomNode,
/**
* Reads a file contents and parse it to document.
*/
- public async void read_from_file_async (GLib.File file) throws GLib.Error {
+ public async void read_from_file_async (GLib.File file, Cancellable? cancellable = null) throws GLib.Error
{
var parser = new XParser (this);
yield parser.read_file_async (file, null);
}
@@ -193,7 +193,7 @@ public class GXml.GomDocument : GomNode,
/**
* Reads a string and parse it to document.
*/
- public async void read_from_string_async (string str) throws GLib.Error {
+ public async void read_from_string_async (string str, Cancellable? cancellable = null) throws GLib.Error {
var parser = new XParser (this);
yield parser.read_string_async (str, null);
}
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 9605d1a..f2f57a3 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -48,18 +48,6 @@ public class GXml.GomElement : GomNode,
*/
protected Attributes _attributes;
// Convenient Serialization methods
- /**
- * Parsing a URI file.
- */
- public void read_from_uri (string uri) throws GLib.Error {
- this.read_from_file (File.new_for_uri (uri));
- }
- /**
- * Parsing asinchronically a URI file.
- */
- public async void read_from_uri_async (string uri) throws GLib.Error {
- yield this.read_from_file_async (File.new_for_uri (uri));
- }
/**
* Parses an XML file, deserializing it over {@link GomElement}.
*/
@@ -102,7 +90,7 @@ public class GXml.GomElement : GomNode,
/**
* Parses an XML string, deserializing it over {@link GomElement}.
*/
- public async void read_from_string_async (string str) throws GLib.Error {
+ public async void read_from_string_async (string str, Cancellable? cancellable = null) throws GLib.Error {
var parser = new XParser (this);
yield parser.read_string_async (str, null);
}
@@ -116,7 +104,7 @@ public class GXml.GomElement : GomNode,
/**
* Serialize asinchronically {@link GomElement} to a string.
*/
- public async string write_string_async () throws GLib.Error {
+ public async string write_string_async (Cancellable? cancellable = null) throws GLib.Error {
var parser = new XParser (this);
return yield parser.write_string_async ();
}
@@ -129,7 +117,7 @@ public class GXml.GomElement : GomNode,
/**
* Uses element's {@link GomDocument} to write asynchronically an XML to a file, serializing it.
*/
- public async void write_file_async (GLib.File f) throws GLib.Error {
+ public async void write_file_async (GLib.File f, Cancellable? cancellable = null) throws GLib.Error {
yield (this.owner_document as GomDocument).write_file_async (f);
}
/**
@@ -141,7 +129,7 @@ public class GXml.GomElement : GomNode,
/**
* Uses element's {@link GomDocument} to write an XML to a stream, serializing it.
*/
- public async void write_stream_async (GLib.OutputStream stream) throws GLib.Error {
+ public async void write_stream_async (GLib.OutputStream stream, Cancellable? cancellable = null) throws
GLib.Error {
yield (this.owner_document as GomDocument).write_stream_async (stream);
}
/**
@@ -155,7 +143,7 @@ public class GXml.GomElement : GomNode,
* Creates an {@link GLib.InputStream} to write a string representation
* in XML of {@link GomElement} using node's {@link GomDocument}
*/
- public async InputStream create_stream_async () throws GLib.Error {
+ public async InputStream create_stream_async (Cancellable? cancellable = null) throws GLib.Error {
return yield (this.owner_document as GomDocument).create_stream_async ();
}
// DomNode overrides
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]