Added support for category element
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 17 Dec 2008 01:29:44 +0000 (23:29 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 17 Dec 2008 01:35:03 +0000 (23:35 -0200)
A new object to represent an entry or feed category.

atom/Makefile.am
atom/category.c [new file with mode: 0644]
include/atompub/Makefile.am
include/atompub/atom-xml.h
include/atompub/atom.h
include/atompub/category-xml.h [new file with mode: 0644]
include/atompub/category.h [new file with mode: 0644]

index 0206273..166e8fc 100644 (file)
@@ -1,5 +1,5 @@
 lib_LTLIBRARIES = libatom.la
-libatom_la_SOURCES = id.c entry.c person.c feed.c \
+libatom_la_SOURCES = id.c entry.c person.c category.c feed.c \
                config.c ctx.c backend.c error.c frontend.c request.c \
                core.c
 libatom_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
diff --git a/atom/category.c b/atom/category.c
new file mode 100644 (file)
index 0000000..6b18679
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include <atompub/atom.h>
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+struct _atom_category
+{
+  char *term;
+  IRI *scheme;
+  char *label;
+};
+
+AtomCategory *
+atom_category_new (char *term)
+{
+  AtomCategory *category;
+  category = g_slice_new (AtomCategory);
+  category->term = g_strdup (term);
+  category->scheme = NULL;
+  category->label = NULL;
+  return category;
+}
+
+void
+atom_category_delete (AtomCategory *category)
+{
+  if (category->term)
+    g_free (category->term);
+  if (category->scheme)
+    iri_delete (category->scheme);
+  if (category->label)
+    g_free (category->label);
+  g_slice_free (AtomCategory, category);
+}
+
+char *
+atom_category_term (AtomCategory *category)
+{
+  return category->term;
+}
+
+void
+atom_category_term_set (AtomCategory *category, char *term)
+{
+  if (category->term)
+    g_free (category->term);
+  category->term = g_strdup (term);
+}
+
+IRI *
+atom_category_scheme (AtomCategory *category)
+{
+  return category->scheme;
+}
+
+void
+atom_category_scheme_set (AtomCategory *category, IRI *scheme)
+{
+  if (category->scheme)
+    iri_delete (category->scheme);
+  category->scheme = iri_copy (scheme);
+}
+
+char *
+atom_category_label (AtomCategory *category)
+{
+  return category->label;
+}
+
+void
+atom_category_label_set (AtomCategory *category, char *label)
+{
+  if (category->label)
+    g_free (category->label);
+  category->label = g_strdup (label);
+}
+
+xmlNodePtr
+atom_category_to_xmlnode (AtomCategory *category, char *elname)
+{
+  xmlNodePtr node;
+  node = xmlNewNode (NULL, elname);
+  xmlNewTextChild (node, NULL, "term", category->term);
+  if (category->scheme)
+    xmlNewTextChild (node, NULL, "scheme", iri_get_string (category->scheme));
+  if (category->label)
+    xmlNewTextChild (node, NULL, "label", category->label);
+  return node;
+}
+
+AtomPerson *
+atom_category_new_from_xmlnode (xmlNodePtr node)
+{
+  xmlNodePtr child;
+  AtomCategory *category;
+  category = g_slice_new0 (AtomCategory);
+  for (child = node->xmlChildrenNode; child != NULL; child = child->next)
+    {
+      char *content = xmlNodeGetContent (child->xmlChildrenNode);
+      if (!xmlStrcmp (child->name, "term"))
+       category->term = content;
+      else if (!xmlStrcmp (child->name, "scheme"))
+       category->scheme = iri_new_from_string (content);
+      else if (!xmlStrcmp (child->name, "label"))
+       category->label = content;
+      else
+       xmlFree (content);
+    }
+  return category;
+}
index 1ac753d..8af120b 100644 (file)
@@ -1,4 +1,4 @@
 pkginclude_HEADERS = atom.h config.h ctx.h entry.h person.h error.h feed.h \
                id.h iri.h backend.h atom-glib.h error-glib.h atom-xml.h \
                entry-xml.h person-xml.h feed-xml.h globals.h \
-               map.h frontend.h request.h core.h
+               map.h frontend.h request.h core.h category.h
index 5ae430d..03bec00 100644 (file)
@@ -21,6 +21,7 @@
 #define ATOMPUB_ATOM_XML_H
 
 #include <atompub/person-xml.h>
+#include <atompub/category-xml.h>
 #include <atompub/entry-xml.h>
 #include <atompub/feed-xml.h>
 
index 15e18e9..926d250 100644 (file)
@@ -28,6 +28,7 @@
 #include <atompub/id.h>
 #include <atompub/entry.h>
 #include <atompub/person.h>
+#include <atompub/category.h>
 #include <atompub/feed.h>
 #include <atompub/backend.h>
 #include <atompub/map.h>
diff --git a/include/atompub/category-xml.h b/include/atompub/category-xml.h
new file mode 100644 (file)
index 0000000..d0ce07a
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef ATOM_CATEGORY_XML_H
+#define ATOM_CATEGORY_XML_H
+
+#include <atompub/category.h>
+
+#include <libxml/tree.h>
+
+xmlNodePtr atom_category_to_xmlnode (AtomCategory *, char *);
+AtomCategory * atom_category_new_from_xmlnode (xmlNodePtr);
+
+#endif
diff --git a/include/atompub/category.h b/include/atompub/category.h
new file mode 100644 (file)
index 0000000..5b88408
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef ATOM_CATEGORY_H
+#define ATOM_CATEGORY_H
+
+#include <atompub/iri.h>
+
+typedef struct _atom_category AtomCategory;
+
+AtomCategory * atom_category_new (char *);
+void atom_category_delete (AtomCategory *);
+char * atom_category_term (AtomCategory *);
+void atom_category_term_set (AtomCategory *, char *);
+IRI * atom_category_scheme (AtomCategory *);
+void atom_category_scheme_set (AtomCategory *, IRI *);
+char * atom_category_label (AtomCategory *);
+void atom_category_label_set (AtomCategory *, char *);
+
+#endif