Xalan-C++ API Reference  1.12.0
StylesheetRoot.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 #if !defined(XALAN_STYLESHEETROOT_HEADER_GUARD)
19 #define XALAN_STYLESHEETROOT_HEADER_GUARD
20 
21 
22 
23 // Base include file. Must be first.
24 #include "XSLTDefinitions.hpp"
25 
26 
27 
28 #include "Stylesheet.hpp"
29 
30 
31 
34 
35 
36 
38 
39 
40 
42 
43 
44 
45 namespace XALAN_CPP_NAMESPACE {
46 
47 
48 
49 class ElemAttributeSet;
50 class StylesheetConstructionContext;
51 class XalanText;
53 
54 
57 
58 /**
59  * This acts as the stylesheet root of the stylesheet
60  * tree, and holds values that are shared by all
61  * stylesheets in the tree.
62  */
64 {
65 public:
66 
68 
70 
71  typedef XalanMap<const XalanQName*,
73 
74  /**
75  * Construct a Stylesheet from a Document.
76  *
77  * @param baseIdentifier document identifier
78  * @param constructionContext context for construction of object
79  */
81  const XalanDOMString& baseIdentifier,
82  StylesheetConstructionContext& constructionContext);
83 
84  virtual
85  ~StylesheetRoot();
86 
87  static StylesheetRoot*
88  create(
89  MemoryManager& theManager,
90  const XalanDOMString& baseIdentifier,
91  StylesheetConstructionContext& constructionContext);
92 
93  MemoryManager&
95  {
96  return m_version.getMemoryManager();
97  }
98  /**
99  * Called after construction is completed.
100  */
101  virtual void
102  postConstruction(StylesheetConstructionContext& constructionContext);
103 
104  /**
105  * Transform the source tree to the output in the given result tree target.
106  *
107  * @param inputSource The input source
108  * @param outputTarget The output result target
109  * @param constructionContext context for construction of object
110  */
111  void
112  process(
113  XalanNode* sourceTree,
114  XSLTResultTarget& outputTarget,
115  StylesheetExecutionContext& executionContext) const;
116 
117  /**
118  * Have the stylesheet create the appropriate FormatterListener,
119  * based on the XSLTResultTarget provided. setupFormatterListener
120  * also calls setFormatterListener() on the execution context
121  * instance. setupFormatterListener() is done automatically by
122  * process(), but this is provided as an escape, to allow for
123  * changing the FormatterListener on-the-fly.
124  *
125  * @param outputTarget The output source tree
126  * @param constructionContext context for construction of object
127  * @return a pointer to the new FormatterListener instance.
128  */
130  setupFormatterListener(
131  XSLTResultTarget& outputTarget,
132  StylesheetExecutionContext& executionContext) const;
133 
134  /**
135  * Return the output method that was specified in the stylesheet.
136  * The returned value is one of FormatterLister::eFormat values.
137  *
138  * @return value of output method
139  */
142  {
143  return m_outputMethod;
144  }
145 
146  bool
148  {
149  return getOutputMethod() == FormatterListener::OUTPUT_METHOD_NONE ? false : true;
150  }
151 
152  /**
153  * Get the output version string that was specified in the
154  * xsl:output element
155  *
156  * @return output version string
157  */
160  {
161  theResult.assign(m_version);
162 
163  return theResult;
164  }
165 
166  /**
167  * Determine if output indenting was specified in the
168  * xsl:output element
169  *
170  * @return true to indent
171  */
172  bool
174  {
175  return m_indentResult == eIndentNoImplicit ||
176  m_indentResult == eIndentNoExplicit ? false : true;
177  }
178 
179  /**
180  * Determine if output indenting should be
181  * enabled for HTML output. Semantically,
182  * this implies the output method is implicit,
183  * not explicit, but we don't really check that.
184  *
185  * @return true to indent
186  */
187  bool
189  {
190  return m_indentResult == eIndentNoExplicit ? false : true;
191  }
192 
193  /**
194  * Get the output encoding string that was specified in the
195  * xsl:output element
196  *
197  * @return encoding string
198  */
201  {
202  theResult.assign(m_encoding);
203 
204  return theResult;
205  }
206 
207  /**
208  * Get the media-type string that was specified in the
209  * xsl:output element
210  *
211  * @return media type string
212  */
215  {
216  theResult.assign(m_mediatype);
217 
218  return theResult;
219  }
220 
221  /**
222  * Get the doctype-system-id string that was specified in the
223  * xsl:output element
224  *
225  * @return document type string
226  */
229  {
230  theResult.assign(m_doctypeSystem);
231 
232  return theResult;
233  }
234 
235  /**
236  * Get the doctype-public-id string that was specified in the
237  * xsl:output element
238  *
239  * @return document type public id string
240  */
243  {
244  theResult.assign(m_doctypePublic);
245 
246  return theResult;
247  }
248 
249  /**
250  * Determine whether to output XML declarations.
251  *
252  * @return true to output declarations
253  */
254  bool
256  {
257  return m_omitxmlDecl;
258  }
259 
260  /**
261  * Get the standalone string that was specified in the
262  * xsl:output element.(either "yes" or "no")
263  *
264  * @return standalone string
265  */
268  {
269  theResult.assign(m_standalone);
270 
271  return theResult;
272  }
273 
274  /**
275  * Get the template representing the default rule for text.
276  *
277  * @return pointer to template rule for text
278  */
281  {
282  return m_defaultTextRule;
283  }
284 
285  /**
286  * Get the template representing the default rule.
287  *
288  * @return pointer to default template rule
289  */
292  {
293  return m_defaultRule;
294  }
295 
296  /**
297  * Get the template representing the default root rule.
298  *
299  * @return pointer to default root template rule
300  */
303  {
304  return m_defaultRootRule;
305  }
306 
307  /**
308  * Process the "xsl:output" element.
309  *
310  * @param name name of element
311  * @param atts attribute list for element
312  * @param constructionContext context for construction of object
313  */
314  void
315  processOutputSpec(
316  const XalanDOMChar* name,
317  const AttributeListType& atts,
318  StylesheetConstructionContext& constructionContext);
319 
320  /**
321  * Retrieve the stack of imported stylesheets.
322  *
323  * @return stack of URIs for stylesheets
324  */
325  URLStackType&
327  {
328  return m_importStack;
329  }
330 
331  /**
332  * Retrieve the stack of imported stylesheets.
333  *
334  * @return const stack of URIs for stylesheets
335  */
336  const URLStackType&
338  {
339  return m_importStack;
340  }
341 
342  /**
343  * Change the value of the flag for indenting results.
344  *
345  * @param bIndent true to indent results
346  */
347  void
348  setIndentResult(bool bIndent)
349  {
350  m_indentResult = bIndent == true ? eIndentYesExplicit : eIndentNoExplicit;
351  }
352 
353  /**
354  * Change the value of the output method, one of the
355  * FormatterListener::eFormat values.
356  *
357  * @param meth new method number
358  */
359  void
361  {
362  m_outputMethod = meth;
363  }
364 
365  bool
367  {
368  assert((m_hasCDATASectionElems == false && m_cdataSectionElems.empty() == true ) ||
369  ( m_hasCDATASectionElems == true && m_cdataSectionElems.empty() == false));
370 
371  return m_hasCDATASectionElems;
372  }
373 
374  /**
375  * Determine if a QName is in the list of CDATA section
376  * element QNames.
377  *
378  * @param theQName The QName of the element to check.
379  * @return true or false
380  */
381  bool
382  isCDATASectionElementName(const XalanQName& theQName) const;
383 
384  /**
385  * Given a valid element key, return the corresponding node list.
386  *
387  * @param context context node
388  * @param qname qname of the key, which must match the 'name'
389  * attribute on xsl:key
390  * @param ref value that must match the value found by the
391  * 'match' attribute on xsl:key
392  * @param resolver resolver for namespace resolution
393  * @param nodelist A node list to contain the nodes found
394  * @param executionContext The current execution context
395  * @param theKeysTable The table of keys to search.
396  */
397  void
398  getNodeSetByKey(
399  XalanNode* context,
400  const XalanQName& qname,
401  const XalanDOMString& ref,
402  const PrefixResolver& resolver,
403  MutableNodeRefList& nodelist,
404  StylesheetExecutionContext& executionContext,
405  const Locator* locator,
406  KeyTablesTableType& theKeysTable) const;
407 
408  unsigned long
410  {
411  return m_elemNumberNextID++;
412  }
413 
414  unsigned long
416  {
417  return m_elemNumberNextID;
418  }
419 
420  bool
422  {
423  return m_hasStripOrPreserveSpace;
424  }
425 
426  /**
427  * Check to see if a whitespace text node should be stripped from
428  * the source tree.
429  *
430  * @param theNode The text node to check.
431  */
432  bool
433  shouldStripSourceNode(const XalanText& theNode) const
434  {
435  if (hasPreserveOrStripSpaceElements() == true &&
436  theNode.isWhitespace() == true)
437  {
438  return internalShouldStripSourceNode(theNode);
439  }
440 
441  return false;
442  }
443 
444  void
445  addAttributeSet(ElemAttributeSet& theAttributeSet);
446 
447 #if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION)
448  /**
449  * Get the nth attribute set with the specified name.
450  *
451  * @param execution context for executing this stylesheet
452  * @param theQName the name of the attribute set
453  * @param matchingIndex index of the attribute set with the specified name
454  * @param theLocator the locator
455  * @returns a pointer to the attribute, 0 if no matching attribute set
456  */
457  const ElemAttributeSet*
458  getAttributeSet(
459  StylesheetExecutionContext& theExecutionContext,
460  const XalanQName& theQName,
461  size_type matchingIndex,
462  const Locator* theLocator) const;
463 #else
464  void
465  executeAttributeSet(
466  StylesheetExecutionContext& theExecutionContext,
467  const XalanQName& theQName,
468  const Locator* theLocator) const;
469 #endif
470 
471 
472 private:
473 
474  /**
475  * Choose the encoding to use.
476  *
477  * @param outputTarget The output result target
478  *
479  * @return The chosen encoding
480  */
481  const XalanDOMString&
482  getEncoding(const XSLTResultTarget& outputTarget) const;
483 
484  /**
485  * Create the default rule if needed.
486  *
487  * @param constructionContext context for construction of object
488  */
489  void
490  initDefaultRule(StylesheetConstructionContext& constructionContext);
491 
492  /**
493  * Check to see if a whitespace text node should be stripped from
494  * the source tree.
495  *
496  * @param theNode The text node to check.
497  */
498  bool
499  internalShouldStripSourceNode(const XalanText& theNode) const;
500 
501  /**
502  * The version tells the version of XML to be used for outputting the result tree,
503  * as specified in xsl:output.
504  */
505  XalanDOMString m_version;
506 
507  enum eIndentType { eIndentNoImplicit, eIndentNoExplicit, eIndentYesImplicit, eIndentYesExplicit };
508 
509  /**
510  * indent-result is by default no, which means an XSL processor must not
511  * change the whitespace on output.
512  */
513  eIndentType m_indentResult;
514 
515  /**
516  * The encoding attribute specifies the preferred encoding to use
517  * for outputting the result tree.
518  */
519  XalanDOMString m_encoding;
520 
521  /**
522  * The media-type attribute is applicable for the xml output method.
523  * The default value for the media-type attribute is text/xml.
524  */
525  XalanDOMString m_mediatype;
526 
527  /**
528  * If the doctype-system-id attribute is specified, the xml output method should
529  * output a document type declaration immediately before the first element.
530  * The name following <!DOCTYPE should be the name of the first element.
531  */
532  XalanDOMString m_doctypeSystem;
533 
534  /**
535  * If doctype-public-id attribute is also specified, then the xml output
536  * method should output PUBLIC followed by the public identifier and then
537  * the system identifier; otherwise, it should output SYSTEM followed by
538  * the system identifier. The internal subset should be empty. The
539  * doctype-public-id attribute should be ignored unless the doctype-system-id
540  * attribute is specified.
541  */
542  XalanDOMString m_doctypePublic;
543 
544  /**
545  * Tells whether or not to output an XML declaration.
546  */
547  bool m_omitxmlDecl;
548 
549  /**
550  * Tells what the xmldecl should specify for the standalone value.
551  */
552  XalanDOMString m_standalone;
553 
554  /**
555  * The URL that belongs to the result namespace.
556  * @serial
557  */
558  XalanDOMString m_resultNameSpaceURL;
559 
560  /**
561  * The output method as specified in xsl:output.
562  */
563  FormatterListener::eFormat m_outputMethod;
564 
565  /**
566  * Vector of qnames that specifies elements that should be formatted
567  * as CDATA.
568  */
569  XalanQNameVectorType m_cdataSectionElems;
570 
571  bool m_hasCDATASectionElems;
572 
573  /**
574  * A stack of who's importing whom is needed in order to detect
575  * a recursive include or import, which is an error.
576  */
577  URLStackType m_importStack;
578 
579 
580  /**
581  * The default template to use for text nodes if we don't find
582  * anything else. This is initialized in initDefaultRule().
583  */
584  ElemTemplateElement* m_defaultTextRule;
585 
586  /**
587  * The default template to use if we don't find anything
588  * else. This is initialized in initDefaultRule().
589  */
590  ElemTemplateElement* m_defaultRule;
591 
592  /**
593  * The default template to use for the root if we don't find
594  * anything else. This is initialized in initDefaultRule().
595  */
596  ElemTemplateElement* m_defaultRootRule;
597 
598  /**
599  * This is set to true if an xsl:key directive is found.
600  */
601  bool m_needToBuildKeysTable;
602 
603  /**
604  * This is set to true if URLs should be escaped in HTML output (the default)
605  */
606  bool m_outputEscapeURLs;
607 
608  /**
609  * The amount to indent. The default is -1, which indicates not to indent.
610  */
611  int m_indentAmount;
612 
613  /**
614  * This is set to true if we should omit the META tag in HTML output (the default is false)
615  */
616  bool m_omitMETATag;
617 
618  /**
619  * This is set to true if we should omit the META tag in HTML output (the default is false)
620  */
621  unsigned long m_elemNumberNextID;
622 
623  /**
624  * A lookup table of all attribute sets.
625  */
626  AttributeSetMapType m_attributeSetsMap;
627 
628  /**
629  * true if there are any whitespace strip or preserve
630  * elements.
631  */
632  bool m_hasStripOrPreserveSpace;
633 
634 
635  // Not implemented...
636  StylesheetRoot(const StylesheetRoot&);
637 
638  StylesheetRoot&
639  operator=(const StylesheetRoot&);
640 
641  bool
642  operator==(const StylesheetRoot&) const;
643 };
644 
645 
646 
647 }
648 
649 
650 
651 #endif // XALAN_STYLESHEETROOT_HEADER_GUARD
xalanc::StylesheetRoot::getOmitOutputXMLDecl
bool getOmitOutputXMLDecl() const
Determine whether to output XML declarations.
Definition: StylesheetRoot.hpp:255
xalanc::StylesheetRoot::getOutputMediaType
XalanDOMString & getOutputMediaType(XalanDOMString &theResult) const
Get the media-type string that was specified in the xsl:output element.
Definition: StylesheetRoot.hpp:214
xalanc::StylesheetRoot::isOutputMethodSet
bool isOutputMethodSet() const
Definition: StylesheetRoot.hpp:147
xalanc::StylesheetRoot::getImportStack
URLStackType & getImportStack()
Retrieve the stack of imported stylesheets.
Definition: StylesheetRoot.hpp:326
xalanc::XalanDOMString::assign
XalanDOMString & assign(const XalanDOMChar *theSource)
Definition: XalanDOMString.hpp:390
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::AttributeListType
xercesc::AttributeList AttributeListType
Definition: AttributeListImpl.hpp:41
xalanc::StylesheetRoot::getOutputEncoding
XalanDOMString & getOutputEncoding(XalanDOMString &theResult) const
Get the output encoding string that was specified in the xsl:output element.
Definition: StylesheetRoot.hpp:200
xalanc::ElemAttributeSet
Definition: ElemAttributeSet.hpp:37
xalanc::StylesheetExecutionContext
Definition: StylesheetExecutionContext.hpp:106
xalanc::StylesheetRoot::getOutputMethod
FormatterListener::eFormat getOutputMethod() const
Return the output method that was specified in the stylesheet.
Definition: StylesheetRoot.hpp:141
xalanc::StylesheetRoot::getDefaultTextRule
ElemTemplateElement * getDefaultTextRule() const
Get the template representing the default rule for text.
Definition: StylesheetRoot.hpp:280
xalanc::XalanNode
Definition: XalanNode.hpp:38
xalanc::XalanText::isWhitespace
virtual bool isWhitespace() const =0
Determine whether the text node instance is composed entirely of XML whitespace.
xalanc::StylesheetRoot::getOutputDoctypePublic
XalanDOMString & getOutputDoctypePublic(XalanDOMString &theResult) const
Get the doctype-public-id string that was specified in the xsl:output element.
Definition: StylesheetRoot.hpp:242
XalanDOMString.hpp
xalanc::XalanVector
Definition: XalanVector.hpp:58
xalanc::XalanText
Definition: XalanText.hpp:40
XALAN_USES_MEMORY_MANAGER
#define XALAN_USES_MEMORY_MANAGER(Type)
Definition: XalanMemoryManagement.hpp:589
xalanc::MutableNodeRefList
Local implementation of MutableNodeRefList.
Definition: MutableNodeRefList.hpp:46
XALAN_XSLT_EXPORT
#define XALAN_XSLT_EXPORT
Definition: XSLTDefinitions.hpp:27
FormatterListener.hpp
xalanc::StylesheetRoot::getElemNumberCount
unsigned long getElemNumberCount() const
Definition: StylesheetRoot.hpp:415
xalanc::StylesheetRoot::getDefaultRootRule
ElemTemplateElement * getDefaultRootRule() const
Get the template representing the default root rule.
Definition: StylesheetRoot.hpp:302
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::StylesheetRoot::AttributeSetVectorType
AttributeSetVectorTypeDecl AttributeSetVectorType
Definition: StylesheetRoot.hpp:69
xalanc::ElemTemplateElement
Definition: ElemTemplateElement.hpp:79
xalanc::StylesheetRoot::getOutputVersion
XalanDOMString & getOutputVersion(XalanDOMString &theResult) const
Get the output version string that was specified in the xsl:output element.
Definition: StylesheetRoot.hpp:159
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::XSLTResultTarget
Definition: XSLTResultTarget.hpp:45
STLHelper.hpp
xalanc::FormatterListener::eFormat
eFormat
Definition: FormatterListener.hpp:65
xalanc::StylesheetRoot::getMemoryManager
MemoryManager & getMemoryManager()
Definition: StylesheetRoot.hpp:94
xalanc::StylesheetRoot::getHTMLOutputIndent
bool getHTMLOutputIndent() const
Determine if output indenting should be enabled for HTML output.
Definition: StylesheetRoot.hpp:188
xalanc::StylesheetRoot::getDefaultRule
ElemTemplateElement * getDefaultRule() const
Get the template representing the default rule.
Definition: StylesheetRoot.hpp:291
xalanc::StylesheetConstructionContext
Definition: StylesheetConstructionContext.hpp:83
xalanc::StylesheetRoot::setIndentResult
void setIndentResult(bool bIndent)
Change the value of the flag for indenting results.
Definition: StylesheetRoot.hpp:348
xalanc::StylesheetRoot::getOutputStandalone
XalanDOMString & getOutputStandalone(XalanDOMString &theResult) const
Get the standalone string that was specified in the xsl:output element.
Definition: StylesheetRoot.hpp:267
xalanc::StylesheetRoot::getNextElemNumberID
unsigned long getNextElemNumberID()
Definition: StylesheetRoot.hpp:409
xalanc::PrefixResolver
This class defines an interface for classes that resolve namespace prefixes to their URIs.
Definition: PrefixResolver.hpp:39
xalanc::XalanMap
Xalan implementation of a hashtable.
Definition: XalanMap.hpp:186
xalanc::StylesheetRoot::shouldStripSourceNode
bool shouldStripSourceNode(const XalanText &theNode) const
Check to see if a whitespace text node should be stripped from the source tree.
Definition: StylesheetRoot.hpp:433
xalanc::AttributeSetVectorTypeDecl
XalanVector< ElemAttributeSet * > AttributeSetVectorTypeDecl
Definition: StylesheetRoot.hpp:52
xalanc::StylesheetRoot::hasPreserveOrStripSpaceElements
bool hasPreserveOrStripSpaceElements() const
Definition: StylesheetRoot.hpp:421
XalanMap.hpp
xalanc::StylesheetRoot
This acts as the stylesheet root of the stylesheet tree, and holds values that are shared by all styl...
Definition: StylesheetRoot.hpp:63
XSLTDefinitions.hpp
xalanc::StylesheetRoot::getImportStack
const URLStackType & getImportStack() const
Retrieve the stack of imported stylesheets.
Definition: StylesheetRoot.hpp:337
xalanc::Stylesheet
This class represents the base stylesheet or an "import" stylesheet.
Definition: Stylesheet.hpp:86
xalanc::FormatterListener
A SAX-based formatter interface for the XSL processor.
Definition: FormatterListener.hpp:56
xalanc::XalanQName
Class to represent a qualified name.
Definition: XalanQName.hpp:70
xalanc::StylesheetRoot::getOutputIndent
bool getOutputIndent() const
Determine if output indenting was specified in the xsl:output element.
Definition: StylesheetRoot.hpp:173
xalanc::StylesheetRoot::XalanQNameVectorType
XalanVector< const XalanQName * > XalanQNameVectorType
Definition: StylesheetRoot.hpp:67
xalanc::StylesheetRoot::getOutputDoctypeSystem
XalanDOMString & getOutputDoctypeSystem(XalanDOMString &theResult) const
Get the doctype-system-id string that was specified in the xsl:output element.
Definition: StylesheetRoot.hpp:228
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::StylesheetRoot::hasCDATASectionElements
bool hasCDATASectionElements() const
Definition: StylesheetRoot.hpp:366
xalanc::StylesheetRoot::AttributeSetMapType
XalanMap< const XalanQName *, AttributeSetVectorType > AttributeSetMapType
Definition: StylesheetRoot.hpp:72
xalanc::StylesheetRoot::setOutputMethod
void setOutputMethod(FormatterListener::eFormat meth)
Change the value of the output method, one of the FormatterListener::eFormat values.
Definition: StylesheetRoot.hpp:360
Stylesheet.hpp