2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <atompub/atom.h>
23 #include <libxml/tree.h>
33 atom_category_new (char *term)
35 AtomCategory *category;
36 category = g_slice_new (AtomCategory);
37 category->term = g_strdup (term);
38 category->scheme = NULL;
39 category->label = NULL;
44 atom_category_delete (AtomCategory *category)
47 g_free (category->term);
49 iri_delete (category->scheme);
51 g_free (category->label);
52 g_slice_free (AtomCategory, category);
56 atom_category_term (AtomCategory *category)
58 return category->term;
62 atom_category_term_set (AtomCategory *category, char *term)
65 g_free (category->term);
66 category->term = g_strdup (term);
70 atom_category_scheme (AtomCategory *category)
72 return category->scheme;
76 atom_category_scheme_set (AtomCategory *category, IRI *scheme)
79 iri_delete (category->scheme);
80 category->scheme = iri_copy (scheme);
84 atom_category_label (AtomCategory *category)
86 return category->label;
90 atom_category_label_set (AtomCategory *category, char *label)
93 g_free (category->label);
94 category->label = g_strdup (label);
98 atom_category_to_xmlnode (AtomCategory *category, char *elname)
101 node = xmlNewNode (NULL, elname);
102 xmlNewTextChild (node, NULL, "term", category->term);
103 if (category->scheme)
104 xmlNewTextChild (node, NULL, "scheme", iri_get_string (category->scheme));
106 xmlNewTextChild (node, NULL, "label", category->label);
111 atom_category_new_from_xmlnode (xmlNodePtr node)
114 AtomCategory *category;
115 category = g_slice_new0 (AtomCategory);
116 for (child = node->xmlChildrenNode; child != NULL; child = child->next)
118 char *content = xmlNodeGetContent (child->xmlChildrenNode);
119 if (!xmlStrcmp (child->name, "term"))
120 category->term = content;
121 else if (!xmlStrcmp (child->name, "scheme"))
122 category->scheme = iri_new_from_string (content);
123 else if (!xmlStrcmp (child->name, "label"))
124 category->label = content;