Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

NamespaceSupport.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-  $Id: NamespaceSupport.cpp,v 1.1.1.1.2.1 2003/04/21 19:14:54 chad Exp $
00002 
00003 #include "ACEXML/common/NamespaceSupport.h"
00004 
00005 static const ACEXML_Char ACEXML_XMLNS_PREFIX_name[] = {'x', 'm', 'l', 'n', 's', 0};
00006 const ACEXML_Char *ACEXML_NamespaceSupport::XMLNS_PREFIX = ACEXML_XMLNS_PREFIX_name;
00007 
00008 static const ACEXML_Char ACEXML_DEFAULT_NS_PREFIX[] = {0};
00009 
00010 static const ACEXML_Char ACEXML_TABOO_NS_PREFIX[] = {'x', 'm', 'l', 0};
00011 
00012 static const ACEXML_Char ACEXML_XMLNS_URI_name[] = {
00013   'h', 't', 't', 'p', ':', '/', '/',
00014   'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
00015   'X', 'M', 'L', '/', '1', '9', '9', '8', '/',
00016   'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', 0};
00017 const ACEXML_Char *ACEXML_NamespaceSupport::XMLNS = ACEXML_XMLNS_URI_name;
00018 
00019 #if !defined (__ACEXML_INLINE__)
00020 # include "ACEXML/common/NamespaceSupport.i"
00021 #endif /* __ACEXML_INLINE__ */
00022 
00023 ACEXML_Namespace_Context_Stack::ACEXML_Namespace_Context_Stack (void)
00024   : head_ (0)
00025 {
00026 }
00027 
00028 ACEXML_Namespace_Context_Stack::~ACEXML_Namespace_Context_Stack (void)
00029 {
00030   // Clean up stuff.
00031 }
00032 
00033 int
00034 ACEXML_Namespace_Context_Stack::push (ACEXML_NS_CONTEXT *nsc)
00035 {
00036   struct NS_Node_T *temp = 0;
00037   ACE_NEW_RETURN (temp, struct NS_Node_T, -1);
00038 
00039   temp->item_ = nsc;
00040   temp->next_ = this->head_;
00041 
00042   this->head_ = temp;
00043   return 0;
00044 }
00045 
00046 ACEXML_NS_CONTEXT *
00047 ACEXML_Namespace_Context_Stack::pop (void)
00048 {
00049   if (this->head_ != 0)
00050     {
00051       struct NS_Node_T *temp = this->head_;
00052       this->head_ = temp->next_;
00053 
00054       ACEXML_NS_CONTEXT* retv = temp->item_;
00055       delete temp;
00056       return retv;
00057     }
00058   return 0;
00059 }
00060 
00061 
00062 ACEXML_NamespaceSupport::ACEXML_NamespaceSupport (void)
00063   : ns_stack_ (),
00064     effective_context_ (0)
00065 {
00066   // @@ No way to tell if the new fails.
00067   ACE_NEW (effective_context_,
00068            ACEXML_NS_CONTEXT ());
00069 
00070   ACEXML_String prefix (ACEXML_TABOO_NS_PREFIX, 0, 0);
00071   ACEXML_String uri (ACEXML_XMLNS_URI_name, 0, 0);
00072   this->effective_context_->bind (prefix, uri);
00073 }
00074 
00075 ACEXML_NamespaceSupport::~ACEXML_NamespaceSupport (void)
00076 {
00077   while (this->popContext () == 0)
00078     ;
00079 }
00080 
00081 int
00082 ACEXML_NamespaceSupport::declarePrefix (const ACEXML_Char *prefix,
00083                                         const ACEXML_Char *uri)
00084 {
00085   // Unless predefined by w3.org(?) NS prefix can never start with
00086   // "xml".
00087   if (ACE_OS_String::strcmp (ACEXML_TABOO_NS_PREFIX, prefix) == 0)
00088     return -1;
00089 
00090   ACEXML_String ns_prefix (prefix, 0, 0);
00091   ACEXML_String ns_uri (uri, 0, 0);
00092 
00093   return this->effective_context_->bind (ns_prefix,
00094                                          ns_uri);
00095 }
00096 
00097 int
00098 ACEXML_NamespaceSupport::getDeclaredPrefixes (ACEXML_STR_LIST &prefixes) const
00099 {
00100   ACEXML_NS_CONTEXT_ENTRY *entry;
00101 
00102   // The prefix for default namespace (empty string) is included in
00103   // the return list.
00104   for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
00105        iter.next (entry) != 0;
00106        iter.advance ())
00107     prefixes.enqueue_tail (entry->ext_id_.c_str ());
00108 
00109   return 0;
00110 }
00111 
00112 const ACEXML_Char *
00113 ACEXML_NamespaceSupport::getPrefix (const ACEXML_Char *uri) const
00114 {
00115   ACEXML_NS_CONTEXT_ENTRY *entry;
00116 
00117   for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
00118        iter.next (entry) != 0;
00119        iter.advance ())
00120     if (entry->int_id_ == ACEXML_String (uri, 0, 0) &&
00121         entry->ext_id_ != ACEXML_String (ACEXML_DEFAULT_NS_PREFIX, 0, 0))
00122       return entry->ext_id_.c_str ();
00123 
00124   return 0;                     // Nothing found.
00125 }
00126 
00127 int
00128 ACEXML_NamespaceSupport::getPrefixes (ACEXML_STR_LIST &prefixes) const
00129 {
00130   ACEXML_NS_CONTEXT_ENTRY *entry;
00131 
00132   // The prefix for default namespace (empty string) is not included
00133   // in the return list.
00134   for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
00135        iter.next (entry) != 0;
00136        iter.advance ())
00137     if (entry->ext_id_ != ACEXML_String(ACEXML_DEFAULT_NS_PREFIX, 0, 0))
00138       prefixes.enqueue_tail (entry->ext_id_.c_str ());
00139     else
00140       continue;
00141 
00142   return 0;
00143 }
00144 
00145 int
00146 ACEXML_NamespaceSupport::getPrefixes (const ACEXML_Char *uri,
00147                                       ACEXML_STR_LIST &prefixes) const
00148 {
00149   ACEXML_NS_CONTEXT_ENTRY *entry;
00150 
00151   for (ACEXML_NS_CONTEXT_ITER iter (*this->effective_context_);
00152        iter.next (entry) != 0;
00153        iter.advance ())
00154     if (entry->int_id_ == ACEXML_String (uri, 0, 0) &&
00155         entry->ext_id_ != ACEXML_String (ACEXML_DEFAULT_NS_PREFIX, 0, 0))
00156       prefixes.enqueue_tail (entry->ext_id_.c_str ());
00157     else
00158       continue;
00159 
00160   return 0;                     // Nothing found.
00161 }
00162 
00163 const ACEXML_Char *
00164 ACEXML_NamespaceSupport::getURI (const ACEXML_Char *prefix) const
00165 {
00166   ACEXML_NS_CONTEXT_ENTRY *entry;
00167 
00168   if (this->effective_context_->find (ACEXML_String (prefix, 0, 0),
00169                                       entry) == 0)
00170     return entry->int_id_.c_str ();
00171   return 0;
00172 }
00173 
00174 int
00175 ACEXML_NamespaceSupport::popContext (void)
00176 {
00177   delete this->effective_context_;
00178 
00179   if ((this->effective_context_ = this->ns_stack_.pop ()) == 0)
00180     return -1;
00181   return 0;
00182 }
00183 
00184 int
00185 ACEXML_NamespaceSupport::pushContext (void)
00186 {
00187   ACEXML_NS_CONTEXT *temp = this->effective_context_;
00188   ACE_NEW_RETURN (this->effective_context_,
00189                   ACEXML_NS_CONTEXT (),
00190                   -1);
00191 
00192   // @@ Copy everything from the old context to the new one.
00193   ACEXML_NS_CONTEXT_ENTRY *entry;
00194 
00195   for (ACEXML_NS_CONTEXT_ITER iter (*temp);
00196        iter.next (entry) != 0;
00197        iter.advance ())
00198     this->effective_context_->bind (entry->ext_id_,
00199                                     entry->int_id_);
00200   this->ns_stack_.push (temp);
00201   return 0;
00202 }
00203 
00204 
00205 int
00206 ACEXML_NamespaceSupport::processName (const ACEXML_Char *qName,
00207                                       const ACEXML_Char *&uri,
00208                                       const ACEXML_Char *&name,
00209                                       int is_attribute) const
00210 {
00211   size_t qlen = ACE_OS_String::strlen (qName);
00212   int len = -1;
00213   for (size_t i = 0; i < qlen; ++i)
00214     if (qName [i] == ':')
00215       {
00216         len = ACE_static_cast(int, i);
00217         break;
00218       }
00219 
00220   ACEXML_String prefix;
00221 
00222   if (len == -1)
00223     {
00224       name = qName;
00225     }
00226   else
00227     {
00228       prefix.set (qName, len, 1);
00229       name = qName + len + 1;
00230     }
00231 
00232   if (is_attribute && len == -1) {
00233     uri = ACEXML_DEFAULT_NS_PREFIX;
00234     return 0;
00235   }
00236 
00237   ACEXML_NS_CONTEXT_ENTRY *entry;
00238 
00239   if (this->effective_context_->find (prefix, entry) == 0)
00240     uri = entry->int_id_.c_str ();
00241   else
00242     {
00243       uri = ACEXML_DEFAULT_NS_PREFIX;
00244       return -1;
00245     }
00246 
00247   return 0;
00248 }
00249 
00250 int
00251 ACEXML_NamespaceSupport::reset (void)
00252 {
00253   // Not implemented.
00254   return 0;
00255 }
00256 
00257 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00258 template class ACE_Hash_Map_Entry<ACEXML_String, ACEXML_String>;
00259 template class ACE_Hash_Map_Manager_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>;
00260 template class ACE_Hash_Map_Iterator_Base_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>;
00261 template class ACE_Hash_Map_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>;
00262 template class ACE_Hash_Map_Reverse_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>;
00263 template class ACE_Unbounded_Queue<const ACEXML_Char *>;
00264 template class ACE_Unbounded_Queue_Iterator<const ACEXML_Char *>;
00265 template class ACE_Node<const ACEXML_Char *>;
00266 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00267 #pragma instantiate ACE_Hash_Map_Entry<ACEXML_String, ACEXML_String>
00268 #pragma instantiate ACE_Hash_Map_Manager_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>
00269 #pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>
00270 #pragma instantiate ACE_Hash_Map_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>
00271 #pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACEXML_String, ACEXML_String, ACE_Hash<ACEXML_String>, ACE_Equal_To<ACEXML_String>, ACE_Null_Mutex>
00272 #pragma instantiate ACE_Unbounded_Queue<const ACEXML_Char *>
00273 #pragma instantiate ACE_Unbounded_Queue_Iterator<const ACEXML_Char *>
00274 #pragma instantiate ACE_Node<const ACEXML_Char *>
00275 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

Generated on Mon Jun 16 13:23:22 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002