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(XALANQNAME_HEADER_GUARD_1357924680) 00019 #define XALANQNAME_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base header file. Must be first. 00024 #include <xalanc/XPath/XPathDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanMap.hpp> 00029 #include <xalanc/Include/XalanDeque.hpp> 00030 #include <xalanc/Include/STLHelper.hpp> 00031 00032 00033 00034 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00035 00036 00037 00038 #include <xalanc/PlatformSupport/DOMStringHelper.hpp> 00039 #include <xalanc/PlatformSupport/PrefixResolver.hpp> 00040 00041 00042 00043 #include <xalanc/XPath/NameSpace.hpp> 00044 #include <xalanc/XPath/XalanXPathException.hpp> 00045 00046 00047 00048 XALAN_CPP_NAMESPACE_BEGIN 00049 00050 00051 00052 class XalanElement; 00053 class XPathEnvSupport; 00054 00055 00056 00057 /** 00058 * Class to represent a qualified name. The name of an internal XSLT object, 00059 * specifically a named template (see [7 Named Templates]), a mode (see [6.7 Modes]), 00060 * an attribute set (see [8.1.4 Named Attribute Sets]), a key (see [14.2 Keys]), 00061 * a locale (see [14.3 Number Formatting]), a variable or a parameter (see 00062 * [12 Variables and Parameters]) is specified as a QName. If it has a prefix, 00063 * then the prefix is expanded into a URI reference using the namespace declarations 00064 * in effect on the attribute in which the name occurs. The expanded name 00065 * consisting of the local part of the name and the possibly null URI reference 00066 * is used as the name of the object. The default namespace is not used for 00067 * unprefixed names. 00068 */ 00069 00070 class XALAN_XPATH_EXPORT XalanQName 00071 { 00072 public: 00073 00074 typedef XalanDeque<NameSpace, ConstructWithMemoryManagerTraits<NameSpace> > 00075 NamespaceVectorType; 00076 typedef XalanDeque<NamespaceVectorType, ConstructWithMemoryManagerTraits<NamespaceVectorType> > 00077 NamespacesStackType; 00078 00079 /** 00080 * Construct an empty XalanQName. 00081 * 00082 */ 00083 explicit 00084 XalanQName() 00085 { 00086 } 00087 00088 virtual 00089 ~XalanQName() 00090 { 00091 } 00092 00093 XalanQName(const XalanQName&) 00094 { 00095 } 00096 00097 /** 00098 * Retrieve the local part of qualified name. 00099 * 00100 * @return local part string 00101 */ 00102 virtual const XalanDOMString& 00103 getLocalPart() const = 0; 00104 00105 /** 00106 * Retrieve the namespace of qualified name. 00107 * 00108 * @return namespace string 00109 */ 00110 virtual const XalanDOMString& 00111 getNamespace() const = 0; 00112 00113 /** 00114 * Determine if the qualified name is valid. 00115 * 00116 * @return true if the instance is a valid QName, false if not. 00117 */ 00118 bool 00119 isValid() const 00120 { 00121 return isValidNCName(getLocalPart()); 00122 } 00123 00124 /** 00125 * Whether the qualified name is empty. 00126 * 00127 * @return true if namespace and local part are both empty 00128 */ 00129 bool 00130 isEmpty() const 00131 { 00132 return getNamespace().empty() && getLocalPart().empty(); 00133 } 00134 00135 /** 00136 * Override equals and agree that we're equal if the passed object is a 00137 * string and it matches the name of the arg. 00138 * 00139 * @param theRHS namespace to compare 00140 * @return true if namespace and local part are both empty 00141 */ 00142 bool 00143 equals(const XalanQName& theRHS) const 00144 { 00145 // Note that we do not use our member variables here. See 00146 // class QNameReference for details... 00147 return getLocalPart() == theRHS.getLocalPart() && 00148 getNamespace() == theRHS.getNamespace(); 00149 } 00150 00151 /** 00152 * Format the QName using the notation "{namespace-uri}local-part" or 00153 * "local-part" if the namespace URI is empty. The result is appended 00154 * to the provided string. 00155 * 00156 * @param theString The string to format with the 00157 * @return A reference to the parameter. 00158 */ 00159 XalanDOMString& 00160 format(XalanDOMString& theString) const; 00161 00162 size_t 00163 hash() const 00164 { 00165 return getLocalPart().hash() % (getNamespace().hash() + 1); 00166 } 00167 00168 class XALAN_XPATH_EXPORT PrefixResolverProxy : public PrefixResolver 00169 { 00170 public: 00171 00172 /** 00173 * Construct a PrefixResolver from a NamespacesStackType 00174 * instance. 00175 * 00176 * @param theStack The stack to use for prefix resolution 00177 * @param theURI The namespace URI of the resolver, if any. Only a reference is kept, so this cannot be a temporary 00178 * @return pointer to the string value if found, otherwise 0. 00179 */ 00180 PrefixResolverProxy( 00181 const NamespacesStackType& theStack, 00182 const XalanDOMString& theURI); 00183 00184 virtual 00185 ~PrefixResolverProxy(); 00186 00187 virtual const XalanDOMString* 00188 getNamespaceForPrefix(const XalanDOMString& prefix) const; 00189 00190 virtual const XalanDOMString& 00191 getURI() const; 00192 00193 private: 00194 00195 const NamespacesStackType& m_stack; 00196 00197 const XalanDOMString& m_uri; 00198 }; 00199 00200 /** 00201 * Get the namespace for a prefix by searching a vector of namespaces. 00202 * 00203 * @param namespaces vector of namespaces to search 00204 * @param prefix namespace prefix to find 00205 * @return pointer to the string value if found, otherwise null. 00206 */ 00207 static const XalanDOMString* 00208 getNamespaceForPrefix( 00209 const NamespaceVectorType& namespaces, 00210 const XalanDOMString& prefix); 00211 00212 /** 00213 * Get the namespace for a prefix by searching a stack of namespace 00214 * vectors. 00215 * 00216 * @param nsStack stack of namespace vectors to search 00217 * @param prefix namespace prefix to find 00218 * @return pointer to the string value if found, otherwise null. 00219 */ 00220 static const XalanDOMString* 00221 getNamespaceForPrefix( 00222 const NamespacesStackType& nsStack, 00223 const XalanDOMString& prefix); 00224 00225 static const XalanDOMString* 00226 getNamespaceForPrefix( 00227 const NamespacesStackType& nsStack, 00228 const XalanDOMChar* prefix); 00229 00230 /** 00231 * Get the namespace for a prefix by searching a range of iterators. 00232 * The search is done in reverse, from the end of the range to the 00233 * beginning. 00234 * 00235 * @param theBegin The beginning iterator for the range 00236 * @param theBegin The ending iterator for the range 00237 * @param prefix namespace prefix to find 00238 * @return pointer to the string value if found, otherwise null. 00239 */ 00240 static const XalanDOMString* 00241 getNamespaceForPrefix( 00242 NamespacesStackType::const_iterator theBegin, 00243 NamespacesStackType::const_iterator theEnd, 00244 const XalanDOMString& prefix); 00245 00246 /** 00247 * Get the prefix for a namespace by searching a vector of namespaces. 00248 * 00249 * @param namespaces vector of namespaces to search 00250 * @param uri URI string for namespace to find 00251 * @param reverse true to search vector from last to first, default true 00252 * @return pointer to the string value if found, otherwise null. 00253 */ 00254 static const XalanDOMString* 00255 getPrefixForNamespace( 00256 const NamespaceVectorType& namespaces, 00257 const XalanDOMString& uri); 00258 00259 static const XalanDOMString* 00260 getNamespaceForPrefix( 00261 const NamespaceVectorType& namespaces, 00262 const XalanDOMChar* prefix); 00263 00264 /** 00265 * Get the prefix for a namespace by searching a stack of namespace 00266 * vectors. 00267 * 00268 * @param nsStack stack of namespace vectors to search 00269 * @param uri URI string for namespace to find 00270 * @return pointer to the string value if found, otherwise null. 00271 */ 00272 static const XalanDOMString* 00273 getPrefixForNamespace( 00274 const NamespacesStackType& nsStack, 00275 const XalanDOMString& uri); 00276 00277 /** 00278 * Get the prefix for a namespace by searching a range of iterators. 00279 * The search is done in reverse, from the end of the range to the 00280 * beginning. 00281 * 00282 * @param theBegin The beginning iterator for the range to search 00283 * @param theBegin The ending iterator for the range to search 00284 * @param uri URI string for namespace to find 00285 * @return pointer to the string value if found, otherwise null. 00286 */ 00287 static const XalanDOMString* 00288 getPrefixForNamespace( 00289 NamespacesStackType::const_iterator theBegin, 00290 NamespacesStackType::const_iterator theEnd, 00291 const XalanDOMString& uri); 00292 00293 static const XalanDOMString* 00294 getNamespaceForPrefix( 00295 NamespacesStackType::const_iterator theBegin, 00296 NamespacesStackType::const_iterator theEnd, 00297 const XalanDOMChar* prefix); 00298 /** 00299 * Determine if the string supplied satisfies the grammar for 00300 * an XML NCName. 00301 * 00302 * @param theNCName The string to check 00303 * @return bool true if the string is a valid NCName, false if not. 00304 */ 00305 static bool 00306 isValidNCName(const XalanDOMString& theNCName); 00307 00308 /** 00309 * Determine if the string supplied satisfies the grammar for 00310 * an XML NCName. 00311 * 00312 * @param theNCName The string to check 00313 * @param theLength The length of the string 00314 * @return bool true if the string is a valid NCName, false if not 00315 */ 00316 static bool 00317 isValidNCName( 00318 const XalanDOMChar* theNCName, 00319 XalanDOMString::size_type theLength = XalanDOMString::npos); 00320 00321 /** 00322 * Determine if the string supplied satisfies the grammar for 00323 * an XML QName. Note that this function does not determine 00324 * if any supplied prefix is bound to a namespace URI 00325 * 00326 * @param theQName The string to check 00327 * @return bool true if the string is a valid QName, false if not 00328 */ 00329 static bool 00330 isValidQName(const XalanDOMString& theQName); 00331 00332 /** 00333 * Determine if the string supplied satisfies the grammar for 00334 * an XML QName. Note that this function does not determine 00335 * if any supplied prefix is bound to a namespace URI 00336 * 00337 * @param theQName The string to check 00338 * @param theLength The length of the string 00339 * @return bool true if the string is a valid QName, false if not 00340 */ 00341 static bool 00342 isValidQName( 00343 const XalanDOMChar* theQName, 00344 XalanDOMString::size_type theLength = XalanDOMString::npos); 00345 00346 class InvalidQNameException : public XalanXPathException 00347 { 00348 public: 00349 00350 /** 00351 * Constructor 00352 * 00353 * @param theQName The QName string that is not valid. 00354 * @param theQNameLength The length of the string. 00355 * @param theResult A temporary string for loading the error message. 00356 */ 00357 InvalidQNameException( 00358 const XalanDOMChar* theQName, 00359 XalanDOMString::size_type theQNameLength, 00360 XalanDOMString& theResult, 00361 const Locator* theLocator); 00362 00363 /** 00364 * Constructor 00365 * 00366 * @param theMessage The message for the exception 00367 * @param theManager The MemoryManager instance to use when constructing the exception 00368 */ 00369 InvalidQNameException( 00370 const XalanDOMString& theMessage, 00371 MemoryManager& theManager, 00372 const Locator* theLocator); 00373 00374 InvalidQNameException(const InvalidQNameException& other); 00375 00376 virtual 00377 ~InvalidQNameException(); 00378 00379 virtual const XalanDOMChar* 00380 getType() const; 00381 00382 private: 00383 00384 static const XalanDOMString& 00385 format( 00386 const XalanDOMChar* theQName, 00387 XalanDOMString::size_type theQNameLength, 00388 XalanDOMString& theResult); 00389 }; 00390 00391 protected: 00392 00393 static const XalanDOMString s_emptyString; 00394 }; 00395 00396 00397 inline bool 00398 operator==( 00399 const XalanQName& theLHS, 00400 const XalanQName& theRHS) 00401 { 00402 return theLHS.equals(theRHS); 00403 } 00404 00405 00406 00407 inline bool 00408 operator!=( 00409 const XalanQName& theLHS, 00410 const XalanQName& theRHS) 00411 { 00412 return !(theLHS == theRHS); 00413 } 00414 00415 00416 00417 inline bool 00418 operator<( 00419 const XalanQName& theLHS, 00420 const XalanQName& theRHS) 00421 { 00422 if (theLHS.getNamespace() < theRHS.getNamespace()) 00423 { 00424 return true; 00425 } 00426 else if (equals(theLHS.getNamespace(), theRHS.getNamespace())) 00427 { 00428 return theLHS.getLocalPart() < theRHS.getLocalPart(); 00429 } 00430 else 00431 { 00432 return false; 00433 } 00434 } 00435 00436 template<> 00437 struct XalanMapKeyTraits<XalanQName> 00438 { 00439 typedef XalanHashMemberReference<XalanQName> Hasher; 00440 typedef XALAN_STD_QUALIFIER equal_to<XalanQName> Comparator; 00441 }; 00442 00443 template<> 00444 struct XalanMapKeyTraits<const XalanQName*> 00445 { 00446 typedef XalanHashMemberPointer<XalanQName> Hasher; 00447 typedef pointer_equal<XalanQName> Comparator; 00448 }; 00449 00450 00451 XALAN_CPP_NAMESPACE_END 00452 00453 00454 00455 #endif // XALANQNAME_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|