Xalan-C++ API Reference  1.12.0
NamespacesHandler.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #if !defined(XALAN_NAMESPACESHANDLER_HEADER_GUARD)
20 #define XALAN_NAMESPACESHANDLER_HEADER_GUARD
21 
22 
23 
24 // Base include file. Must be first.
26 
27 
28 
31 
32 
33 
35 
36 
37 
40 
41 
42 
43 namespace XALAN_CPP_NAMESPACE {
44 
45 
46 
47 class StylesheetConstructionContext;
48 class StylesheetExecutionContext;
49 
50 
51 
53 {
54 
55 public:
56 
58  {
59  public:
60 
61  PrefixChecker();
62 
63  virtual
64  ~PrefixChecker();
65 
66  virtual bool
67  isActive(const XalanDOMString& thePrefix) const = 0;
68  };
69 
71  {
72  public:
73 
75  m_prefix(&s_emptyString),
76  m_uri(&s_emptyString)
77  {
78  }
79 
81  const XalanDOMString& prefix,
82  const XalanDOMString& uri) :
83  m_prefix(&prefix),
84  m_uri(&uri)
85  {
86  }
87 
88  /**
89  * Retrieve the prefix for namespace
90  *
91  * @return prefix string
92  */
93  const XalanDOMString&
94  getPrefix() const
95  {
96  assert(m_prefix != 0);
97 
98  return *m_prefix;
99  }
100 
101  /**
102  * Set the prefix for namespace
103  *
104  * @param prefix The new prefix value
105  */
106  void
107  setPrefix(const XalanDOMString& prefix)
108  {
109  m_prefix = &prefix;
110  }
111 
112  /**
113  * Retrieve the URI for namespace
114  *
115  * @return URI string
116  */
117  const XalanDOMString&
118  getURI() const
119  {
120  assert(m_uri != 0);
121 
122  return *m_uri;
123  }
124 
125  /**
126  * Set the URI for namespace
127  *
128  * @param uri The new uri value
129  */
130  void
131  setURI(const XalanDOMString& uri)
132  {
133  m_uri = &uri;
134  }
135 
136  protected:
137 
139 
140  private:
141 
142  const XalanDOMString* m_prefix;
143 
144  const XalanDOMString* m_uri;
145  };
146 
148  {
149  public:
150 
152  Namespace(),
153  m_resultAttributeName(&s_emptyString)
154  {
155  }
156 
158  const XalanDOMString& prefix,
159  const XalanDOMString& uri) :
160  Namespace(prefix, uri),
161  m_resultAttributeName(&s_emptyString)
162  {
163  }
164 
165  /**
166  * Retrieve the name of the result attribute.
167  *
168  * @return name string
169  */
170  const XalanDOMString&
172  {
173  assert(m_resultAttributeName != 0);
174 
175  return *m_resultAttributeName;
176  }
177 
178  /**
179  * Set the name of the result attribute.
180  *
181  * @param name The new name value
182  */
183  void
185  {
186  m_resultAttributeName = &name;
187  }
188 
189  private:
190 
191  const XalanDOMString* m_resultAttributeName;
192  };
193 
196 
200 
201  typedef XalanMap<const XalanDOMString*,
203 
204 
205  /**
206  * Create a default, empty instance.
207  */
208  explicit
209  NamespacesHandler(MemoryManager& theManager);
210 
211  /**
212  * Create an instance namespace handler using the
213  * current namespaces in effect.
214  *
215  * @param theConstructionContext The current construction context.
216  * @param stylesheetNamespacesHandler The stylesheet's handler.
217  * @param theCurrentNamespaces The stack of active namespace declarations.
218  * @param theXSLTNamespaceURI The namespace URI for XSLT.
219  */
221  StylesheetConstructionContext& theConstructionContext,
222  const NamespacesHandler& stylesheetNamespacesHandler,
223  const NamespacesStackType& theCurrentNamespaces,
224  const XalanDOMString& theXSLTNamespaceURI);
225 
227 
228  /**
229  * Process an exclude-result-prefixes attribute.
230  *
231  * @param theConstructionContext The current construction context.
232  * @param theValue The attribute's value.
233  * @param theCurrentNamespaces The stack of active namespace declarations.
234  */
235  void
236  processExcludeResultPrefixes(
237  StylesheetConstructionContext& theConstructionContext,
238  const XalanDOMChar* theValue,
239  const NamespacesStackType& theCurrentNamespaces);
240 
241  /**
242  * Process an extension-element-prefixes attribute.
243  *
244  * @param theConstructionContext The current construction context.
245  * @param theValue The attribute's value.
246  * @param theCurrentNamespaces The stack of active namespace declarations.
247  */
248  void
249  processExtensionElementPrefixes(
250  StylesheetConstructionContext& theConstructionContext,
251  const XalanDOMChar* theValue,
252  const NamespacesStackType& theCurrentNamespaces);
253 
254  /**
255  * Notify the instance that the stylesheet is fully constructed.
256  *
257  * @param theConstructionContext The current construction context.
258  * @param fProcessNamespaceAliases If true, process any namespace aliases
259  * @param theElementName The name of the owning element.
260  * @param parentNamespacesHandler The parent handler, if any.
261  * @param prefixChecker A pointer to a PrefixChecker instance to use, if any.
262  */
263  void
264  postConstruction(
265  StylesheetConstructionContext& theConstructionContext,
266  bool fProcessNamespaceAliases = true,
267  const XalanDOMString& theElementName = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
268  const NamespacesHandler* parentNamespacesHandler = 0,
269  const PrefixChecker* prefixChecker = 0);
270 
272  operator=(const NamespacesHandler& theRHS);
273 
274  /**
275  * Determine of a given namespace should be excluded.
276  *
277  * @param theXSLTNamespaceURI The namespace URI for XSLT.
278  * @param theURI The namespace URI.
279  * @return true of the namespace should be excluded, false if not.
280  */
281  bool
282  shouldExcludeResultNamespaceNode(
283  const XalanDOMString& theXSLTNamespaceURI,
284  const XalanDOMString& theURI) const;
285 
286  /**
287  * Add a URI as an extension namespace prefixes.
288  *
289  * @param theConstructionContext The current construction context.
290  * @param theURI The namespace URI.
291  */
292  void
293  addExtensionNamespaceURI(
294  StylesheetConstructionContext& theConstructionContext,
295  const XalanDOMString& theURI);
296 
297  /**
298  * Get the namespace URI for the given prefix.
299  *
300  * @param thePrefix The namespace prefix.
301  * @return The namespace URI
302  */
303  const XalanDOMString*
304  getNamespace(const XalanDOMString& thePrefix) const;
305 
306  /**
307  * Get the namespace alias URI for the given namespace.
308  *
309  * @param theStylesheetNamespace The namespace as declared in the stylesheet.
310  * @return The namespace alias URI
311  */
312  const XalanDOMString*
313  getNamespaceAlias(const XalanDOMString& theStylesheetNamespace) const;
314 
315  /**
316  * Set the namespace alias URI for the given namespace.
317  *
318  * @param theConstructionContext The current construction context.
319  * @param theStylesheetNamespace The namespace as declared in the stylesheet.
320  * @param theResultNamespace The namespace as it should appear in the result tree.
321  */
322  void
323  setNamespaceAlias(
324  StylesheetConstructionContext& theConstructionContext,
325  const XalanDOMString& theStylesheetNamespace,
326  const XalanDOMString& theResultNamespace);
327 
328  /**
329  * Copy the aliases from the given NamespacesHandler.
330  *
331  * @param parentNamespacesHandler The parent handler.
332  */
333  void
334  copyNamespaceAliases(const NamespacesHandler& parentNamespacesHandler);
335 
336  /**
337  * Output the result tree namespace declarations.
338  *
339  * @param theExecutionContext The current execution context.
340  * @param supressDefault If true, any default namespace declaration will not be output.
341  */
342  void
343  outputResultNamespaces(
344  StylesheetExecutionContext& theExecutionContext,
345  bool supressDefault = false) const;
346 
347  /**
348  * Clear out the handler.
349  */
350  void
351  clear();
352 
353  /**
354  * Swap the contents of this instance with another.
355  *
356  * @param theOther The other instance.
357  */
358  void
359  swap(NamespacesHandler& theOther);
360 
363  {
364  return m_namespaceDeclarations.size();
365  }
366 
367 private:
368 
369  /**
370  * Create all of the result attribute names.
371  *
372  * @param theConstructionContext The current construction context.
373  */
374  void
375  createResultAttributeNames(StylesheetConstructionContext& theConstructionContext);
376 
377  /**
378  * Process the exclude result prefix data.
379  *
380  * @param theConstructionContext The current construction context.
381  * @param theElementPrefix The prefix of the owning element.
382  * @param prefixChecker A pointer to a PrefixChecker instance to use, if any.
383  */
384  void
385  processExcludeResultPrefixes(
386  StylesheetConstructionContext& theConstructionContext,
387  const XalanDOMString& theElementPrefix,
388  const PrefixChecker* prefixChecker);
389 
390  /**
391  * Process the namespace aliases data.
392  */
393  void
394  processNamespaceAliases();
395 
396  /**
397  * Copy the contents of the supplied map
398  *
399  * @param theNamespaceAliases The map to copy.
400  */
401  void
402  copyNamespaceAliases(const NamespaceAliasesMapType& theNamespaceAliases);
403 
404  /**
405  * Copy the contents of the supplied vector
406  *
407  * @param theExtensionNamespaceURIs The set to copy.
408  */
409  void
410  copyExtensionNamespaceURIs(const XalanDOMStringPointerVectorType& theExtensionNamespaceURIs);
411 
412  /**
413  * Copy the contents of the supplied vector
414  *
415  * @param theExcludeResultPrefixes The vector to copy.
416  */
417  void
418  copyExcludeResultPrefixes(const NamespacesVectorType& theExcludeResultPrefixes);
419 
420  /**
421  * Determine if a given namespace should be excluded as a result of
422  * an exclude-result-prefixes declaration.
423  *
424  * @param theNamespaceURI The namespace URI to check.
425  * @return true if the namespace should be excluded, false if not.
426  */
427  bool
428  isExcludedNamespaceURI(const XalanDOMString& theNamespaceURI) const;
429 
430  /**
431  * Determine if a given URI is an extension namespace URI
432  *
433  * @param theNamespaceURI The namespace URI to check.
434  * @return true if the namespace uri is an extension namespace URI, false if not.
435  */
436  bool
437  isExtensionNamespaceURI(const XalanDOMString& theNamespaceURI) const
438  {
439  return findString(theNamespaceURI, m_extensionNamespaceURIs);
440  }
441 
442  /**
443  * Determine if a given string is present in the vector
444  *
445  * @param theString The string to find.
446  * @return true if the string is present, false if not.
447  */
448  static bool
449  findString(
450  const XalanDOMString& theString,
451  const XalanDOMStringPointerVectorType& theVector);
452 
453 
454  // Not implemented...
455  bool
456  operator==(const NamespacesHandler&) const;
457 
458 
459  // Data members...
460  NamespacesVectorType m_excludedResultPrefixes;
461 
462  NamespaceExtendedVectorType m_namespaceDeclarations;
463 
464  XalanDOMStringPointerVectorType m_extensionNamespaceURIs;
465 
466  NamespaceAliasesMapType m_namespaceAliases;
467 };
468 
469 
470 
471 }
472 
473 
474 
475 #endif // XALAN_NAMESPACESHANDLER_HEADER_GUARD
xalanc::NamespacesHandler::NamespaceExtended
Definition: NamespacesHandler.hpp:147
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::NamespacesHandler::Namespace::getPrefix
const XalanDOMString & getPrefix() const
Retrieve the prefix for namespace.
Definition: NamespacesHandler.hpp:94
xalanc::NamespacesHandler::Namespace::Namespace
Namespace(const XalanDOMString &prefix, const XalanDOMString &uri)
Definition: NamespacesHandler.hpp:80
xalanc::NamespacesHandler::NamespacesStackType
XalanQName::NamespacesStackType NamespacesStackType
Definition: NamespacesHandler.hpp:195
xalanc::clear
void clear(XalanDOMString &theString)
Remove all elements from target string.
Definition: DOMStringHelper.hpp:2475
xalanc::StylesheetExecutionContext
Definition: StylesheetExecutionContext.hpp:106
xalanc::NamespacesHandler::NamespaceExtended::NamespaceExtended
NamespaceExtended(const XalanDOMString &prefix, const XalanDOMString &uri)
Definition: NamespacesHandler.hpp:157
xalanc::NamespacesHandler::Namespace::getURI
const XalanDOMString & getURI() const
Retrieve the URI for namespace.
Definition: NamespacesHandler.hpp:118
xalanc::XalanVector< Namespace >
XALAN_XSLT_EXPORT
#define XALAN_XSLT_EXPORT
Definition: XSLTDefinitions.hpp:27
xalanc::swap
void swap(XalanVector< Type > &theLHS, XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1107
XalanVector.hpp
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::NamespacesHandler::XalanDOMStringPointerVectorType
XalanVector< const XalanDOMString * > XalanDOMStringPointerVectorType
Definition: NamespacesHandler.hpp:199
XalanQName.hpp
xalanc::NamespacesHandler
Definition: NamespacesHandler.hpp:52
xalanc::NamespacesHandler::getNamespaceDeclarationsCount
NamespaceExtendedVectorType::size_type getNamespaceDeclarationsCount() const
Definition: NamespacesHandler.hpp:362
DOMStringHelper.hpp
xalanc::XalanDeque
Xalan implementation of deque.
Definition: XalanDeque.hpp:200
xalanc::NamespacesHandler::PrefixChecker
Definition: NamespacesHandler.hpp:57
xalanc::NamespacesHandler::NamespaceExtendedVectorType
XalanVector< NamespaceExtended > NamespaceExtendedVectorType
Definition: NamespacesHandler.hpp:198
NameSpace.hpp
xalanc::NamespacesHandler::NamespaceVectorType
XalanQName::NamespaceVectorType NamespaceVectorType
Definition: NamespacesHandler.hpp:194
xalanc::NamespacesHandler::Namespace::Namespace
Namespace()
Definition: NamespacesHandler.hpp:74
xalanc::StylesheetConstructionContext
Definition: StylesheetConstructionContext.hpp:83
xalanc::NamespacesHandler::Namespace::setPrefix
void setPrefix(const XalanDOMString &prefix)
Set the prefix for namespace.
Definition: NamespacesHandler.hpp:107
xalanc::NamespacesHandler::NamespaceExtended::NamespaceExtended
NamespaceExtended()
Definition: NamespacesHandler.hpp:151
xalanc::NamespacesHandler::Namespace
Definition: NamespacesHandler.hpp:70
xalanc::XalanMap
Xalan implementation of a hashtable.
Definition: XalanMap.hpp:186
xalanc::NamespacesHandler::NamespaceExtended::getResultAttributeName
const XalanDOMString & getResultAttributeName() const
Retrieve the name of the result attribute.
Definition: NamespacesHandler.hpp:171
xalanc::NamespacesHandler::NamespaceAliasesMapType
XalanMap< const XalanDOMString *, const XalanDOMString * > NamespaceAliasesMapType
Definition: NamespacesHandler.hpp:202
XalanMap.hpp
XSLTDefinitions.hpp
xalanc::NamespacesHandler::Namespace::s_emptyString
static const XalanDOMString s_emptyString
Definition: NamespacesHandler.hpp:138
xalanc::NamespacesHandler::NamespaceExtended::setResultAttributeName
void setResultAttributeName(const XalanDOMString &name)
Set the name of the result attribute.
Definition: NamespacesHandler.hpp:184
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::NamespacesHandler::Namespace::setURI
void setURI(const XalanDOMString &uri)
Set the URI for namespace.
Definition: NamespacesHandler.hpp:131
xalanc::NamespacesHandler::NamespacesVectorType
XalanVector< Namespace > NamespacesVectorType
Definition: NamespacesHandler.hpp:197
xalanc::XalanVector< NamespaceExtended >::size_type
size_t size_type
Definition: XalanVector.hpp:68