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 00019 #if !defined(XALAN_NAMESPACESHANDLER_HEADER_GUARD) 00020 #define XALAN_NAMESPACESHANDLER_HEADER_GUARD 00021 00022 00023 00024 // Base include file. Must be first. 00025 #include <xalanc/XSLT/XSLTDefinitions.hpp> 00026 00027 00028 00029 #include <xalanc/Include/XalanVector.hpp> 00030 #include <xalanc/Include/XalanMap.hpp> 00031 00032 00033 00034 #include <xalanc/PlatformSupport/DOMStringHelper.hpp> 00035 00036 00037 00038 #include <xalanc/XPath/NameSpace.hpp> 00039 #include <xalanc/XPath/XalanQName.hpp> 00040 00041 00042 00043 XALAN_CPP_NAMESPACE_BEGIN 00044 00045 00046 00047 class StylesheetConstructionContext; 00048 class StylesheetExecutionContext; 00049 00050 00051 00052 class XALAN_XSLT_EXPORT NamespacesHandler 00053 { 00054 00055 public: 00056 00057 class PrefixChecker 00058 { 00059 public: 00060 00061 PrefixChecker(); 00062 00063 virtual 00064 ~PrefixChecker(); 00065 00066 virtual bool 00067 isActive(const XalanDOMString& thePrefix) const = 0; 00068 }; 00069 00070 class XALAN_XSLT_EXPORT Namespace 00071 { 00072 public: 00073 00074 Namespace() : 00075 m_prefix(&s_emptyString), 00076 m_uri(&s_emptyString) 00077 { 00078 } 00079 00080 Namespace( 00081 const XalanDOMString& prefix, 00082 const XalanDOMString& uri) : 00083 m_prefix(&prefix), 00084 m_uri(&uri) 00085 { 00086 } 00087 00088 /** 00089 * Retrieve the prefix for namespace 00090 * 00091 * @return prefix string 00092 */ 00093 const XalanDOMString& 00094 getPrefix() const 00095 { 00096 assert(m_prefix != 0); 00097 00098 return *m_prefix; 00099 } 00100 00101 /** 00102 * Set the prefix for namespace 00103 * 00104 * @param prefix The new prefix value 00105 */ 00106 void 00107 setPrefix(const XalanDOMString& prefix) 00108 { 00109 m_prefix = &prefix; 00110 } 00111 00112 /** 00113 * Retrieve the URI for namespace 00114 * 00115 * @return URI string 00116 */ 00117 const XalanDOMString& 00118 getURI() const 00119 { 00120 assert(m_uri != 0); 00121 00122 return *m_uri; 00123 } 00124 00125 /** 00126 * Set the URI for namespace 00127 * 00128 * @param uri The new uri value 00129 */ 00130 void 00131 setURI(const XalanDOMString& uri) 00132 { 00133 m_uri = &uri; 00134 } 00135 00136 protected: 00137 00138 static const XalanDOMString s_emptyString; 00139 00140 private: 00141 00142 const XalanDOMString* m_prefix; 00143 00144 const XalanDOMString* m_uri; 00145 }; 00146 00147 class XALAN_XSLT_EXPORT NamespaceExtended : public Namespace 00148 { 00149 public: 00150 00151 NamespaceExtended() : 00152 Namespace(), 00153 m_resultAttributeName(&s_emptyString) 00154 { 00155 } 00156 00157 NamespaceExtended( 00158 const XalanDOMString& prefix, 00159 const XalanDOMString& uri) : 00160 Namespace(prefix, uri), 00161 m_resultAttributeName(&s_emptyString) 00162 { 00163 } 00164 00165 /** 00166 * Retrieve the name of the result attribute. 00167 * 00168 * @return name string 00169 */ 00170 const XalanDOMString& 00171 getResultAttributeName() const 00172 { 00173 assert(m_resultAttributeName != 0); 00174 00175 return *m_resultAttributeName; 00176 } 00177 00178 /** 00179 * Set the name of the result attribute. 00180 * 00181 * @param name The new name value 00182 */ 00183 void 00184 setResultAttributeName(const XalanDOMString& name) 00185 { 00186 m_resultAttributeName = &name; 00187 } 00188 00189 private: 00190 00191 const XalanDOMString* m_resultAttributeName; 00192 }; 00193 00194 typedef XalanQName::NamespaceVectorType NamespaceVectorType; 00195 typedef XalanQName::NamespacesStackType NamespacesStackType; 00196 00197 typedef XalanVector<Namespace> NamespacesVectorType; 00198 typedef XalanVector<NamespaceExtended> NamespaceExtendedVectorType; 00199 typedef XalanVector<const XalanDOMString*> XalanDOMStringPointerVectorType; 00200 00201 typedef XalanMap<const XalanDOMString*, 00202 const XalanDOMString*> NamespaceAliasesMapType; 00203 00204 00205 /** 00206 * Create a default, empty instance. 00207 */ 00208 explicit 00209 NamespacesHandler(MemoryManager& theManager); 00210 00211 /** 00212 * Create an instance namespace handler using the 00213 * current namespaces in effect. 00214 * 00215 * @param theConstructionContext The current construction context. 00216 * @param stylesheetNamespacesHandler The stylesheet's handler. 00217 * @param theCurrentNamespaces The stack of active namespace declarations. 00218 * @param theXSLTNamespaceURI The namespace URI for XSLT. 00219 */ 00220 NamespacesHandler( 00221 StylesheetConstructionContext& theConstructionContext, 00222 const NamespacesHandler& stylesheetNamespacesHandler, 00223 const NamespacesStackType& theCurrentNamespaces, 00224 const XalanDOMString& theXSLTNamespaceURI); 00225 00226 ~NamespacesHandler(); 00227 00228 /** 00229 * Process an exclude-result-prefixes attribute. 00230 * 00231 * @param theConstructionContext The current construction context. 00232 * @param theValue The attribute's value. 00233 * @param theCurrentNamespaces The stack of active namespace declarations. 00234 */ 00235 void 00236 processExcludeResultPrefixes( 00237 StylesheetConstructionContext& theConstructionContext, 00238 const XalanDOMChar* theValue, 00239 const NamespacesStackType& theCurrentNamespaces); 00240 00241 /** 00242 * Process an extension-element-prefixes attribute. 00243 * 00244 * @param theConstructionContext The current construction context. 00245 * @param theValue The attribute's value. 00246 * @param theCurrentNamespaces The stack of active namespace declarations. 00247 */ 00248 void 00249 processExtensionElementPrefixes( 00250 StylesheetConstructionContext& theConstructionContext, 00251 const XalanDOMChar* theValue, 00252 const NamespacesStackType& theCurrentNamespaces); 00253 00254 /** 00255 * Notify the instance that the stylesheet is fully constructed. 00256 * 00257 * @param theConstructionContext The current construction context. 00258 * @param fProcessNamespaceAliases If true, process any namespace aliases 00259 * @param theElementName The name of the owning element. 00260 * @param parentNamespacesHandler The parent handler, if any. 00261 * @param prefixChecker A pointer to a PrefixChecker instance to use, if any. 00262 */ 00263 void 00264 postConstruction( 00265 StylesheetConstructionContext& theConstructionContext, 00266 bool fProcessNamespaceAliases = true, 00267 const XalanDOMString& theElementName = XalanDOMString(XalanMemMgrs::getDummyMemMgr()), 00268 const NamespacesHandler* parentNamespacesHandler = 0, 00269 const PrefixChecker* prefixChecker = 0); 00270 00271 NamespacesHandler& 00272 operator=(const NamespacesHandler& theRHS); 00273 00274 /** 00275 * Determine of a given namespace should be excluded. 00276 * 00277 * @param theXSLTNamespaceURI The namespace URI for XSLT. 00278 * @param theURI The namespace URI. 00279 * @return true of the namespace should be excluded, false if not. 00280 */ 00281 bool 00282 shouldExcludeResultNamespaceNode( 00283 const XalanDOMString& theXSLTNamespaceURI, 00284 const XalanDOMString& theURI) const; 00285 00286 /** 00287 * Add a URI as an extension namespace prefixes. 00288 * 00289 * @param theConstructionContext The current construction context. 00290 * @param theURI The namespace URI. 00291 */ 00292 void 00293 addExtensionNamespaceURI( 00294 StylesheetConstructionContext& theConstructionContext, 00295 const XalanDOMString& theURI); 00296 00297 /** 00298 * Get the namespace URI for the given prefix. 00299 * 00300 * @param thePrefix The namespace prefix. 00301 * @return The namespace URI 00302 */ 00303 const XalanDOMString* 00304 getNamespace(const XalanDOMString& thePrefix) const; 00305 00306 /** 00307 * Get the namespace alias URI for the given namespace. 00308 * 00309 * @param theStylesheetNamespace The namespace as declared in the stylesheet. 00310 * @return The namespace alias URI 00311 */ 00312 const XalanDOMString* 00313 getNamespaceAlias(const XalanDOMString& theStylesheetNamespace) const; 00314 00315 /** 00316 * Set the namespace alias URI for the given namespace. 00317 * 00318 * @param theConstructionContext The current construction context. 00319 * @param theStylesheetNamespace The namespace as declared in the stylesheet. 00320 * @param theResultNamespace The namespace as it should appear in the result tree. 00321 */ 00322 void 00323 setNamespaceAlias( 00324 StylesheetConstructionContext& theConstructionContext, 00325 const XalanDOMString& theStylesheetNamespace, 00326 const XalanDOMString& theResultNamespace); 00327 00328 /** 00329 * Copy the aliases from the given NamespacesHandler. 00330 * 00331 * @param parentNamespacesHandler The parent handler. 00332 */ 00333 void 00334 copyNamespaceAliases(const NamespacesHandler& parentNamespacesHandler); 00335 00336 /** 00337 * Output the result tree namespace declarations. 00338 * 00339 * @param theExecutionContext The current execution context. 00340 * @param supressDefault If true, any default namespace declaration will not be output. 00341 */ 00342 void 00343 outputResultNamespaces( 00344 StylesheetExecutionContext& theExecutionContext, 00345 bool supressDefault = false) const; 00346 00347 /** 00348 * Clear out the handler. 00349 */ 00350 void 00351 clear(); 00352 00353 /** 00354 * Swap the contents of this instance with another. 00355 * 00356 * @param theOther The other instance. 00357 */ 00358 void 00359 swap(NamespacesHandler& theOther); 00360 00361 NamespaceExtendedVectorType::size_type 00362 getNamespaceDeclarationsCount() const 00363 { 00364 return m_namespaceDeclarations.size(); 00365 } 00366 00367 private: 00368 00369 /** 00370 * Create all of the result attribute names. 00371 * 00372 * @param theConstructionContext The current construction context. 00373 */ 00374 void 00375 createResultAttributeNames(StylesheetConstructionContext& theConstructionContext); 00376 00377 /** 00378 * Process the exclude result prefix data. 00379 * 00380 * @param theConstructionContext The current construction context. 00381 * @param theElementPrefix The prefix of the owning element. 00382 * @param prefixChecker A pointer to a PrefixChecker instance to use, if any. 00383 */ 00384 void 00385 processExcludeResultPrefixes( 00386 StylesheetConstructionContext& theConstructionContext, 00387 const XalanDOMString& theElementPrefix, 00388 const PrefixChecker* prefixChecker); 00389 00390 /** 00391 * Process the namespace aliases data. 00392 */ 00393 void 00394 processNamespaceAliases(); 00395 00396 /** 00397 * Copy the contents of the supplied map 00398 * 00399 * @param theNamespaceAliases The map to copy. 00400 */ 00401 void 00402 copyNamespaceAliases(const NamespaceAliasesMapType& theNamespaceAliases); 00403 00404 /** 00405 * Copy the contents of the supplied vector 00406 * 00407 * @param theExtensionNamespaceURIs The set to copy. 00408 */ 00409 void 00410 copyExtensionNamespaceURIs(const XalanDOMStringPointerVectorType& theExtensionNamespaceURIs); 00411 00412 /** 00413 * Copy the contents of the supplied vector 00414 * 00415 * @param theExcludeResultPrefixes The vector to copy. 00416 */ 00417 void 00418 copyExcludeResultPrefixes(const NamespacesVectorType& theExcludeResultPrefixes); 00419 00420 /** 00421 * Determine if a given namespace should be excluded as a result of 00422 * an exclude-result-prefixes declaration. 00423 * 00424 * @param theNamespaceURI The namespace URI to check. 00425 * @return true if the namespace should be excluded, false if not. 00426 */ 00427 bool 00428 isExcludedNamespaceURI(const XalanDOMString& theNamespaceURI) const; 00429 00430 /** 00431 * Determine if a given URI is an extension namespace URI 00432 * 00433 * @param theNamespaceURI The namespace URI to check. 00434 * @return true if the namespace uri is an extension namespace URI, false if not. 00435 */ 00436 bool 00437 isExtensionNamespaceURI(const XalanDOMString& theNamespaceURI) const 00438 { 00439 return findString(theNamespaceURI, m_extensionNamespaceURIs); 00440 } 00441 00442 /** 00443 * Determine if a given string is present in the vector 00444 * 00445 * @param theString The string to find. 00446 * @return true if the string is present, false if not. 00447 */ 00448 static bool 00449 findString( 00450 const XalanDOMString& theString, 00451 const XalanDOMStringPointerVectorType& theVector); 00452 00453 00454 // Not implemented... 00455 bool 00456 operator==(const NamespacesHandler&) const; 00457 00458 00459 // Data members... 00460 NamespacesVectorType m_excludedResultPrefixes; 00461 00462 NamespaceExtendedVectorType m_namespaceDeclarations; 00463 00464 XalanDOMStringPointerVectorType m_extensionNamespaceURIs; 00465 00466 NamespaceAliasesMapType m_namespaceAliases; 00467 }; 00468 00469 00470 00471 XALAN_CPP_NAMESPACE_END 00472 00473 00474 00475 #endif // XALAN_NAMESPACESHANDLER_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 |
|