[gxml] Added missing files to repository
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Added missing files to repository
- Date: Wed, 15 Apr 2015 21:51:18 +0000 (UTC)
commit 6809728e0823be1f8743f0a69f5699ee71ab065b
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Apr 15 11:11:39 2015 -0500
Added missing files to repository
gxml/libxml-ChildNodeList.vala | 233 ++++++++++++++++++++++++++++++++
gxml/libxml-NamespaceAttrNodeList.vala | 30 ++++
gxml/libxml-TagNamedList.vala | 36 +++++
3 files changed, 299 insertions(+), 0 deletions(-)
---
diff --git a/gxml/libxml-ChildNodeList.vala b/gxml/libxml-ChildNodeList.vala
new file mode 100644
index 0000000..50278a9
--- /dev/null
+++ b/gxml/libxml-ChildNodeList.vala
@@ -0,0 +1,233 @@
+/* .vala
+ *
+ * Copyright (C) 2015 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Richard Schwarting <aquarichy gmail com>
+ * Daniel Espinosa <esodan gmail com>
+ */
+
+using Gee;
+
+internal abstract class GXml.ChildNodeList : Gee.AbstractCollection<GXml.xNode>, NodeList
+{
+ /* TODO: must be live
+ if this reflects children of a node, then must always be current
+ same with nodes from GetElementByTagName, made need separate impls for each */
+ // TODO: if necessary, create two versions that use parent instead of head
+
+ internal weak xDocument owner;
+ internal abstract Xml.Node *head { get; set; }
+
+ internal abstract Xml.Node *parent_as_xmlnode { get; }
+
+ /**
+ * { inheritDoc}
+ */
+ public ulong length {
+ get {
+ return size;
+ }
+ protected set { }
+ }
+
+ public override bool add (xNode item)
+ {
+ append_child (item);
+ return true;
+ }
+ public override void clear () {}
+ public override bool contains (xNode item) { return false; }
+ public override bool remove (xNode item) { return false; }
+ public override bool read_only { get { return true; } }
+ public override int size {
+ get {
+ if (head != null) {
+ //GLib.warning ("At NodeChildNodeList: get_size");
+ int len = 1;
+ var cur = head;
+ while (cur->next != null) {
+ cur = cur->next;
+ len++;
+ }
+ return len;
+ }
+ return 0;
+ }
+ }
+ public override Gee.Iterator<xNode> iterator () {
+ return new NodeListIterator (this);
+ }
+ public override bool @foreach (ForallFunc<xNode> func) {
+ return iterator ().foreach (func);
+ }
+
+ /** GNOME List conventions */
+ public xNode first () {
+ return this.owner.lookup_node (head);
+ }
+ public xNode last () {
+ Xml.Node *cur = head;
+ while (cur != null && cur->next != null) {
+ cur = cur->next;
+ }
+ return this.owner.lookup_node (cur); // TODO :check for nulls?
+ }
+ public new xNode @get (int n)
+ requires (head != null)
+ {
+ Xml.Node *cur = head;
+ int i = 0;
+ while (cur->next != null && i != n) {
+ cur = cur->next;
+ i++;
+ }
+ return this.owner.lookup_node (cur);
+ }
+ public xNode item (ulong idx) { return get ((int) idx); }
+
+ /** Node's child methods, implemented here **/
+ internal new unowned xNode? insert_before (xNode new_child, xNode? ref_child) {
+ Xml.Node *child = head;
+
+ if (ref_child == null) {
+ this.append_child (ref_child);
+ }
+
+ while (child != ((BackedNode)ref_child).node && child != null) {
+ child = child->next;
+ }
+ if (child == null) {
+ GXml.warning (DomException.NOT_FOUND, "ref_child '%s' not found, was supposed
to have '%s' inserted before it.".printf (ref_child.node_name, new_child.node_name));
+ return null;
+ // TODO: provide a more useful description of ref_child, but there are so
many different types
+ } else {
+ if (new_child.node_type == NodeType.DOCUMENT_FRAGMENT) {
+ foreach (xNode new_grand_child in new_child.child_nodes) {
+ child->add_prev_sibling (((BackedNode)new_grand_child).node);
+ }
+ } else {
+ child->add_prev_sibling (((BackedNode)new_child).node);
+ }
+ }
+ return new_child;
+ }
+
+ internal new unowned xNode? replace_child (xNode new_child, xNode old_child) {
+ // TODO: verify that libxml2 already removes
+ // new_child first if it is found elsewhere in
+ // the tree.
+
+ // TODO: nuts, if Node as an iface can't have properties,
+ // then I have to cast these to Nodes, ugh.
+ // TODO: need to handle errors?
+
+ // TODO: want to do a 'find_child' function
+ if (new_child.node_type == NodeType.DOCUMENT_FRAGMENT) {
+ this.insert_before (new_child, old_child);
+ this.remove_child (old_child);
+ } else {
+ Xml.Node *child = head;
+
+ while (child != null && child != ((BackedNode)old_child).node) {
+ child = child->next;
+ }
+
+ if (child != null) {
+ // it is a valid child
+ child->replace (((BackedNode)new_child).node);
+ } else {
+ GXml.warning (DomException.NOT_FOUND, "old_child '%s' not found,
tried to replace with '%s'".printf (old_child.node_name, new_child.node_name));
+ }
+ }
+
+ return old_child;
+ }
+ internal new unowned xNode? remove_child (xNode old_child) /* throws DomError */ {
+ // TODO: verify that old_child is a valid child here and then unlink
+
+ ((BackedNode)old_child).node->unlink (); // TODO: do we need to free libxml2 stuff
manually?
+ return old_child;
+ }
+
+ internal virtual unowned xNode? append_child (xNode new_child) /* throws DomError */ {
+ // TODO: verify that libxml2 will first remove
+ // new_child if it already exists elsewhere in
+ // the tree.
+
+ if (new_child.node_type == NodeType.DOCUMENT_FRAGMENT) {
+ foreach (xNode grand_child in new_child.child_nodes) {
+ parent_as_xmlnode->add_child (((BackedNode)grand_child).node);
+ }
+ } else {
+ if (new_child.node_type == NodeType.ENTITY_REFERENCE) {
+ GLib.warning ("Appending EntityReferences to Nodes is not yet
supported");
+ } else {
+ parent_as_xmlnode->add_child (((BackedNode)new_child).node);
+ }
+ }
+
+ return new_child;
+ }
+
+ public string to_string (bool in_line = true) {
+ string str = "";
+ foreach (xNode node in this) {
+ str += node.to_string ();
+ }
+ return str;
+ }
+
+ /* ** NodeListIterator ***/
+
+ private class NodeListIterator : GLib.Object, Gee.Traversable<xNode>, Gee.Iterator<xNode>
+ {
+ private weak xDocument doc;
+ private Xml.Node *cur;
+ private Xml.Node *head;
+
+ /* TODO: consider rewriting this to work on NodeList instead of the Xml.Node*
+ list, then perhaps we could reuse it for get_elements_by_tag_name () */
+ public NodeListIterator (ChildNodeList list) {
+ this.head = list.head;
+ this.cur = null;
+ this.doc = list.owner;
+ }
+ /* Gee.Iterator interface */
+ public new xNode @get () { return this.doc.lookup_node (this.cur); }
+ public bool has_next () { return head == null ? false : true; }
+ public bool next () {
+ if (has_next ()) {
+ cur = head;
+ head = head->next;
+ return true;
+ }
+ return false;
+ }
+ public void remove () {}
+ public bool read_only { get { return true; } }
+ public bool valid { get { return cur != null ? true : false; } }
+
+ /* Traversable interface */
+ public new bool @foreach (Gee.ForallFunc<xNode> f)
+ {
+ if (next ())
+ return f (get ());
+ return false;
+ }
+ }
+ }
diff --git a/gxml/libxml-NamespaceAttrNodeList.vala b/gxml/libxml-NamespaceAttrNodeList.vala
new file mode 100644
index 0000000..f3ad2cb
--- /dev/null
+++ b/gxml/libxml-NamespaceAttrNodeList.vala
@@ -0,0 +1,30 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 0; tab-width: 2 -*- */
+/* ObjectModel.vala
+ *
+ * Copyright (C) 2015 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+
+internal class GXml.NamespaceAttrNodeList : GXml.LinkedList {
+ internal NamespaceAttrNodeList (BackedNode root, xDocument owner) {
+ base (root);
+ for (Xml.Ns *cur = root.node->ns_def; cur != null; cur = cur->next) {
+ this.append_child (new NamespaceAttr (cur, owner));
+ }
+ }
+}
diff --git a/gxml/libxml-TagNamedList.vala b/gxml/libxml-TagNamedList.vala
new file mode 100644
index 0000000..bb93f35
--- /dev/null
+++ b/gxml/libxml-TagNamedList.vala
@@ -0,0 +1,36 @@
+/* NodeList.vala
+ *
+ * Copyright (C) 2011-2013 Richard Schwarting <aquarichy gmail com>
+ * Copyright (C) 2013-2015 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Richard Schwarting <aquarichy gmail com>
+ * Daniel Espinosa <esodan gmail com>
+ */
+
+
+/* TODO: this will somehow need to watch the document and find
+ * out as new elements are added, and get reconstructed each
+ * time, or get reconstructed-on-the-go?
+ */
+internal class GXml.TagNameNodeList : GXml.LinkedList {
+ internal string tag_name;
+ internal TagNameNodeList (string tag_name, xNode root, xDocument owner) {
+ base (root);
+ this.tag_name = tag_name;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]