Debian Codegraph @

libgdome/gdomecore/gdome-xml-entity.c

raw
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
2 /* gdome-xml-entity.c
3 *
4 * Copyright (C) 1999 Raph Levien <[email protected]>
5 * Copyright (C) 2000 Mathieu Lacage <[email protected]>
6 * Copyright (C) 2001 Paolo Casarini <[email protected]>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <glib.h>
26 #include "gdome.h"
27 #include <libxml/tree.h>
28 #include <libxml/parser.h>
29 #include <libxml/xmlmemory.h>
30 #include <libxml/entities.h>
31 #include "gdome-xml-util.h"
32 #include "gdome-xml-xmlutil.h"
33 #include "gdome-xml-str.h"
34 #include "gdome-xml-node.h"
35 #include "gdome-xml-entity.h"
36
37 const GdomeEntityVtab gdome_xml_ent_vtab = {
38 {
39 gdome_xml_n_ref,
40 gdome_xml_n_unref,
41 gdome_xml_ent_query_interface,
42 gdome_xml_n_nodeName,
43 gdome_xml_n_nodeValue,
44 gdome_xml_n_set_nodeValue,
45 gdome_xml_n_nodeType,
46 gdome_xml_n_parentNode,
47 gdome_xml_n_childNodes,
48 gdome_xml_n_firstChild,
49 gdome_xml_n_lastChild,
50 gdome_xml_n_previousSibling,
51 gdome_xml_n_nextSibling,
52 gdome_xml_n_attributes,
53 gdome_xml_n_ownerDocument,
54 gdome_xml_n_insertBefore,
55 gdome_xml_n_replaceChild,
56 gdome_xml_n_removeChild,
57 gdome_xml_n_appendChild,
58 gdome_xml_n_hasChildNodes,
59 gdome_xml_n_cloneNode,
60 gdome_xml_n_normalize,
61 gdome_xml_n_isSupported,
62 gdome_xml_n_namespaceURI,
63 gdome_xml_n_prefix,
64 gdome_xml_n_set_prefix,
65 gdome_xml_n_localName,
66 gdome_xml_n_hasAttributes,
67 gdome_xml_n_addEventListener,
68 gdome_xml_n_removeEventListener,
69 gdome_xml_n_dispatchEvent,
70 gdome_xml_n_subTreeDispatchEvent
71 },
72 gdome_xml_ent_publicId,
73 gdome_xml_ent_systemId,
74 gdome_xml_ent_notationName
75 };
76
77
78 /**
79 * gdome_xml_ent_query_interface:
80 * @self: Node Object ref
81 * @interface: interface needed
82 * @exc: Exception Object ref
83 *
84 * Returns: a reference to this object that implements the @interface needed,
85 * or %NULL if the @interface is not supported by this Object.
86 */
87 gpointer
88 gdome_xml_ent_query_interface (GdomeNode *self, const char *interface, GdomeException *exc)
89 {
90 Gdome_xml_Entity *priv = (Gdome_xml_Entity *)self;
91
92 g_return_val_if_fail (priv != NULL, NULL);
93 g_return_val_if_fail (GDOME_XML_IS_ENT (priv), NULL);
94 g_return_val_if_fail (interface != NULL, NULL);
95 g_return_val_if_fail (exc != NULL, NULL);
96
97 if (!strcmp (interface, "Node") ||
98 !strcmp (interface, "Entity") ||
99 !strcmp (interface, "EventTarget")) {
100 priv->refcnt++;
101 return self;
102 }
103 else
104 return NULL;
105 }
106
107 /**
108 * gdome_xml_ent_publicId:
109 * @self: The Entity Object ref
110 * @exc: The Exception Object ref
111 *
112 * Returns: the public identifier associated with the entity, if specified.
113 * If the public identifier was not specified, this is %NULL.
114 */
115 GdomeDOMString *
116 gdome_xml_ent_publicId (GdomeEntity *self, GdomeException *exc)
117 {
118 Gdome_xml_Entity *priv = (Gdome_xml_Entity *)self;
119 xmlEntity *ent = NULL;
120
121 g_return_val_if_fail (priv != NULL, NULL);
122 g_return_val_if_fail (GDOME_XML_IS_ENT (priv), NULL);
123 g_return_val_if_fail (exc != NULL, NULL);
124
125 ent = priv->n;
126 if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY)
127 return NULL;
128 else
129 return gdome_xml_str_mkref_dup((gchar *)ent->ExternalID);
130 }
131
132 /**
133 * gdome_xml_ent_systemId:
134 * @self: The Entity Object ref
135 * @exc: The Exception Object ref
136 *
137 * Returns: the system identifier associated with the entity, if specified.
138 * If the system identifier was not specified, this is %NULL.
139 */
140 GdomeDOMString *
141 gdome_xml_ent_systemId (GdomeEntity *self, GdomeException *exc)
142 {
143 Gdome_xml_Entity *priv = (Gdome_xml_Entity *)self;
144 xmlEntity *ent = NULL;
145
146 g_return_val_if_fail (priv != NULL, NULL);
147 g_return_val_if_fail (GDOME_XML_IS_ENT (priv), NULL);
148 g_return_val_if_fail (exc != NULL, NULL);
149
150 ent = priv->n;
151 if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY)
152 return NULL;
153 else
154 return gdome_xml_str_mkref_dup((gchar *)ent->SystemID);
155 }
156
157 /**
158 * gdome_xml_ent_notationName:
159 * @self: The Entity Object ref
160 * @exc: The Exception Object ref
161 *
162 * Returns: for unparsed entities, the name of the notation for the entity.
163 * For parsed entities, this is %NULL.
164 */
165 GdomeDOMString *
166 gdome_xml_ent_notationName (GdomeEntity *self, GdomeException *exc)
167 {
168 Gdome_xml_Entity *priv = (Gdome_xml_Entity *)self;
169 xmlEntity *ent = NULL;
170
171 g_return_val_if_fail (priv != NULL, NULL);
172 g_return_val_if_fail (GDOME_XML_IS_ENT (priv), NULL);
173 g_return_val_if_fail (exc != NULL, NULL);
174
175 ent = priv->n;
176 if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY)
177 return NULL;
178 else
179 return gdome_xml_str_mkref_dup((gchar *)gdome_xmlGetContent((xmlNode *)ent));
180 }