[libgrss] Added XBEL files parser
- From: Roberto Guido <rguido src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgrss] Added XBEL files parser
- Date: Wed, 26 May 2010 01:38:57 +0000 (UTC)
commit 894d3c2f9dcf6fea85a5c5f747cabcfdc35f822e
Author: Roberto Guido <bob4mail gmail com>
Date: Wed May 26 03:41:14 2010 +0200
Added XBEL files parser
NEWS | 1 +
TODO | 1 -
src/Makefile.am | 2 +
src/feeds-group.c | 4 +
src/feeds-opml-group-handler.c | 7 --
src/feeds-xbel-group-handler.c | 159 ++++++++++++++++++++++++++++++++++++++++
src/feeds-xbel-group-handler.h | 49 ++++++++++++
src/feeds-xoxo-group-handler.c | 11 +--
src/utils.c | 10 +--
9 files changed, 220 insertions(+), 24 deletions(-)
---
diff --git a/NEWS b/NEWS
index 86674a2..40d0ddb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
libgrss 0.5 (UNRELEASED)
==============================================================================
- Added XOXO files parser
+- Added XBEL files parser
- Added functions feed_channel_fetch_async() and feed_channel_new_from_file()
libgrss 0.4
diff --git a/TODO b/TODO
index a3f25bd..40cec78 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
- dynamic loading for parsing modules
- add RSSCloud support (http://rsscloud.org)
-- add XBEL parser (http://pyxml.sourceforge.net/topics/xbel/)
- namespace OpenSearch (http://a9.com/-/spec/opensearchrss/1.0/)
diff --git a/src/Makefile.am b/src/Makefile.am
index c4462ca..9495e76 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,7 @@ sources_private_h = \
feed-pie-handler.h \
feeds-group-handler.h \
feeds-opml-group-handler.h \
+ feeds-xbel-group-handler.h \
feeds-xoxo-group-handler.h \
ns-handler.h \
utils.h
@@ -48,6 +49,7 @@ sources_c = \
feeds-pool.c \
feeds-store.c \
feeds-subscriber.c \
+ feeds-xbel-group-handler.c \
feeds-xoxo-group-handler.c \
ns-handler.c \
utils.c
diff --git a/src/feeds-group.c b/src/feeds-group.c
index d2a7d03..5484c70 100644
--- a/src/feeds-group.c
+++ b/src/feeds-group.c
@@ -24,6 +24,7 @@
#include "feeds-opml-group-handler.h"
#include "feeds-xoxo-group-handler.h"
+#include "feeds-xbel-group-handler.h"
#define FEEDS_GROUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FEEDS_GROUP_TYPE, FeedsGroupPrivate))
@@ -92,6 +93,9 @@ feeds_groups_get_list (FeedsGroup *group)
parser = FEEDS_GROUP_HANDLER (feeds_xoxo_group_handler_new ());
group->priv->handlers = g_slist_append (group->priv->handlers, parser);
+
+ parser = FEEDS_GROUP_HANDLER (feeds_xbel_group_handler_new ());
+ group->priv->handlers = g_slist_append (group->priv->handlers, parser);
}
return group->priv->handlers;
diff --git a/src/feeds-opml-group-handler.c b/src/feeds-opml-group-handler.c
index 1d9b185..2fb5726 100644
--- a/src/feeds-opml-group-handler.c
+++ b/src/feeds-opml-group-handler.c
@@ -249,13 +249,6 @@ feeds_opml_group_handler_init (FeedsOpmlGroupHandler *object)
object->priv = FEEDS_OPML_GROUP_HANDLER_GET_PRIVATE (object);
}
-/**
- * feeds_opml_group_handler_new:
- *
- * Allocates a new #FeedsOpmlGroupHandler
- *
- * Return value: a new #FeedsOpmlGroupHandler
- */
FeedsOpmlGroupHandler*
feeds_opml_group_handler_new ()
{
diff --git a/src/feeds-xbel-group-handler.c b/src/feeds-xbel-group-handler.c
new file mode 100644
index 0000000..1e64f22
--- /dev/null
+++ b/src/feeds-xbel-group-handler.c
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2010, Roberto Guido <rguido src gnome org>
+ * Michele Tameni <michele amdplanet it>
+ *
+ * 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 3 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.
+ */
+
+#include "feeds-group-handler.h"
+#include "feeds-xbel-group-handler.h"
+#include "utils.h"
+#include "feed-channel.h"
+
+#define FEEDS_XBEL_GROUP_HANDLER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FEEDS_XBEL_GROUP_HANDLER_TYPE, FeedsXbelGroupHandlerPrivate))
+
+/**
+ * SECTION: feeds-xbel-group-handler
+ * @short_description: specialized parser for XBEL files
+ *
+ * #FeedsXbelGroupHandler is a #FeedsGroupHandler specialized for XBEL contents
+ */
+
+struct FeedsXbelGroupHandlerPrivate {
+ int rfu;
+};
+
+static void feeds_group_handler_interface_init (FeedsGroupHandlerInterface *iface);
+G_DEFINE_TYPE_WITH_CODE (FeedsXbelGroupHandler, feeds_xbel_group_handler, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (FEEDS_GROUP_HANDLER_TYPE,
+ feeds_group_handler_interface_init));
+
+static void
+feeds_xbel_group_handler_finalize (GObject *object)
+{
+ FeedsXbelGroupHandler *parser;
+
+ parser = FEEDS_XBEL_GROUP_HANDLER (object);
+ G_OBJECT_CLASS (feeds_xbel_group_handler_parent_class)->finalize (object);
+}
+
+static gboolean
+feeds_xbel_group_handler_check_format (FeedsGroupHandler *self, xmlDocPtr doc, xmlNodePtr cur)
+{
+ if (!xmlStrcmp (cur->name, BAD_CAST"xbel"))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static GList*
+feeds_xbel_group_handler_parse (FeedsGroupHandler *self, xmlDocPtr doc, GError **error)
+{
+ int i;
+ gchar *str;
+ xmlNodePtr cur;
+ xmlNodePtr subnode;
+ GList *items;
+ xmlXPathObjectPtr xpathObj;
+ xmlXPathContextPtr xpathCtx;
+ FeedChannel *channel;
+ FeedsXbelGroupHandler *parser;
+
+ items = NULL;
+ parser = FEEDS_XBEL_GROUP_HANDLER (self);
+
+ xpathCtx = xmlXPathNewContext (doc);
+
+ /**
+ TODO This XPath query may be improved to check only "bookmark" tags into the main "xbel"
+ */
+ xpathObj = xmlXPathEvalExpression (BAD_CAST"//bookmark", xpathCtx);
+
+ for (i = 0; i < xpathObj->nodesetval->nodeNr; ++i) {
+ cur = xpathObj->nodesetval->nodeTab [i];
+
+ if (cur->type == XML_ELEMENT_NODE) {
+ str = (gchar*) xmlGetProp (cur, BAD_CAST"href");
+
+ if (str != NULL && strlen (str) != 0) {
+ channel = feed_channel_new ();
+
+ feed_channel_set_source (channel, str);
+ xmlFree (str);
+
+ if (cur->children != NULL && strcmp ((gchar*) cur->children->name, "title") == 0) {
+ subnode = cur->children;
+ str = (gchar*) xmlNodeListGetString (doc, subnode->xmlChildrenNode, TRUE);
+ if (str != NULL) {
+ feed_channel_set_title (channel, str);
+ g_free (str);
+ }
+ }
+
+ items = g_list_prepend (items, channel);
+ }
+ }
+ }
+
+ xmlXPathFreeObject (xpathObj);
+ xmlXPathFreeContext (xpathCtx);
+
+ if (items != NULL)
+ items = g_list_reverse (items);
+ return items;
+}
+
+static gchar*
+feeds_xbel_group_handler_dump (FeedsGroupHandler *self, GList *channels, GError **error)
+{
+ /**
+ TODO
+ */
+
+ return NULL;
+}
+
+static void
+feeds_group_handler_interface_init (FeedsGroupHandlerInterface *iface)
+{
+ iface->check_format = feeds_xbel_group_handler_check_format;
+ iface->parse = feeds_xbel_group_handler_parse;
+ iface->dump = feeds_xbel_group_handler_dump;
+}
+
+static void
+feeds_xbel_group_handler_class_init (FeedsXbelGroupHandlerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (FeedsXbelGroupHandlerPrivate));
+ object_class->finalize = feeds_xbel_group_handler_finalize;
+}
+
+static void
+feeds_xbel_group_handler_init (FeedsXbelGroupHandler *object)
+{
+ object->priv = FEEDS_XBEL_GROUP_HANDLER_GET_PRIVATE (object);
+}
+
+FeedsXbelGroupHandler*
+feeds_xbel_group_handler_new ()
+{
+ FeedsXbelGroupHandler *parser;
+
+ parser = g_object_new (FEEDS_XBEL_GROUP_HANDLER_TYPE, NULL);
+ return parser;
+}
diff --git a/src/feeds-xbel-group-handler.h b/src/feeds-xbel-group-handler.h
new file mode 100644
index 0000000..34a4b65
--- /dev/null
+++ b/src/feeds-xbel-group-handler.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2010, Roberto Guido <rguido src gnome org>
+ * Michele Tameni <michele amdplanet it>
+ *
+ * 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 3 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.
+ */
+
+#ifndef __FEEDS_XBEL_GROUP_HANDLER_H__
+#define __FEEDS_XBEL_GROUP_HANDLER_H__
+
+#include "libgrss.h"
+
+#define FEEDS_XBEL_GROUP_HANDLER_TYPE (feeds_xbel_group_handler_get_type())
+#define FEEDS_XBEL_GROUP_HANDLER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), FEEDS_XBEL_GROUP_HANDLER_TYPE, FeedsXbelGroupHandler))
+#define FEEDS_XBEL_GROUP_HANDLER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), FEEDS_XBEL_GROUP_HANDLER_TYPE, FeedsXbelGroupHandlerClass))
+#define IS_FEEDS_XBEL_GROUP_HANDLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), FEEDS_XBEL_GROUP_HANDLER_TYPE))
+#define IS_FEEDS_XBEL_GROUP_HANDLER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), FEEDS_XBEL_GROUP_HANDLER_TYPE))
+#define FEEDS_XBEL_GROUP_HANDLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), FEEDS_XBEL_GROUP_HANDLER_TYPE, FeedsXbelGroupHandlerClass))
+
+typedef struct FeedsXbelGroupHandler FeedsXbelGroupHandler;
+typedef struct FeedsXbelGroupHandlerPrivate FeedsXbelGroupHandlerPrivate;
+
+struct FeedsXbelGroupHandler {
+ GObject parent;
+ FeedsXbelGroupHandlerPrivate *priv;
+};
+
+typedef struct {
+ GObjectClass parent;
+} FeedsXbelGroupHandlerClass;
+
+GType feeds_xbel_group_handler_get_type (void) G_GNUC_CONST;
+
+FeedsXbelGroupHandler* feeds_xbel_group_handler_new ();
+
+#endif /* __FEEDS_XBEL_GROUP_HANDLER_H__ */
diff --git a/src/feeds-xoxo-group-handler.c b/src/feeds-xoxo-group-handler.c
index 0ee92c2..5f7463c 100644
--- a/src/feeds-xoxo-group-handler.c
+++ b/src/feeds-xoxo-group-handler.c
@@ -93,6 +93,10 @@ feeds_xoxo_group_handler_parse (FeedsGroupHandler *self, xmlDocPtr doc, GError *
xpathCtx = xmlXPathNewContext (doc);
xmlXPathRegisterNs (xpathCtx, BAD_CAST"xhtml", BAD_CAST"http://www.w3.org/1999/xhtml");
+
+ /**
+ TODO This XPath query may be improved to check only "a" tags into the main "ol"
+ */
xpathObj = xmlXPathEvalExpression (BAD_CAST"//xhtml:a[ type='webfeed']", xpathCtx);
for (i = 0; i < xpathObj->nodesetval->nodeNr; ++i) {
@@ -159,13 +163,6 @@ feeds_xoxo_group_handler_init (FeedsXoxoGroupHandler *object)
object->priv = FEEDS_XOXO_GROUP_HANDLER_GET_PRIVATE (object);
}
-/**
- * feeds_xoxo_group_handler_new:
- *
- * Allocates a new #FeedsXoxoGroupHandler
- *
- * Return value: a new #FeedsXoxoGroupHandler
- */
FeedsXoxoGroupHandler*
feeds_xoxo_group_handler_new ()
{
diff --git a/src/utils.c b/src/utils.c
index 921858a..7d87c87 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -301,15 +301,7 @@ content_to_xml (const gchar *contents, gsize size)
xmlDocPtr
file_to_xml (const gchar *path)
{
- xmlParserCtxtPtr ctxt;
- xmlDocPtr doc;
-
- ctxt = xmlNewParserCtxt ();
- ctxt->sax->getEntity = xml_process_entities;
- doc = xmlSAXParseFile (ctxt->sax, path, 1);
- xmlFreeParserCtxt (ctxt);
-
- return doc;
+ return xmlReadFile (path, NULL, XML_PARSE_RECOVER | XML_PARSE_NOBLANKS);
}
/* in theory, we'd need only the RFC822 timezones here
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]