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_STYLESHEETROOT_HEADER_GUARD) 00019 #define XALAN_STYLESHEETROOT_HEADER_GUARD 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include "XSLTDefinitions.hpp" 00025 00026 00027 00028 #include "Stylesheet.hpp" 00029 00030 00031 00032 #include <xalanc/Include/XalanMap.hpp> 00033 #include <xalanc/Include/STLHelper.hpp> 00034 00035 00036 00037 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00038 00039 00040 00041 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00042 00043 00044 00045 XALAN_CPP_NAMESPACE_BEGIN 00046 00047 00048 00049 class ElemAttributeSet; 00050 class StylesheetConstructionContext; 00051 class XalanText; 00052 class XSLTResultTarget; 00053 00054 00055 typedef XalanVector<ElemAttributeSet*> AttributeSetVectorTypeDecl; 00056 XALAN_USES_MEMORY_MANAGER(AttributeSetVectorTypeDecl) 00057 00058 /** 00059 * This acts as the stylesheet root of the stylesheet 00060 * tree, and holds values that are shared by all 00061 * stylesheets in the tree. 00062 */ 00063 class XALAN_XSLT_EXPORT StylesheetRoot : public Stylesheet 00064 { 00065 public: 00066 00067 typedef XalanVector<const XalanQName*> XalanQNameVectorType; 00068 00069 typedef AttributeSetVectorTypeDecl AttributeSetVectorType; 00070 00071 typedef XalanMap<const XalanQName*, 00072 AttributeSetVectorType> AttributeSetMapType; 00073 00074 /** 00075 * Construct a Stylesheet from a Document. 00076 * 00077 * @param baseIdentifier document identifier 00078 * @param constructionContext context for construction of object 00079 */ 00080 StylesheetRoot( 00081 const XalanDOMString& baseIdentifier, 00082 StylesheetConstructionContext& constructionContext); 00083 00084 virtual 00085 ~StylesheetRoot(); 00086 00087 static StylesheetRoot* 00088 create( 00089 MemoryManager& theManager, 00090 const XalanDOMString& baseIdentifier, 00091 StylesheetConstructionContext& constructionContext); 00092 00093 MemoryManager& 00094 getMemoryManager() 00095 { 00096 return m_version.getMemoryManager(); 00097 } 00098 /** 00099 * Called after construction is completed. 00100 */ 00101 virtual void 00102 postConstruction(StylesheetConstructionContext& constructionContext); 00103 00104 /** 00105 * Transform the source tree to the output in the given result tree target. 00106 * 00107 * @param inputSource The input source 00108 * @param outputTarget The output result target 00109 * @param constructionContext context for construction of object 00110 */ 00111 void 00112 process( 00113 XalanNode* sourceTree, 00114 XSLTResultTarget& outputTarget, 00115 StylesheetExecutionContext& executionContext) const; 00116 00117 /** 00118 * Have the stylesheet create the appropriate FormatterListener, 00119 * based on the XSLTResultTarget provided. setupFormatterListener 00120 * also calls setFormatterListener() on the execution context 00121 * instance. setupFormatterListener() is done automatically by 00122 * process(), but this is provided as an escape, to allow for 00123 * changing the FormatterListener on-the-fly. 00124 * 00125 * @param outputTarget The output source tree 00126 * @param constructionContext context for construction of object 00127 * @return a pointer to the new FormatterListener instance. 00128 */ 00129 FormatterListener* 00130 setupFormatterListener( 00131 XSLTResultTarget& outputTarget, 00132 StylesheetExecutionContext& executionContext) const; 00133 00134 /** 00135 * Return the output method that was specified in the stylesheet. 00136 * The returned value is one of FormatterLister::eFormat values. 00137 * 00138 * @return value of output method 00139 */ 00140 FormatterListener::eFormat 00141 getOutputMethod() const 00142 { 00143 return m_outputMethod; 00144 } 00145 00146 bool 00147 isOutputMethodSet() const 00148 { 00149 return getOutputMethod() == FormatterListener::OUTPUT_METHOD_NONE ? false : true; 00150 } 00151 00152 /** 00153 * Get the output version string that was specified in the 00154 * xsl:output element 00155 * 00156 * @return output version string 00157 */ 00158 XalanDOMString& 00159 getOutputVersion(XalanDOMString& theResult) const 00160 { 00161 theResult.assign(m_version); 00162 00163 return theResult; 00164 } 00165 00166 /** 00167 * Determine if output indenting was specified in the 00168 * xsl:output element 00169 * 00170 * @return true to indent 00171 */ 00172 bool 00173 getOutputIndent() const 00174 { 00175 return m_indentResult == eIndentNoImplicit || 00176 m_indentResult == eIndentNoExplicit ? false : true; 00177 } 00178 00179 /** 00180 * Determine if output indenting should be 00181 * enabled for HTML output. Semantically, 00182 * this implies the output method is implicit, 00183 * not explicit, but we don't really check that. 00184 * 00185 * @return true to indent 00186 */ 00187 bool 00188 getHTMLOutputIndent() const 00189 { 00190 return m_indentResult == eIndentNoExplicit ? false : true; 00191 } 00192 00193 /** 00194 * Get the output encoding string that was specified in the 00195 * xsl:output element 00196 * 00197 * @return encoding string 00198 */ 00199 XalanDOMString& 00200 getOutputEncoding(XalanDOMString& theResult) const 00201 { 00202 theResult.assign(m_encoding); 00203 00204 return theResult; 00205 } 00206 00207 /** 00208 * Get the media-type string that was specified in the 00209 * xsl:output element 00210 * 00211 * @return media type string 00212 */ 00213 XalanDOMString& 00214 getOutputMediaType(XalanDOMString& theResult) const 00215 { 00216 theResult.assign(m_mediatype); 00217 00218 return theResult; 00219 } 00220 00221 /** 00222 * Get the doctype-system-id string that was specified in the 00223 * xsl:output element 00224 * 00225 * @return document type string 00226 */ 00227 XalanDOMString & 00228 getOutputDoctypeSystem(XalanDOMString& theResult) const 00229 { 00230 theResult.assign(m_doctypeSystem); 00231 00232 return theResult; 00233 } 00234 00235 /** 00236 * Get the doctype-public-id string that was specified in the 00237 * xsl:output element 00238 * 00239 * @return document type public id string 00240 */ 00241 XalanDOMString& 00242 getOutputDoctypePublic(XalanDOMString& theResult) const 00243 { 00244 theResult.assign(m_doctypePublic); 00245 00246 return theResult; 00247 } 00248 00249 /** 00250 * Determine whether to output XML declarations. 00251 * 00252 * @return true to output declarations 00253 */ 00254 bool 00255 getOmitOutputXMLDecl() const 00256 { 00257 return m_omitxmlDecl; 00258 } 00259 00260 /** 00261 * Get the standalone string that was specified in the 00262 * xsl:output element.(either "yes" or "no") 00263 * 00264 * @return standalone string 00265 */ 00266 XalanDOMString& 00267 getOutputStandalone(XalanDOMString& theResult) const 00268 { 00269 theResult.assign(m_standalone); 00270 00271 return theResult; 00272 } 00273 00274 /** 00275 * Get the template representing the default rule for text. 00276 * 00277 * @return pointer to template rule for text 00278 */ 00279 ElemTemplateElement* 00280 getDefaultTextRule() const 00281 { 00282 return m_defaultTextRule; 00283 } 00284 00285 /** 00286 * Get the template representing the default rule. 00287 * 00288 * @return pointer to default template rule 00289 */ 00290 ElemTemplateElement* 00291 getDefaultRule() const 00292 { 00293 return m_defaultRule; 00294 } 00295 00296 /** 00297 * Get the template representing the default root rule. 00298 * 00299 * @return pointer to default root template rule 00300 */ 00301 ElemTemplateElement* 00302 getDefaultRootRule() const 00303 { 00304 return m_defaultRootRule; 00305 } 00306 00307 /** 00308 * Process the "xsl:output" element. 00309 * 00310 * @param name name of element 00311 * @param atts attribute list for element 00312 * @param constructionContext context for construction of object 00313 */ 00314 void 00315 processOutputSpec( 00316 const XalanDOMChar* name, 00317 const AttributeListType& atts, 00318 StylesheetConstructionContext& constructionContext); 00319 00320 /** 00321 * Retrieve the stack of imported stylesheets. 00322 * 00323 * @return stack of URIs for stylesheets 00324 */ 00325 URLStackType& 00326 getImportStack() 00327 { 00328 return m_importStack; 00329 } 00330 00331 /** 00332 * Retrieve the stack of imported stylesheets. 00333 * 00334 * @return const stack of URIs for stylesheets 00335 */ 00336 const URLStackType& 00337 getImportStack() const 00338 { 00339 return m_importStack; 00340 } 00341 00342 /** 00343 * Change the value of the flag for indenting results. 00344 * 00345 * @param bIndent true to indent results 00346 */ 00347 void 00348 setIndentResult(bool bIndent) 00349 { 00350 m_indentResult = bIndent == true ? eIndentYesExplicit : eIndentNoExplicit; 00351 } 00352 00353 /** 00354 * Change the value of the output method, one of the 00355 * FormatterListener::eFormat values. 00356 * 00357 * @param meth new method number 00358 */ 00359 void 00360 setOutputMethod(FormatterListener::eFormat meth) 00361 { 00362 m_outputMethod = meth; 00363 } 00364 00365 bool 00366 hasCDATASectionElements() const 00367 { 00368 assert((m_hasCDATASectionElems == false && m_cdataSectionElems.empty() == true ) || 00369 ( m_hasCDATASectionElems == true && m_cdataSectionElems.empty() == false)); 00370 00371 return m_hasCDATASectionElems; 00372 } 00373 00374 /** 00375 * Determine if a QName is in the list of CDATA section 00376 * element QNames. 00377 * 00378 * @param theQName The QName of the element to check. 00379 * @return true or false 00380 */ 00381 bool 00382 isCDATASectionElementName(const XalanQName& theQName) const; 00383 00384 /** 00385 * Given a valid element key, return the corresponding node list. 00386 * 00387 * @param context context node 00388 * @param qname qname of the key, which must match the 'name' 00389 * attribute on xsl:key 00390 * @param ref value that must match the value found by the 00391 * 'match' attribute on xsl:key 00392 * @param resolver resolver for namespace resolution 00393 * @param nodelist A node list to contain the nodes found 00394 * @param executionContext The current execution context 00395 * @param theKeysTable The table of keys to search. 00396 */ 00397 void 00398 getNodeSetByKey( 00399 XalanNode* context, 00400 const XalanQName& qname, 00401 const XalanDOMString& ref, 00402 const PrefixResolver& resolver, 00403 MutableNodeRefList& nodelist, 00404 StylesheetExecutionContext& executionContext, 00405 const Locator* locator, 00406 KeyTablesTableType& theKeysTable) const; 00407 00408 unsigned long 00409 getNextElemNumberID() 00410 { 00411 return m_elemNumberNextID++; 00412 } 00413 00414 unsigned long 00415 getElemNumberCount() const 00416 { 00417 return m_elemNumberNextID; 00418 } 00419 00420 bool 00421 hasPreserveOrStripSpaceElements() const 00422 { 00423 return m_hasStripOrPreserveSpace; 00424 } 00425 00426 /** 00427 * Check to see if a whitespace text node should be stripped from 00428 * the source tree. 00429 * 00430 * @param theNode The text node to check. 00431 */ 00432 bool 00433 shouldStripSourceNode(const XalanText& theNode) const 00434 { 00435 if (hasPreserveOrStripSpaceElements() == true && 00436 theNode.isWhitespace() == true) 00437 { 00438 return internalShouldStripSourceNode(theNode); 00439 } 00440 00441 return false; 00442 } 00443 00444 void 00445 addAttributeSet(ElemAttributeSet& theAttributeSet); 00446 00447 #if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION) 00448 /** 00449 * Get the nth attribute set with the specified name. 00450 * 00451 * @param execution context for executing this stylesheet 00452 * @param theQName the name of the attribute set 00453 * @param matchingIndex index of the attribute set with the specified name 00454 * @param theLocator the locator 00455 * @returns a pointer to the attribute, 0 if no matching attribute set 00456 */ 00457 const ElemAttributeSet* 00458 getAttributeSet( 00459 StylesheetExecutionContext& theExecutionContext, 00460 const XalanQName& theQName, 00461 size_type matchingIndex, 00462 const Locator* theLocator) const; 00463 #else 00464 void 00465 executeAttributeSet( 00466 StylesheetExecutionContext& theExecutionContext, 00467 const XalanQName& theQName, 00468 const Locator* theLocator) const; 00469 #endif 00470 00471 00472 private: 00473 00474 /** 00475 * Choose the encoding to use. 00476 * 00477 * @param outputTarget The output result target 00478 * 00479 * @return The chosen encoding 00480 */ 00481 const XalanDOMString& 00482 getEncoding(const XSLTResultTarget& outputTarget) const; 00483 00484 /** 00485 * Create the default rule if needed. 00486 * 00487 * @param constructionContext context for construction of object 00488 */ 00489 void 00490 initDefaultRule(StylesheetConstructionContext& constructionContext); 00491 00492 /** 00493 * Check to see if a whitespace text node should be stripped from 00494 * the source tree. 00495 * 00496 * @param theNode The text node to check. 00497 */ 00498 bool 00499 internalShouldStripSourceNode(const XalanText& theNode) const; 00500 00501 /** 00502 * The version tells the version of XML to be used for outputting the result tree, 00503 * as specified in xsl:output. 00504 */ 00505 XalanDOMString m_version; 00506 00507 enum eIndentType { eIndentNoImplicit, eIndentNoExplicit, eIndentYesImplicit, eIndentYesExplicit }; 00508 00509 /** 00510 * indent-result is by default no, which means an XSL processor must not 00511 * change the whitespace on output. 00512 */ 00513 eIndentType m_indentResult; 00514 00515 /** 00516 * The encoding attribute specifies the preferred encoding to use 00517 * for outputting the result tree. 00518 */ 00519 XalanDOMString m_encoding; 00520 00521 /** 00522 * The media-type attribute is applicable for the xml output method. 00523 * The default value for the media-type attribute is text/xml. 00524 */ 00525 XalanDOMString m_mediatype; 00526 00527 /** 00528 * If the doctype-system-id attribute is specified, the xml output method should 00529 * output a document type declaration immediately before the first element. 00530 * The name following <!DOCTYPE should be the name of the first element. 00531 */ 00532 XalanDOMString m_doctypeSystem; 00533 00534 /** 00535 * If doctype-public-id attribute is also specified, then the xml output 00536 * method should output PUBLIC followed by the public identifier and then 00537 * the system identifier; otherwise, it should output SYSTEM followed by 00538 * the system identifier. The internal subset should be empty. The 00539 * doctype-public-id attribute should be ignored unless the doctype-system-id 00540 * attribute is specified. 00541 */ 00542 XalanDOMString m_doctypePublic; 00543 00544 /** 00545 * Tells whether or not to output an XML declaration. 00546 */ 00547 bool m_omitxmlDecl; 00548 00549 /** 00550 * Tells what the xmldecl should specify for the standalone value. 00551 */ 00552 XalanDOMString m_standalone; 00553 00554 /** 00555 * The URL that belongs to the result namespace. 00556 * @serial 00557 */ 00558 XalanDOMString m_resultNameSpaceURL; 00559 00560 /** 00561 * The output method as specified in xsl:output. 00562 */ 00563 FormatterListener::eFormat m_outputMethod; 00564 00565 /** 00566 * Vector of qnames that specifies elements that should be formatted 00567 * as CDATA. 00568 */ 00569 XalanQNameVectorType m_cdataSectionElems; 00570 00571 bool m_hasCDATASectionElems; 00572 00573 /** 00574 * A stack of who's importing whom is needed in order to detect 00575 * a recursive include or import, which is an error. 00576 */ 00577 URLStackType m_importStack; 00578 00579 00580 /** 00581 * The default template to use for text nodes if we don't find 00582 * anything else. This is initialized in initDefaultRule(). 00583 */ 00584 ElemTemplateElement* m_defaultTextRule; 00585 00586 /** 00587 * The default template to use if we don't find anything 00588 * else. This is initialized in initDefaultRule(). 00589 */ 00590 ElemTemplateElement* m_defaultRule; 00591 00592 /** 00593 * The default template to use for the root if we don't find 00594 * anything else. This is initialized in initDefaultRule(). 00595 */ 00596 ElemTemplateElement* m_defaultRootRule; 00597 00598 /** 00599 * This is set to true if an xsl:key directive is found. 00600 */ 00601 bool m_needToBuildKeysTable; 00602 00603 /** 00604 * This is set to true if URLs should be escaped in HTML output (the default) 00605 */ 00606 bool m_outputEscapeURLs; 00607 00608 /** 00609 * The amount to indent. The default is -1, which indicates not to indent. 00610 */ 00611 int m_indentAmount; 00612 00613 /** 00614 * This is set to true if we should omit the META tag in HTML output (the default is false) 00615 */ 00616 bool m_omitMETATag; 00617 00618 /** 00619 * This is set to true if we should omit the META tag in HTML output (the default is false) 00620 */ 00621 unsigned long m_elemNumberNextID; 00622 00623 /** 00624 * A lookup table of all attribute sets. 00625 */ 00626 AttributeSetMapType m_attributeSetsMap; 00627 00628 /** 00629 * true if there are any whitespace strip or preserve 00630 * elements. 00631 */ 00632 bool m_hasStripOrPreserveSpace; 00633 00634 00635 // Not implemented... 00636 StylesheetRoot(const StylesheetRoot&); 00637 00638 StylesheetRoot& 00639 operator=(const StylesheetRoot&); 00640 00641 bool 00642 operator==(const StylesheetRoot&) const; 00643 }; 00644 00645 00646 00647 XALAN_CPP_NAMESPACE_END 00648 00649 00650 00651 #endif // XALAN_STYLESHEETROOT_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 |
|