From cdc83984660dd198178090bb8367d3b2dab7b4f9 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Fri, 5 Jul 2019 14:06:22 -0500 Subject: [PATCH] Namespace: removed deprecated interface --- gxml/Namespace.vala | 49 ------------ gxml/XDocument.vala | 4 +- gxml/XElement.vala | 19 ++--- gxml/XListNamespaces.vala | 160 -------------------------------------- gxml/XNamespace.vala | 45 ----------- gxml/XPath.vala | 14 +++- gxml/meson.build | 3 - 7 files changed, 23 insertions(+), 271 deletions(-) delete mode 100644 gxml/Namespace.vala delete mode 100644 gxml/XListNamespaces.vala delete mode 100644 gxml/XNamespace.vala diff --git a/gxml/Namespace.vala b/gxml/Namespace.vala deleted file mode 100644 index e1af7d34..00000000 --- a/gxml/Namespace.vala +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 0; tab-width: 2 -*- */ -/* ObjectModel.vala - * - * Copyright (C) 2013, 2014 Daniel Espinosa - * - * 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 . - * - * Authors: - * Daniel Espinosa - */ - -using Gee; - -/** - * DOM1 Interface to handle XML Namespaces. - * - * Basic information for a XML document's namespaces and applied to a given - * {@link GXml.Node}. - * - * Namespace management is a matter of this or other libraries, implementing - * this interfaces. - */ -[Version (deprecated = true, deprecated_since = "0.18", replacement = "")] -public interface GXml.Namespace : Object -{ - /** - * Read-only property to get namespace's URI. - */ - public abstract string? uri { owned get; } - /** - * Read-only property to get namespace's prefix. - * - * Prefix should be added to {@link GXml.Element} or {@link GXml.Attribute} - * name in order to apply a given namespace, unless it is the default. - */ - public abstract string? prefix { owned get; } -} - diff --git a/gxml/XDocument.vala b/gxml/XDocument.vala index 623d845c..888970b1 100644 --- a/gxml/XDocument.vala +++ b/gxml/XDocument.vala @@ -358,8 +358,8 @@ public class GXml.XDocument : GXml.XNode, * {@link XPathContext} implementation. */ public GXml.XPathObject evaluate (string expression, - Gee.List? resolver = null) - throws GXml.XPathError + Gee.Map? resolver = null) + throws GXml.XPathObjectError { XPathObject nullobj = null; if (document_element == null) diff --git a/gxml/XElement.vala b/gxml/XElement.vala index b4da56c3..ff8ee19b 100644 --- a/gxml/XElement.vala +++ b/gxml/XElement.vala @@ -330,8 +330,8 @@ public class GXml.XElement : GXml.XNonDocumentChildNode, * {@inheritDoc} */ public GXml.XPathObject evaluate (string expression, - Gee.List? resolver = null) - throws GXml.XPathError + Gee.Map? resolver = null) + throws GXml.XPathObjectError { GXml.XPathObject nullobj = null; if (!(this is GXml.DomNode)) @@ -340,14 +340,15 @@ public class GXml.XElement : GXml.XNonDocumentChildNode, var ndoc = Xml.Parser.read_memory (data, data.length); var gdoc = new GXml.XDocument.from_doc (ndoc); var context = new Xml.XPath.Context (ndoc); - if (resolver != null) - resolver.foreach (ns => { - int res = context.register_ns (ns.prefix, ns.uri); - if (res != 0) { - GLib.warning (_("invalid namespace. Code: ")+res.to_string ()); + if (resolver != null) { + foreach (string prefix in resolver.keys) { + var uri = resolver.get (prefix); + int res = context.register_ns (prefix, uri); + if (res != 0) { + throw new XPathObjectError.INVALID_NAMESPACE_ERROR (_("invalid namespace. Code: %s"), res.to_string ()); + } } - return true; - }); + } return new GXml.LXPathObject (gdoc, context.eval (expression)); } } diff --git a/gxml/XListNamespaces.vala b/gxml/XListNamespaces.vala deleted file mode 100644 index b43b7931..00000000 --- a/gxml/XListNamespaces.vala +++ /dev/null @@ -1,160 +0,0 @@ -/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 0; tab-width: 2 -*- */ -/* GXmlListNamespaces.vala - * - * Copyright (C) 2015 Daniel Espinosa - * - * 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 . - * - * Authors: - * Daniel Espinosa - */ - -using Gee; - -/** - * A {@link Gee.AbstractList} implementation to access libxml2's {@link Xml.Ns} namespaces collection - */ -public class GXml.XListNamespaces : Gee.AbstractList -{ - private XDocument _doc; - private Xml.Node *_node; - public XListNamespaces (XDocument doc, Xml.Node *node) { - _node = node; - _doc = doc; - } - // List - public override new GXml.Namespace @get (int index) { - GXml.Namespace nullns = null; - if (_node == null) return nullns; - var ns = _node->ns_def; - int i = 0; - while (ns != null) { - if (i == index) { - return new XNamespace (ns); - } - ns = ns->next; - i++; - } - return nullns; - } - public override int index_of (GXml.Namespace item) { - if (_node == null) return -1; - if (!(item is XNamespace)) return -1; - var ns = _node->ns_def; - int i = 0; - while (ns != null) { - if (((XNamespace) item).get_internal_ns () == ns) return i; - ns = ns->next; - i++; - } - return -1; - } - public override void insert (int index, GXml.Namespace item) {} - public override Gee.ListIterator list_iterator () { return new Iterator (_node); } - public override GXml.Namespace remove_at (int index) { - GXml.Namespace nullns = null; - return nullns; - } - public override new void @set (int index, GXml.Namespace item) {} - public override Gee.List? slice (int start, int stop) { - var l = new ArrayList (); - if (_node == null) return l; - var ns = _node->ns_def; - int i = 0; - while (ns != null) { - if (i >= start && i <= stop) { - l.add (new XNamespace (ns)); - } - ns = ns->next; - i++; - } - return l; - } - // Collection - public override bool add (GXml.Namespace item) { - if (!(item is Namespace)) return false; - if (_node == null) return false; - return (_node->new_ns (((Namespace) item).uri, ((Namespace) item).prefix)) != null; - } - public override void clear () {} - public override bool contains (GXml.Namespace item) { - if (!(item is XNamespace)) return false; - if (_node == null) return false; - var ns = _node->ns_def; - while (ns != null) { - if (ns == ((XNamespace) item).get_internal_ns ()) return true; - } - return false; - } - public override Gee.Iterator iterator () { return new Iterator (_node); } - public override bool remove (GXml.Namespace item) { return false; } - public override bool read_only { get { return false; } } - public override int size { - get { - if (_node == null) return -1; - var ns = _node->ns_def; - int i = 0; - while (ns != null) { - i++; - ns = ns->next; - } - return i; - } - } - public class Iterator : Object, Gee.Traversable, Gee.Iterator, - Gee.ListIterator { - private Xml.Node *_node; - private Xml.Ns *_current; - private int i = -1; - public Iterator (Xml.Node *node) { - _node = node; - } - // ListIterator - public void add (GXml.Namespace item) { - if (_node == null) return; - if (!(item is GXml.Namespace)) return; - var ns = (GXml.Namespace) item; - _node->new_ns (ns.uri, ns.prefix); - } - public int index () { return i; } - public new void @set (GXml.Namespace item) {} - // Iterator - public new GXml.Namespace @get () { return new XNamespace (_current); } - public bool has_next () { - if (_node->ns_def == null) return false; - if (_current != null) - if (_current->next == null) return false; - return true; - } - public bool next () { - if (_node->ns_def == null) return false; - if (_current == null) - _current = _node->ns_def; - if (_current->next == null) return false; - _current = _current->next; - return true; - } - public void remove () {} - public bool read_only { get { return false; } } - public bool valid { get { return (_current != null); } } - // Traversable - public new bool @foreach (Gee.ForallFunc f) { - while (has_next ()) { - next (); - if (!f(@get())) return false; - } - return true; - } - } -} diff --git a/gxml/XNamespace.vala b/gxml/XNamespace.vala deleted file mode 100644 index cc63b91f..00000000 --- a/gxml/XNamespace.vala +++ /dev/null @@ -1,45 +0,0 @@ -/* GXmlNamespace.vala - * - * Copyright (C) 2016 Daniel Espinosa - * - * 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 . - * - * Authors: - * Daniel Espinosa - */ - -using Gee; - -/** - * Class implemeting {@link GXml.Namespace} - */ -public class GXml.XNamespace : Object, GXml.Namespace -{ - private Xml.Ns *_ns; - public XNamespace (Xml.Ns* ns) { _ns = ns; } - public Xml.Ns* get_internal_ns () { return _ns; } - // GXml.Namespace - public string? uri { - owned get { - if (_ns == null) return null; - return _ns->href.dup (); - } - } - public string? @prefix { - owned get { - if (_ns == null) return null; - return _ns->prefix.dup (); - } - } -} diff --git a/gxml/XPath.vala b/gxml/XPath.vala index 23d897c7..e95e15b6 100644 --- a/gxml/XPath.vala +++ b/gxml/XPath.vala @@ -71,14 +71,22 @@ public interface GXml.XPathContext : GLib.Object { /** * Evaluate XPath expression. * - * This method evaluates provided expression, registers provided namespaces in resolver and returns an {@link GXml.XPathObject}. + * This method evaluates provided expression, registers provided namespaces + * in resolver and returns an {@link GXml.XPathObject}. + * + * Resolver is a map where its key is the namespace's prefix and + * its value is the namespace's URI * * Throw {@link GXml.XPathError} if one of provided namespaces is invalid. */ public abstract GXml.XPathObject evaluate (string expression, - Gee.List? resolver = null) - throws GXml.XPathError; + Gee.Map? resolver = null) + throws GXml.XPathObjectError; + +} +public errordomain GXml.XPathObjectError { + INVALID_NAMESPACE_ERROR } public interface GXml.XPathObject : GLib.Object { diff --git a/gxml/meson.build b/gxml/meson.build index 52da5f84..ca3d78b7 100644 --- a/gxml/meson.build +++ b/gxml/meson.build @@ -68,7 +68,6 @@ valasources = files ([ 'gxml-init.vala', 'HTMLCollection.vala', 'LXPathObject.vala', - 'Namespace.vala', 'NodeType.vala', 'Parser.vala', 'SettableTokenList.vala', @@ -84,8 +83,6 @@ valasources = files ([ 'XHashMapAttr.vala', 'XHtmlDocument.vala', 'XListChildren.vala', - 'XListNamespaces.vala', - 'XNamespace.vala', 'XNode.vala', 'XParser.vala', 'XPath.vala', -- GitLab