00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XALAN_XALANNAMESPACESSTACK_HEADER_GUARD) 00019 #define XALAN_XALANNAMESPACESSTACK_HEADER_GUARD 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/DOMSupport/DOMSupportDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanVector.hpp> 00029 #include <xalanc/Include/XalanDeque.hpp> 00030 00031 00032 00033 #include <xalanc/PlatformSupport/PrefixResolver.hpp> 00034 #include <xalanc/PlatformSupport/XalanNamespace.hpp> 00035 00036 00037 00038 XALAN_CPP_NAMESPACE_BEGIN 00039 00040 00041 class XalanDOMString; 00042 00043 00044 00045 class XALAN_DOMSUPPORT_EXPORT XalanNamespacesStack 00046 { 00047 public: 00048 00049 class XALAN_DOMSUPPORT_EXPORT PrefixResolverProxy : public PrefixResolver 00050 { 00051 public: 00052 00053 /** 00054 * Construct a PrefixResolver from a XalanNamespaceStack 00055 * instance. 00056 * 00057 * @param theStack The stack to use for prefix resolution 00058 * @param theURI The namespace URI of the resolver, if any. Only a reference is kept, so this cannot be a temporary 00059 * @return pointer to the string value if found, otherwise 0. 00060 */ 00061 PrefixResolverProxy( 00062 const XalanNamespacesStack& theStack, 00063 const XalanDOMString& theURI); 00064 00065 virtual 00066 ~PrefixResolverProxy(); 00067 00068 virtual const XalanDOMString* 00069 getNamespaceForPrefix(const XalanDOMString& prefix) const; 00070 00071 virtual const XalanDOMString& 00072 getURI() const; 00073 00074 private: 00075 00076 const XalanNamespacesStack& m_stack; 00077 00078 const XalanDOMString& m_uri; 00079 }; 00080 00081 class XALAN_DOMSUPPORT_EXPORT XalanNamespacesStackEntry 00082 { 00083 public: 00084 00085 typedef XalanNamespace value_type; 00086 00087 typedef XalanDeque<value_type> NamespaceCollectionType; 00088 00089 typedef const XalanDOMString& (value_type::*MemberFunctionType)() const; 00090 00091 typedef NamespaceCollectionType::iterator iterator; 00092 typedef NamespaceCollectionType::reverse_iterator reverse_iterator; 00093 typedef NamespaceCollectionType::const_iterator const_iterator; 00094 typedef NamespaceCollectionType::const_reverse_iterator const_reverse_iterator; 00095 00096 XalanNamespacesStackEntry(MemoryManager& theManager); 00097 00098 XalanNamespacesStackEntry(const XalanNamespacesStackEntry& theSource, 00099 MemoryManager& theManager); 00100 00101 ~XalanNamespacesStackEntry(); 00102 00103 XalanNamespacesStackEntry& 00104 set(const XalanNamespacesStackEntry& theRHS, 00105 MemoryManager& theManager); 00106 00107 void 00108 addDeclaration( 00109 const XalanDOMString& thePrefix, 00110 const XalanDOMChar* theNamespaceURI, 00111 XalanDOMString::size_type theLength); 00112 00113 /** 00114 * Get the namespace for a prefix. 00115 * 00116 * @param thePrefix The prefix to find 00117 * @return pointer to the string value if found, otherwise 0. 00118 */ 00119 const XalanDOMString* 00120 getNamespaceForPrefix(const XalanDOMString& thePrefix) const 00121 { 00122 return findEntry(thePrefix, &XalanNamespace::getPrefix, &XalanNamespace::getURI); 00123 } 00124 00125 /** 00126 * Get the prefix for a namespace. 00127 * 00128 * @param theURI The namespace URI to find 00129 * @return pointer to the string value if found, otherwise 0. 00130 */ 00131 const XalanDOMString* 00132 getPrefixForNamespace(const XalanDOMString& theURI) const 00133 { 00134 return findEntry(theURI, &XalanNamespace::getURI, &XalanNamespace::getPrefix); 00135 } 00136 00137 bool 00138 isPrefixPresent(const XalanDOMString& thePrefix) const 00139 { 00140 return getNamespaceForPrefix(thePrefix) == 0 ? false : true; 00141 } 00142 00143 iterator 00144 begin() 00145 { 00146 return m_namespaces.begin(); 00147 } 00148 00149 const_iterator 00150 begin() const 00151 { 00152 return m_namespaces.begin(); 00153 } 00154 00155 iterator 00156 end() 00157 { 00158 return m_position; 00159 } 00160 00161 const_iterator 00162 end() const 00163 { 00164 return const_iterator(m_position); 00165 } 00166 00167 reverse_iterator 00168 rbegin() 00169 { 00170 return reverse_iterator(end()); 00171 } 00172 00173 const_reverse_iterator 00174 rbegin() const 00175 { 00176 return const_reverse_iterator(end()); 00177 } 00178 00179 reverse_iterator 00180 rend() 00181 { 00182 return reverse_iterator(begin()); 00183 } 00184 00185 const_reverse_iterator 00186 rend() const 00187 { 00188 return const_reverse_iterator(begin()); 00189 } 00190 00191 void 00192 clear(); 00193 00194 void 00195 reset() 00196 { 00197 m_position = m_namespaces.begin(); 00198 } 00199 00200 void 00201 swap(XalanNamespacesStackEntry& theOther); 00202 00203 private: 00204 //Not implemented 00205 XalanNamespacesStackEntry(); 00206 XalanNamespacesStackEntry(const XalanNamespacesStackEntry& theSource); 00207 00208 const XalanDOMString* 00209 findEntry( 00210 const XalanDOMString& theKey, 00211 MemberFunctionType theKeyFunction, 00212 MemberFunctionType theValueFunction) const; 00213 00214 NamespaceCollectionType m_namespaces; 00215 00216 iterator m_position; 00217 }; 00218 00219 00220 typedef XalanNamespacesStackEntry value_type; 00221 00222 typedef XalanDeque<value_type, ConstructWithMemoryManagerTraits<value_type> > NamespacesStackType; 00223 typedef XalanVector<bool> BoolVectorType; 00224 00225 typedef NamespacesStackType::iterator iterator; 00226 typedef NamespacesStackType::reverse_iterator reverse_iterator; 00227 typedef NamespacesStackType::const_iterator const_iterator; 00228 typedef NamespacesStackType::const_reverse_iterator const_reverse_iterator; 00229 00230 typedef NamespacesStackType::size_type size_type; 00231 00232 typedef const XalanDOMString* (value_type::*MemberFunctionType)(const XalanDOMString&) const; 00233 00234 00235 explicit 00236 XalanNamespacesStack(MemoryManager& theManager); 00237 00238 ~XalanNamespacesStack(); 00239 00240 void 00241 addDeclaration( 00242 const XalanDOMString& thePrefix, 00243 const XalanDOMString& theURI) 00244 { 00245 addDeclaration( 00246 thePrefix, 00247 theURI.c_str(), 00248 theURI.length()); 00249 } 00250 00251 void 00252 addDeclaration( 00253 const XalanDOMString& thePrefix, 00254 const XalanDOMChar* theURI) 00255 { 00256 addDeclaration( 00257 thePrefix, 00258 theURI, 00259 length(theURI)); 00260 } 00261 00262 void 00263 addDeclaration( 00264 const XalanDOMString& thePrefix, 00265 const XalanDOMChar* theURI, 00266 XalanDOMString::size_type theLength); 00267 00268 void 00269 pushContext(); 00270 00271 void 00272 popContext(); 00273 00274 const XalanDOMString* 00275 getNamespaceForPrefix(const XalanDOMString& thePrefix) const; 00276 00277 const XalanDOMString* 00278 getPrefixForNamespace(const XalanDOMString& theURI) const 00279 { 00280 return findEntry(theURI, &value_type::getPrefixForNamespace); 00281 } 00282 00283 /** 00284 * See if the prefix has been mapped to a namespace in the current 00285 * context, without looking down the stack of namespaces. 00286 */ 00287 bool 00288 prefixIsPresentLocal(const XalanDOMString& thePrefix); 00289 00290 void 00291 clear(); 00292 00293 iterator 00294 begin() 00295 { 00296 return m_stackBegin + 1; 00297 } 00298 00299 const_iterator 00300 begin() const 00301 { 00302 return const_iterator(m_stackBegin + 1); 00303 } 00304 00305 iterator 00306 end() 00307 { 00308 return m_stackPosition + 1; 00309 } 00310 00311 const_iterator 00312 end() const 00313 { 00314 return const_iterator(m_stackPosition + 1); 00315 } 00316 00317 reverse_iterator 00318 rbegin() 00319 { 00320 return reverse_iterator(end()); 00321 } 00322 00323 const_reverse_iterator 00324 rbegin() const 00325 { 00326 return const_reverse_iterator(end()); 00327 } 00328 00329 reverse_iterator 00330 rend() 00331 { 00332 return reverse_iterator(begin()); 00333 } 00334 00335 const_reverse_iterator 00336 rend() const 00337 { 00338 return const_reverse_iterator(begin()); 00339 } 00340 00341 size_type 00342 size() const 00343 { 00344 return m_resultNamespaces.size() - 1; 00345 } 00346 00347 bool 00348 empty() const 00349 { 00350 return NamespacesStackType::const_iterator(m_stackPosition) == m_resultNamespaces.begin() ? true : false; 00351 } 00352 00353 private: 00354 00355 // not implemented 00356 XalanNamespacesStack(const XalanNamespacesStack&); 00357 XalanNamespacesStack(); 00358 XalanNamespacesStackEntry& 00359 operator=(const XalanNamespacesStackEntry& theRHS); 00360 00361 bool 00362 operator==(const XalanNamespacesStack&) const; 00363 00364 XalanNamespacesStack& 00365 operator=(const XalanNamespacesStack&); 00366 00367 enum { eDefaultCreateNewContextStackSize = 25 }; 00368 00369 const XalanDOMString* 00370 findEntry( 00371 const XalanDOMString& theKey, 00372 MemberFunctionType theFunction) const; 00373 00374 /** 00375 * A stack to keep track of the result tree namespaces. 00376 */ 00377 NamespacesStackType m_resultNamespaces; 00378 00379 NamespacesStackType::iterator m_stackBegin; 00380 00381 NamespacesStackType::iterator m_stackPosition; 00382 00383 BoolVectorType m_createNewContextStack; 00384 }; 00385 00386 00387 00388 XALAN_CPP_NAMESPACE_END 00389 00390 00391 00392 #endif // XALAN_XALANNAMESPACESSTACK_HEADER_GUARD
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|