3 #include "ACEXML/common/NamespaceSupport.h"
4 #include "ace/OS_NS_string.h"
6 static const ACEXML_Char ACEXML_XMLNS_PREFIX_name
[] = ACE_TEXT ("xmlns");
8 const ACEXML_Char
*ACEXML_NamespaceSupport::XMLNS_PREFIX
= ACEXML_XMLNS_PREFIX_name
;
10 static const ACEXML_Char ACEXML_DEFAULT_NS_PREFIX
[] = {0};
12 static const ACEXML_Char ACEXML_TABOO_NS_PREFIX
[] = ACE_TEXT ("xml");
14 static const ACEXML_Char ACEXML_XMLNS_URI_name
[] = ACE_TEXT ("http://www.w3.org/XML/1998/namespace");
15 const ACEXML_Char
*ACEXML_NamespaceSupport::XMLNS
= ACEXML_XMLNS_URI_name
;
17 ACEXML_Namespace_Context_Stack::ACEXML_Namespace_Context_Stack ()
21 ACEXML_Namespace_Context_Stack::~ACEXML_Namespace_Context_Stack ()
27 ACEXML_Namespace_Context_Stack::push (ACEXML_NS_CONTEXT
*nsc
)
29 return (this->stack_
.push (nsc
) < 0);
33 ACEXML_Namespace_Context_Stack::pop ()
35 if (this->stack_
.size() <= 0)
38 ACEXML_NS_CONTEXT
* temp
= 0;
39 int retval
= this->stack_
.pop (temp
);
42 ACE_ERROR ((LM_ERROR
, "Unable to pop Namespace context from stack\n"));
49 ACEXML_NamespaceSupport::popContext ()
51 delete this->effective_context_
;
53 if ((this->effective_context_
= this->ns_stack_
.pop ()) == 0)
59 ACEXML_NamespaceSupport::pushContext ()
61 ACEXML_NS_CONTEXT
*temp
= this->effective_context_
;
62 ACE_NEW_RETURN (this->effective_context_
,
66 // @@ Copy everything from the old context to the new one.
67 ACEXML_NS_CONTEXT_ENTRY
*entry
= 0;
69 for (ACEXML_NS_CONTEXT_ITER
iter (*temp
);
70 iter
.next (entry
) != 0;
72 this->effective_context_
->bind (entry
->ext_id_
,
74 this->ns_stack_
.push (temp
);
78 ACEXML_NamespaceSupport::ACEXML_NamespaceSupport ()
80 effective_context_ (0)
84 ACEXML_NamespaceSupport::init ()
86 // @@ No way to tell if the new fails.
87 ACE_NEW_RETURN (effective_context_
, ACEXML_NS_CONTEXT(), -1);
89 ACEXML_String
prefix (ACEXML_TABOO_NS_PREFIX
, 0, false);
90 ACEXML_String
uri (ACEXML_XMLNS_URI_name
, 0, false);
91 return this->effective_context_
->bind (prefix
, uri
);
94 ACEXML_NamespaceSupport::~ACEXML_NamespaceSupport ()
96 while (this->popContext () == 0)
101 ACEXML_NamespaceSupport::declarePrefix (const ACEXML_Char
*prefix
,
102 const ACEXML_Char
*uri
)
107 // Unless predefined by w3.org(?) NS prefix can never start with
109 if (ACE_OS::strcmp (ACEXML_TABOO_NS_PREFIX
, prefix
) == 0)
112 ACEXML_String
ns_prefix (prefix
, 0, false);
113 ACEXML_String
ns_uri (uri
, 0, false);
115 return this->effective_context_
->rebind (ns_prefix
, ns_uri
);
119 ACEXML_NamespaceSupport::getDeclaredPrefixes (ACEXML_STR_LIST
&prefixes
) const
121 ACEXML_NS_CONTEXT_ENTRY
*entry
= 0;
123 // The prefix for default namespace (empty string) is included in
125 for (ACEXML_NS_CONTEXT_ITER
iter (*this->effective_context_
);
126 iter
.next (entry
) != 0;
128 prefixes
.enqueue_tail (entry
->ext_id_
.c_str ());
134 ACEXML_NamespaceSupport::getPrefix (const ACEXML_Char
*uri
) const
136 if (!uri
|| *uri
== 0)
139 ACEXML_NS_CONTEXT_ENTRY
*entry
= 0;
141 for (ACEXML_NS_CONTEXT_ITER
iter (*this->effective_context_
);
142 iter
.next (entry
) != 0;
144 if (entry
->int_id_
== ACEXML_String (uri
, 0, false))
145 return entry
->ext_id_
.c_str ();
147 return 0; // Nothing found.
151 ACEXML_NamespaceSupport::getPrefixes (ACEXML_STR_LIST
&prefixes
) const
153 ACEXML_NS_CONTEXT_ENTRY
*entry
= 0;
155 // The prefix for default namespace (empty string) is not included
156 // in the return list.
157 for (ACEXML_NS_CONTEXT_ITER
iter (*this->effective_context_
);
158 iter
.next (entry
) != 0;
160 prefixes
.enqueue_tail (entry
->ext_id_
.c_str ());
165 ACEXML_NamespaceSupport::getPrefixes (const ACEXML_Char
*uri
,
166 ACEXML_STR_LIST
&prefixes
) const
171 ACEXML_NS_CONTEXT_ENTRY
*entry
= 0;
173 for (ACEXML_NS_CONTEXT_ITER
iter (*this->effective_context_
);
174 iter
.next (entry
) != 0;
176 if (entry
->int_id_
== ACEXML_String (uri
, 0, false) &&
177 entry
->ext_id_
!= ACEXML_String (ACEXML_DEFAULT_NS_PREFIX
, 0, false))
178 prefixes
.enqueue_tail (entry
->ext_id_
.c_str ());
182 return 0; // Nothing found.
186 ACEXML_NamespaceSupport::getURI (const ACEXML_Char
*prefix
) const
191 ACEXML_NS_CONTEXT_ENTRY
*entry
= 0;
193 if (this->effective_context_
->find (ACEXML_String (prefix
, 0, false),
195 return entry
->int_id_
.c_str ();
200 ACEXML_NamespaceSupport::processName (const ACEXML_Char
*qName
,
201 const ACEXML_Char
*&uri
,
202 const ACEXML_Char
*&name
,
203 int is_attribute
) const
205 int qlen
= static_cast<int> (ACE_OS::strlen (qName
));
207 for (int i
= 0; i
< qlen
; ++i
)
208 if (qName
[i
] == ':')
214 ACEXML_String
prefix (ACE_TEXT (""), 0, false);
219 prefix
.set (qName
, len
, 1);
220 name
= qName
+ len
+ 1;
223 if (is_attribute
&& len
== -1) {
224 uri
= ACEXML_DEFAULT_NS_PREFIX
;
228 ACEXML_NS_CONTEXT_ENTRY
*entry
= 0;
230 if (this->effective_context_
->find (prefix
, entry
) == 0)
231 uri
= entry
->int_id_
.c_str ();
234 uri
= ACEXML_DEFAULT_NS_PREFIX
;
241 ACEXML_NamespaceSupport::reset ()
243 while (this->popContext() != -1)