[gxml] Renamed HtmlDocument to GHtmlDocument



commit d7318fdc439224cb652ac3528fb1481b16ba172b
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Sep 4 10:44:24 2017 -0500

    Renamed HtmlDocument to GHtmlDocument
    
    Added new DomHtmlDocument interface for
    future HTML documents handling using different
    backend, other than libmxl2.

 gxml/DomHtml.vala                                  |   40 ++++++++++++++++++++
 gxml/GHtml.vala                                    |   31 +++++++++------
 gxml/GXmlDocument.vala                             |    2 +-
 gxml/GomDocument.vala                              |    2 +-
 gxml/Html.vala                                     |   40 ++++++++++++++++++++
 gxml/Makefile.am                                   |    1 +
 ...tmlDocumentTest.vala => GHtmlDocumentTest.vala} |   18 ++++----
 test/GXmlTest.vala                                 |    2 +-
 test/Makefile.am                                   |    2 +-
 9 files changed, 112 insertions(+), 26 deletions(-)
---
diff --git a/gxml/DomHtml.vala b/gxml/DomHtml.vala
new file mode 100644
index 0000000..4127c4e
--- /dev/null
+++ b/gxml/DomHtml.vala
@@ -0,0 +1,40 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
+/* Html.vala
+ *
+ * Copyright (C) 2017  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:
+ *      Yannick Inizan <inizan yannick gmail com>
+ *      Daniel Espinosa <esodan gmail com>
+ */
+
+/**
+ * Interface for HTML handling implementation
+ */
+public interface GXml.DomHtmlDocument : Object, GXml.DomDocument {
+       /**
+        * This method reads HTML documents using default parser
+        */
+       public abstract void read_from_string (string str) throws GLib.Error;
+       /**
+        * This method reads HTML documents using default a very tolerant parser
+        */
+       public abstract void read_from_string_tolerant (string str) throws GLib.Error;
+       /**
+        * This method dump to HTML string.
+        */
+       public abstract string to_html () throws GLib.Error;
+}
diff --git a/gxml/GHtml.vala b/gxml/GHtml.vala
index f41fc24..67178ed 100644
--- a/gxml/GHtml.vala
+++ b/gxml/GHtml.vala
@@ -29,18 +29,18 @@ namespace GXml {
        /**
    * HML parsing suport. Document handling
    */
-       public class HtmlDocument : GXml.GDocument {
+       public class GHtmlDocument : GXml.GDocument, GXml.DomHtmlDocument {
                public static int default_options {
                        get {
                                return Html.ParserOption.NONET | Html.ParserOption.NOWARNING | 
Html.ParserOption.NOERROR | Html.ParserOption.NOBLANKS;
                        }
                }
                
-               public HtmlDocument.from_path (string path, int options = 0) throws GLib.Error {
+               public GHtmlDocument.from_path (string path, int options = 0) throws GLib.Error {
                        this.from_file (File.new_for_path (path), options);
                }
                
-               public HtmlDocument.from_uri (string uri, int options = 0) throws GLib.Error {
+               public GHtmlDocument.from_uri (string uri, int options = 0) throws GLib.Error {
                        this.from_file (File.new_for_uri (uri), options);
                }
                
@@ -49,10 +49,10 @@ namespace GXml {
                 * Refer to libxml2 documentation about limitations on parsing.
                 *
                 * In order to use a different parser, may you want to load in memory your file,
-                * then create a new {@link HtmlDocument} using a constructor better fitting
+                * then create a new {@link GHtmlDocument} using a constructor better fitting
                 * your document content or source.
                 */
-               public HtmlDocument.from_file (File file, int options = 0, Cancellable? cancel = null) throws 
GLib.Error {
+               public GHtmlDocument.from_file (File file, int options = 0, Cancellable? cancel = null) 
throws GLib.Error {
                        var ostream = new MemoryOutputStream.resizable ();
                        ostream.splice (file.read (), GLib.OutputStreamSpliceFlags.CLOSE_SOURCE, cancel);
                        this.from_string ((string) ostream.data, options);
@@ -61,14 +61,14 @@ namespace GXml {
                 * This method parse strings using {@link Html.Doc.read_memory} method.
                 * Refer to libxml2 documentation about limitations on parsing.
                 */
-               public HtmlDocument.from_string (string html, int options = 0) {
+               public GHtmlDocument.from_string (string html, int options = 0) {
                        base.from_doc (Html.Doc.read_memory ((char[]) html, html.length, "", null, options));
                }
                /**
                 * This method parse strings using {@link Html.ParserCtxt} class.
                 * Refer to libxml2 documentation about limitations on parsing.
                 */
-               public HtmlDocument.from_string_context (string html, int options = 0) {
+               public GHtmlDocument.from_string_context (string html, int options = 0) {
                        Html.ParserCtxt ctx = new Html.ParserCtxt ();
                        Xml.Doc *doc = ctx.read_memory ((char[]) html, html.length, "", null, options);
                        base.from_doc (doc);
@@ -77,14 +77,19 @@ namespace GXml {
                 * This method parse strings using {@link Html.Doc.read_doc} method.
                 * Refer to libxml2 documentation about limitations on parsing.
                 */
-               public HtmlDocument.from_string_doc (string html, int options = 0) {
+               public GHtmlDocument.from_string_doc (string html, int options = 0) {
                        base.from_doc (Html.Doc.read_doc (html, "", null, options));
                }
-               /**
-                * This method dump to HTML string using {@link Html.Doc.dump_memory} method.
-                * Refer to libxml2 documentation about output.
-                */
-               public new string to_html () {
+               // DomHtmlDocument implementation
+               public void read_from_string (string str) {
+                       this.doc = Html.Doc.read_memory ((char[]) str, str.length, "", null, 0);
+               }
+
+               public void read_from_string_tolerant (string str) throws GLib.Error {
+                       Html.ParserCtxt ctx = new Html.ParserCtxt ();
+                       this.doc = ctx.read_memory ((char[]) str, str.length, "", null, 0);
+               }
+               public string to_html () throws GLib.Error {
                        string buffer;
                        int len = 0;
                        ((Html.Doc*) doc)->dump_memory (out buffer, out len);
diff --git a/gxml/GXmlDocument.vala b/gxml/GXmlDocument.vala
index 586f0f1..534e53c 100644
--- a/gxml/GXmlDocument.vala
+++ b/gxml/GXmlDocument.vala
@@ -387,7 +387,7 @@ public class GXml.GImplementation : GLib.Object, GXml.DomImplementation {
                                          throws GLib.Error
   { return new GDocument (); } // FIXME
   public Document create_html_document (string title) {
-    return new HtmlDocument (); // FIXME:
+    return new GHtmlDocument (); // FIXME:
   }
 }
 
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 5581917..007d3d6 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -382,7 +382,7 @@ public class GXml.GomImplementation : GLib.Object, GXml.DomImplementation {
     return d as DomXMLDocument;
   } // FIXME
   public Document create_html_document (string title) {
-    return new HtmlDocument (); // FIXME:
+    return new GHtmlDocument (); // FIXME:
   }
 }
 
diff --git a/gxml/Html.vala b/gxml/Html.vala
new file mode 100644
index 0000000..32c45d1
--- /dev/null
+++ b/gxml/Html.vala
@@ -0,0 +1,40 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
+/* Html.vala
+ *
+ * Copyright (C) 2017  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:
+ *      Yannick Inizan <inizan yannick gmail com>
+ *      Daniel Espinosa <esodan gmail com>
+ */
+
+/**
+ * Interface for HTML handling implementation
+ */
+public interface DomHtmlDocument : Object, GXml.DomDocument {
+       /**
+        * This method reads HTML documents using default parser
+        */
+       public abstract void read_from_string (string str) throws GLib.Error;
+       /**
+        * This method reads HTML documents using default a very tolerant parser
+        */
+       public abstract void read_from_string_tolerant (string str) throws GLib.Error;
+       /**
+        * This method dump to HTML string.
+        */
+       public abstract void to_html () throws GLib.Error;
+}
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index c64c768..5f6e2e1 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -77,6 +77,7 @@ sources = \
        DomDocument.vala \
        DomElement.vala \
        DomEvents.vala \
+       DomHtml.vala \
        DomMutationObservers.vala \
        DomNode.vala \
        DomRange.vala \
diff --git a/test/HtmlDocumentTest.vala b/test/GHtmlDocumentTest.vala
similarity index 84%
rename from test/HtmlDocumentTest.vala
rename to test/GHtmlDocumentTest.vala
index d35f415..70b6f59 100644
--- a/test/HtmlDocumentTest.vala
+++ b/test/GHtmlDocumentTest.vala
@@ -24,11 +24,11 @@
 
 using GXml;
 
-class HtmlDocumentTest : GXmlTest {
+class GHtmlDocumentTest : GXmlTest {
        public static void add_tests () {
-               Test.add_func ("/gxml/htmldocument/api/element_id", () => {
+               Test.add_func ("/gxml/GHtmlDocument/api/element_id", () => {
                        try {
-                               var doc = new HtmlDocument.from_path (GXmlTestConfig.TEST_DIR+"/index.html");
+                               var doc = new GHtmlDocument.from_path (GXmlTestConfig.TEST_DIR+"/index.html");
                                Test.message ("Checking root element...");
                                assert (doc.root != null);
                                assert (doc.root.name.down () == "html".down ());
@@ -43,9 +43,9 @@ class HtmlDocumentTest : GXmlTest {
                                assert_not_reached ();
                        }
                });
-               Test.add_func ("/gxml/htmldocument/api/element_class", () => {
+               Test.add_func ("/gxml/GHtmlDocument/api/element_class", () => {
                        try {
-                               var doc = new HtmlDocument.from_path (GXmlTestConfig.TEST_DIR+"/index.html");
+                               var doc = new GHtmlDocument.from_path (GXmlTestConfig.TEST_DIR+"/index.html");
                                Test.message ("Checking root element...");
                                assert (doc.root != null);
                                assert (doc.root.name.down () == "html".down ());
@@ -70,7 +70,7 @@ class HtmlDocumentTest : GXmlTest {
                                assert_not_reached ();
                        }
                });
-               Test.add_func ("/gxml/htmldocument/fom_string_doc", () => {
+               Test.add_func ("/gxml/GHtmlDocument/fom_string_doc", () => {
                                var sdoc = "<!doctype html>
 <html>
 <head>
@@ -84,7 +84,7 @@ class HtmlDocumentTest : GXmlTest {
 </body>
 </html>
 ";
-                               var doc = new HtmlDocument.from_string_doc (sdoc);
+                               var doc = new GHtmlDocument.from_string_doc (sdoc);
                                assert (doc.root != null);
                                assert (doc.root.name.down () == "html".down ());
                                var ln = doc.root.get_elements_by_property_value ("type","text/javascript");
@@ -106,11 +106,11 @@ class HtmlDocumentTest : GXmlTest {
                                message (s);
                                assert ("style>\n  * { color: red; }\n  </style>" in s);
                });
-               // Test.add_func ("/gxml/htmldocument/uri", () => {
+               // Test.add_func ("/gxml/GHtmlDocument/uri", () => {
                //      try {
                //              var f = GLib.File.new_for_uri 
("http://www.omgubuntu.co.uk/2017/05/kde-neon-5-10-available-download-comes-plasma-5-10";);
                //              DomDocument doc;
-               //              doc = new HtmlDocument.from_uri 
("http://www.omgubuntu.co.uk/2017/05/kde-neon-5-10-available-download-comes-plasma-5-10";);
+               //              doc = new GHtmlDocument.from_uri 
("http://www.omgubuntu.co.uk/2017/05/kde-neon-5-10-available-download-comes-plasma-5-10";);
                //              message ((doc as GDocument).to_string ());
                //      } catch (GLib.Error e){
                //              message ("ERROR: "+e.message);
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index c1c81f3..9efba8b 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -58,7 +58,7 @@ class GXmlTest {
                GDocumentTest.add_tests ();
                GElementTest.add_tests ();
                GAttributeTest.add_tests ();
-               HtmlDocumentTest.add_tests ();
+               GHtmlDocumentTest.add_tests ();
                DomGDocumentTest.add_tests ();
                XPathTest.add_tests ();
                GomDocumentTest.add_tests ();
diff --git a/test/Makefile.am b/test/Makefile.am
index 05d68dd..c2067b1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -55,7 +55,7 @@ sources = \
        GDocumentTest.vala \
        GElementTest.vala \
        GAttributeTest.vala \
-       HtmlDocumentTest.vala \
+       GHtmlDocumentTest.vala \
        DomGDocumentTest.vala \
        XPathTest.vala \
        GomDocumentTest.vala \


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