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(STYLESHEETCONSTRUCTIONCONTEXT_HEADER_GUARD_1357924680) 19 #define STYLESHEETCONSTRUCTIONCONTEXT_HEADER_GUARD_1357924680 20 21 22 23 // Base include file. Must be first. 24 #include <xalanc/XSLT/XSLTDefinitions.hpp> 25 26 27 28 #include <xalanc/PlatformSupport/URISupport.hpp> 29 30 31 32 #include <xalanc/XalanDOM/XalanDOMString.hpp> 33 34 35 36 #include <xalanc/XPath/XalanQName.hpp> 37 #include <xalanc/XPath/XPath.hpp> 38 #include <xalanc/XPath/XPathConstructionContext.hpp> 39 40 41 42 namespace XERCES_CPP_NAMESPACE 43 { 44 class AttributeList; 45 class DocumentHandler; 46 class Locator; 47 } 48 49 50 51 namespace XALAN_CPP_NAMESPACE { 52 53 54 55 typedef xercesc::AttributeList AttributeListType; 56 typedef xercesc::DocumentHandler DocumentHandlerType; 57 58 using xercesc::AttributeList; 59 using xercesc::DocumentHandler; 60 using xercesc::Locator; 61 62 63 64 class AVT; 65 class AVTPart; 66 class ElemTemplate; 67 class ElemTemplateElement; 68 class ExtensionNSHandler; 69 class PrefixResolver; 70 class Stylesheet; 71 class StylesheetRoot; 72 class XalanDocument; 73 class XalanMatchPatternData; 74 class XalanNode; 75 class XSLTInputSource; 76 77 78 79 // 80 // An abstract class which provides support for constructing the internal 81 // representation of a stylesheet. 82 // 83 class XALAN_XSLT_EXPORT StylesheetConstructionContext : public XPathConstructionContext 84 { 85 public: 86 87 typedef XalanQName::NamespacesStackType NamespacesStackType; 88 89 /** 90 * IDs for XSL element types. These are the values 91 * that must be returned by getElementToken(). 92 */ 93 enum eElementToken 94 { 95 ELEMNAME_UNDEFINED = -2, 96 ELEMNAME_EMPTY = -1, 97 ELEMNAME_WITH_PARAM, 98 ELEMNAME_APPLY_TEMPLATES, 99 ELEMNAME_CHOOSE, 100 ELEMNAME_COMMENT, 101 ELEMNAME_COPY, 102 ELEMNAME_COPY_OF, 103 ELEMNAME_ATTRIBUTE, 104 ELEMNAME_ATTRIBUTE_SET, 105 ELEMNAME_EXTENSION, 106 ELEMNAME_FOR_EACH, 107 ELEMNAME_KEY, 108 ELEMNAME_IF, 109 ELEMNAME_IMPORT, 110 ELEMNAME_INCLUDE, 111 ELEMNAME_CALL_TEMPLATE, 112 ELEMNAME_PARAM, 113 ELEMNAME_NUMBER, 114 ELEMNAME_OTHERWISE, 115 ELEMNAME_PI, 116 ELEMNAME_PRESERVE_SPACE, 117 ELEMNAME_TEMPLATE, 118 ELEMNAME_SORT, 119 ELEMNAME_STRIP_SPACE, 120 ELEMNAME_STYLESHEET, 121 ELEMNAME_TEXT, 122 ELEMNAME_VALUE_OF, 123 ELEMNAME_WHEN, 124 ELEMNAME_FALLBACK, 125 ELEMNAME_ELEMENT, 126 127 ELEMNAME_APPLY_IMPORTS, 128 129 ELEMNAME_VARIABLE, 130 ELEMNAME_MESSAGE, 131 132 ELEMNAME_OUTPUT, 133 ELEMNAME_DECIMAL_FORMAT, 134 ELEMNAME_NAMESPACE_ALIAS, 135 136 // This one doesn't really have a name. 137 // It's used for any literal result 138 // element. 139 ELEMNAME_LITERAL_RESULT, 140 141 // This one doesn't really have a name. 142 // It's used for any literal text in 143 // the content of a literal result 144 // element. 145 ELEMNAME_TEXT_LITERAL_RESULT, 146 147 // This one doesn't really have a name. 148 // It's used for forward-compatible 149 // processing. 150 ELEMNAME_FORWARD_COMPATIBLE, 151 152 // Extension handling. 153 ELEMNAME_EXTENSION_CALL, 154 ELEMNAME_EXTENSION_HANDLER 155 }; 156 157 typedef URISupport::URLAutoPtrType URLAutoPtrType; 158 159 explicit 160 StylesheetConstructionContext(MemoryManager& theManager); 161 162 virtual 163 ~StylesheetConstructionContext(); 164 165 166 // These are inherited from XPathConstructionContext... 167 virtual void 168 problem( 169 eSource source, 170 eClassification classification, 171 const XalanDOMString& msg, 172 const Locator* locator, 173 const XalanNode* sourceNode) = 0; 174 175 virtual void 176 problem( 177 eSource source, 178 eClassification classification, 179 const XalanDOMString& msg, 180 const XalanNode* sourceNode) = 0; 181 182 virtual void 183 reset() = 0; 184 185 virtual const XalanDOMString& 186 getPooledString(const XalanDOMString& theString) = 0; 187 188 virtual const XalanDOMString& 189 getPooledString( 190 const XalanDOMChar* theString, 191 XalanDOMString::size_type theLength = XalanDOMString::npos) = 0; 192 193 virtual XalanDOMString& 194 getCachedString() = 0; 195 196 virtual bool 197 releaseCachedString(XalanDOMString& theString) = 0; 198 199 /** 200 * Create a new StylesheetRoot instance. The StylesheetConstructionContext 201 * instance owns the StylesheetRoot instance, and will delete it when asked 202 * or when the StylesheetConstructionContext instance is destroyed. 203 * 204 * @param theBaseIdentifier A URI to the stylesheet file. 205 * @return A pointer to a new StylesheetRoot instance. 206 */ 207 virtual StylesheetRoot* 208 create(const XalanDOMString& theBaseIdentifier) = 0; 209 210 /** 211 * Create a new StylesheetRoot instance. The StylesheetConstructionContext 212 * instance owns the StylesheetRoot instance, and will delete it when asked 213 * or when the StylesheetConstructionContext instance is destroyed. 214 * 215 * @param theInputSource A reference to the input source. 216 * @return A pointer to a new StylesheetRoot instance. 217 */ 218 virtual StylesheetRoot* 219 create(const XSLTInputSource& theInputSource) = 0; 220 221 /** 222 * Create a new Stylesheet instance. The StylesheetConstructionContext 223 * instance owns the Stylesheet instance, and will delete it when asked 224 * or when the StylesheetConstructionContext instance is destroyed. 225 * 226 * @param A reference to the StylesheetRoot instance. 227 * @param theBaseIdentifier A URI to the stylesheet file. 228 * @return A pointer to a new StylesheetRoot instance. 229 */ 230 virtual Stylesheet* 231 create( 232 StylesheetRoot& theStylesheetRoot, 233 const XalanDOMString& theBaseIdentifier) = 0; 234 235 /** 236 * Destroy a StylesheetRoot instance. If this StylesheetConstructionContext 237 * instance does not own the StylesheetRoot, it will not delete it 238 * 239 * @param theStylesheet A pointer to the StylesheetRoot instance to delete. 240 */ 241 virtual void 242 destroy(StylesheetRoot* theStylesheetRoot) = 0; 243 244 /** 245 * Determine the fully qualified URI for a string. 246 * 247 * @param urlString string to qualify 248 * @return auto pointer to fully qualified URI 249 */ 250 virtual URLAutoPtrType 251 getURLFromString(const XalanDOMString& urlString) = 0; 252 253 /** 254 * Determine the fully qualified URI for a string. 255 * 256 * @param urlString string to qualify 257 * @return string to fully qualified URI 258 */ 259 virtual XalanDOMString& 260 getURLStringFromString( 261 const XalanDOMString& urlString, 262 XalanDOMString& theResult) = 0; 263 264 /** 265 * Determine the fully qualified URI for a string. 266 * 267 * @param urlString string to qualify 268 * @param base base location for URI 269 * @return auto pointer to fully qualified URI 270 */ 271 virtual URLAutoPtrType 272 getURLFromString( 273 const XalanDOMString& urlString, 274 const XalanDOMString& base) = 0; 275 276 /** 277 * Determine the fully qualified URI for a string. 278 * 279 * @param urlString string to qualify 280 * @param base base location for URI 281 * @return string to fully qualified URI 282 */ 283 virtual XalanDOMString& 284 getURLStringFromString( 285 const XalanDOMString& urlString, 286 const XalanDOMString& base, 287 XalanDOMString& theResult) = 0; 288 289 /** 290 * Retrieve the URI for the current XSLT namespace, for example, 291 * "http://www.w3.org/1999/XSL/Transform" 292 * 293 * @return URI string 294 */ 295 virtual const XalanDOMString& 296 getXSLTNamespaceURI() const = 0; 297 298 /** 299 * Create and initialize an xpath for a match pattern and return it. This 300 * is to be used by stylesheet elements that need an XPath that is 301 * guaranteed to persist while it lives. 302 * 303 * @param locator the locator for the XPath. May be null. 304 * @param str string to match 305 * @param resolver resolver for namespace resolution 306 * @param allowVariableReferences If true, variable references are allowed. 307 * @param allowKeyFunction If true, calls to the key() function are allowed. 308 * @return XPath for match pattern 309 */ 310 virtual XPath* 311 createMatchPattern( 312 const Locator* locator, 313 const XalanDOMString& str, 314 const PrefixResolver& resolver, 315 bool allowVariableReferences = true, 316 bool allowKeyFunction = true) = 0; 317 318 /** 319 * Create and initialize an xpath for a match pattern and return it. This 320 * is to be used by stylesheet elements that need an XPath that is 321 * guaranteed to persist while it lives. 322 * 323 * @param locator the locator for the XPath. May be null. 324 * @param str string to match 325 * @param resolver resolver for namespace resolution 326 * @param allowVariableReferences If true, variable references are allowed. 327 * @param allowKeyFunction If true, calls to the key() function are allowed. 328 * @return XPath for match pattern 329 */ 330 virtual XPath* 331 createMatchPattern( 332 const Locator* locator, 333 const XalanDOMChar* str, 334 const PrefixResolver& resolver, 335 bool allowVariableReferences = true, 336 bool allowKeyFunction = true) = 0; 337 338 /** 339 * Create and initialize an xpath and return it. This is to be used by 340 * stylesheet elements that need an XPath that is guaranteed to persist 341 * while it lives. 342 * 343 * @param locator the locator for the XPath. May be null. 344 * @param str string to match 345 * @param resolver resolver for namespace resolution 346 * @return XPath for string matched 347 */ 348 virtual XPath* 349 createXPath( 350 const Locator* locator, 351 const XalanDOMString& str, 352 const PrefixResolver& resolver, 353 bool allowVariableReferences = true, 354 bool allowKeyFunction = true) = 0; 355 356 /** 357 * Create and initialize an xpath and return it. This is to be used by 358 * stylesheet elements that need an XPath that is guaranteed to persist 359 * while it lives. 360 * 361 * @param locator the locator for the XPath. May be null. 362 * @param str string to match 363 * @param resolver resolver for namespace resolution 364 * @return XPath for string matched 365 */ 366 virtual XPath* 367 createXPath( 368 const Locator* locator, 369 const XalanDOMChar* str, 370 const PrefixResolver& resolver, 371 bool allowVariableReferences = true, 372 bool allowKeyFunction = true) = 0; 373 374 /** 375 * Create and initialize an xpath and return it. This is to be used by 376 * stylesheet elements that need an XPath that is guaranteed to persist 377 * while it lives. 378 * 379 * @param locator the locator for the XPath. May be null. 380 * @param str string to match 381 * @param resolver resolver for namespace resolution 382 * @return XPath for string matched 383 */ 384 virtual XPath* 385 createXPath( 386 const Locator* locator, 387 const XalanDOMChar* str, 388 XalanDOMString::size_type len, 389 const PrefixResolver& resolver, 390 bool allowVariableReferences = true, 391 bool allowKeyFunction = true) = 0; 392 393 /** 394 * Get the locator from the top of the locator stack. 395 * 396 * @return A pointer to the Locator, or 0 if there is nothing on the stack. 397 */ 398 virtual const Locator* 399 getLocatorFromStack() const = 0; 400 401 /** 402 * Push a locator on to the locator stack. 403 * 404 * @param A pointer to the Locator to push. 405 */ 406 virtual void 407 pushLocatorOnStack(const Locator* locator) = 0; 408 409 /** 410 * Pop the locator from the top of the locator stack. 411 */ 412 virtual void 413 popLocatorStack() = 0; 414 415 /** 416 * Get the Xalan namespace for built-in extensions. 417 * 418 * @return Xalan namespace for extensions 419 */ 420 virtual const XalanDOMString& 421 getXalanXSLNameSpaceURL() const = 0; 422 423 /** 424 * Read in the XML file, either producing a Document or calling SAX events, 425 * and register the document in a table. If the document has already been 426 * read in, it will not be reparsed. 427 * 428 * @param urlString location of the XML 429 * @param docHandler pointer to SAX event handler 430 * @param docToRegister if using a SAX event handler, the object to register in the source docs table. 431 * @return document object, which represents the parsed XML 432 * @exception SAXException 433 */ 434 virtual XalanDocument* 435 parseXML( 436 const XalanDOMString& urlString, 437 DocumentHandler* docHandler, 438 XalanDocument* docToRegister, 439 ErrorHandler* theErrorHandler = 0) = 0; 440 441 /** 442 * Given an name, determine if it is the xml:space attribute 443 * 444 * @param theAttributeName The name to check 445 * @param theStylesheet The current Stylesheet instance 446 * @param theLocator The Locator for error reporting. May be 0. 447 * 448 * @return true if the string is the xml:space attribute name 449 */ 450 virtual bool 451 isXMLSpaceAttribute( 452 const XalanDOMChar* theAttributeName, 453 const Stylesheet& theStylesheet, 454 const Locator* theLocator = 0) = 0; 455 456 /** 457 * Given an name, determine if it is the xsl:use-attribute-sets attribute 458 * 459 * @param theAttributeName The name to check 460 * @param theStylesheet The current Stylesheet instance 461 * @param theLocator The Locator for error reporting. May be 0. 462 * 463 * @return true if the string is the xsl:use-attribute-sets attribute name 464 */ 465 virtual bool 466 isXSLUseAttributeSetsAttribute( 467 const XalanDOMChar* theAttributeName, 468 const Stylesheet& theStylesheet, 469 const Locator* theLocator = 0) = 0; 470 471 /** 472 * Given an name, determine if it is a valid QName 473 * 474 * @param theName The name to check 475 * @param theStylesheet The current Stylesheet instance 476 * @param theLocator The Locator for error reporting. May be 0. 477 * 478 * @return true if the string is a valid QName. 479 */ 480 virtual bool 481 isValidQName( 482 const XalanDOMChar* theName, 483 const Stylesheet& theStylesheet, 484 const Locator* theLocator = 0) = 0; 485 486 /** 487 * Given an XSL tag name, return an integer token that corresponds to 488 * the enums defined above. 489 * 490 * @param name a probable xsl:xxx element 491 * @return The enum value for that token, or ELEMNAME_UNDEFINED 492 */ 493 virtual eElementToken 494 getElementToken(const XalanDOMString& name) const = 0; 495 496 /** 497 * Get the latest XSLT version currently supported. 498 * 499 * @return XSLT version number 500 */ 501 virtual double 502 getXSLTVersionSupported() const = 0; 503 504 /** 505 * Allocate a vector of XalanDOMChar of the specified 506 * size. 507 * 508 * @param theLength The length of the character vector 509 * @return A pointer to the vector. 510 */ 511 virtual XalanDOMChar* 512 allocateXalanDOMCharVector(XalanDOMString::size_type theLength) = 0; 513 514 /** 515 * Allocate a vector of XalanDOMChar of the specified 516 * size. 517 * 518 * @param theString The source character array 519 * @param theLength The length of the character vector 520 * @param fTerminate If true, terminate the new vector with 0 521 * @return A pointer to the array. 522 */ 523 virtual XalanDOMChar* 524 allocateXalanDOMCharVector( 525 const XalanDOMChar* theString, 526 XalanDOMString::size_type theLength = XalanDOMString::npos, 527 bool fTerminate = true) = 0; 528 529 /** 530 * Create an AVT instance. 531 * 532 * @param locator the Locator for the instance. May be null. 533 * @param name name of AVT 534 * @param stringedValue string value to parse 535 * @param resolver resolver for namespace resolution 536 * @return A pointer to the instance. 537 */ 538 virtual const AVT* 539 createAVT( 540 const Locator* locator, 541 const XalanDOMChar* name, 542 const XalanDOMChar* stringedValue, 543 const PrefixResolver& resolver) = 0; 544 545 /** 546 * Create an AVTPart instance. 547 * 548 * @param theString The source character array 549 * @param theLength The length of the character vector 550 * @param fTerminate If true, terminate the new vector with 0 551 * @return A pointer to the instance. 552 */ 553 virtual const AVTPart* 554 createAVTPart( 555 const XalanDOMChar* theString, 556 XalanDOMString::size_type theLength = XalanDOMString::npos) = 0; 557 558 /** 559 * Create an AVTPart instance. 560 * 561 * @param locator the Locator for the instance. May be null. 562 * @param str The XPath expression for the instance 563 * @param len The length of the expression 564 * @param resolver resolver for namespace resolution 565 * @return A pointer to the instance. 566 */ 567 virtual const AVTPart* 568 createAVTPart( 569 const Locator* locator, 570 const XalanDOMChar* str, 571 XalanDOMString::size_type len, 572 const PrefixResolver& resolver) = 0; 573 574 /** 575 * Allocate a vector of const AVT* of the specified 576 * length. 577 * 578 * @param theLength The length of the vector 579 * @return A pointer to the vector. 580 */ 581 virtual const AVT** 582 allocateAVTPointerVector(size_type theLength) = 0; 583 584 /** 585 * Allocate a vector of const AVTPart* of the specified 586 * length. 587 * 588 * @param theLength The length of the vector 589 * @return A pointer to the vector. 590 */ 591 virtual const AVTPart** 592 allocateAVTPartPointerVector(size_type theLength) = 0; 593 594 /** 595 * Create a XalanQName-derived instance. 596 * 597 * @param qname The qname string 598 * @param namespaces The stack of namespaces 599 * @param Locator The current Locator, if any 600 * @param fUseDefault If true, a qname without a prefix will use the default namespace 601 * @return A pointer to the new instance 602 */ 603 virtual const XalanQName* 604 createXalanQName( 605 const XalanDOMString& qname, 606 const NamespacesStackType& namespaces, 607 const Locator* locator = 0, 608 bool fUseDefault = false) = 0; 609 610 /** 611 * Create a XalanQName-derived instance. 612 * 613 * @param qname The qname string 614 * @param namespaces The stack of namespaces 615 * @param Locator The current Locator, if any 616 * @param fUseDefault If true, a qname without a prefix will use the default namespace 617 * @return A pointer to the new instance 618 */ 619 virtual const XalanQName* 620 createXalanQName( 621 const XalanDOMChar* qname, 622 const NamespacesStackType& namespaces, 623 const Locator* locator = 0, 624 bool fUseDefault = false) = 0; 625 626 /** 627 * Tokenize a string and return the QNames corresponding to 628 * those tokens. 629 * 630 * @param count The number of namespaces in the vector returned 631 * @param qnameTokens The string to tokenize 632 * @param namespaces The stack of namespaces 633 * @param Locator The current Locator, if any 634 * @param fUseDefault If true, qnames without prefixes will use the default namespace 635 * @return The resulting vector of XalanQName instances. 636 */ 637 virtual const XalanQName** 638 tokenizeQNames( 639 size_type& count, 640 const XalanDOMChar* qnameTokens, 641 const NamespacesStackType& namespaces, 642 const Locator* locator = 0, 643 bool fUseDefault = false) = 0; 644 645 /** 646 * Create a stylesheet element for the provided type. The 647 * instance owns the memory and will delete the element when 648 * it goes out of scope and the containing stylesheet is 649 * destroyed. 650 * 651 * @param token The enum value of the element to create. 652 * @param stylesheetTree The stylesheet containing the element 653 * @param atts The list of attributes for the element 654 * @param locator The Locator instance for error reporting. May be 0. 655 * 656 * @return A pointer to the new instance. 657 */ 658 virtual ElemTemplateElement* 659 createElement( 660 int token, 661 Stylesheet& stylesheetTree, 662 const AttributeList& atts, 663 const Locator* locator = 0) = 0; 664 665 /** 666 * Create a elements which have specific names. The instance 667 * owns the memory and will delete the element when it goes 668 * out of scope and the containing stylesheet is destroyed. 669 * 670 * @param token The enum value of the element to create. 671 * @param stylesheetTree The stylesheet containing the element 672 * @param name The name of the element 673 * @param atts The list of attributes for the element 674 * @param locator The Locator instance for error reporting. May be 0. 675 * 676 * @return A pointer to the new instance. 677 */ 678 virtual ElemTemplateElement* 679 createElement( 680 int token, 681 Stylesheet& stylesheetTree, 682 const XalanDOMChar* name, 683 const AttributeList& atts, 684 const Locator* locator = 0) = 0; 685 686 /** 687 * Create a an element for literal text. The instance owns the 688 * memory and will delete the element when it goes out of 689 * scope and the containing stylesheet is destroyed. 690 * 691 * @param stylesheetTree The stylesheet containing the element 692 * @param chars The pointer to character string for element 693 * @param length length of the chars parameter. 694 * @param preserveSpace true is space should be preserved 695 * @param disableOutputEscaping true if output escaping should be disabled 696 * @param locator The Locator instance for error reporting. May be 0. 697 * 698 * @return A pointer to the new instance. 699 */ 700 virtual ElemTemplateElement* 701 createElement( 702 Stylesheet& stylesheetTree, 703 const XalanDOMChar* chars, 704 XalanDOMString::size_type length, 705 bool preserveSpace, 706 bool disableOutputEscaping, 707 const Locator* locator = 0) = 0; 708 709 /** 710 * Create an element to handle an extension element. The 711 * instance owns the memory and will delete the element when 712 * it goes out of scope and the containing stylesheet is 713 * destroyed. 714 * 715 * @param stylesheetTree The stylesheet containing the element 716 * @param name The name of the element 717 * @param atts The list of attributes for the element 718 * @param handler The handler for elements in the extension namespace 719 * @param locator The Locator instance for error reporting. May be 0. 720 * 721 * @return A pointer to the new instance. 722 */ 723 virtual ElemTemplateElement* 724 createElement( 725 Stylesheet& stylesheetTree, 726 const XalanDOMChar* name, 727 const AttributeList& atts, 728 ExtensionNSHandler& handler, 729 const Locator* locator = 0) = 0; 730 731 /** 732 * Create an instance of XalanMatchPatternData, which describes 733 * data related to a match pattern and template in stylesheet. 734 * The instance owns the memory and will delete the element when 735 * it goes out of scope and the containing stylesheet is 736 * destroyed. 737 * 738 * @param theTemplate The ElemTemplate node that contains the template for this pattern 739 * @param thePosition The position in the stylesheet 740 * @param theTargetString The target string for match pattern 741 * @param TheMatchPattern The match pattern 742 * @param thePatternString the pattern string 743 * @param thePriority The priority for the match pattern. 744 * 745 * @return A pointer to the new instance. 746 */ 747 virtual const XalanMatchPatternData* 748 createXalanMatchPatternData( 749 const ElemTemplate& theTemplate, 750 size_type thePosition, 751 const XalanDOMString& theTargetString, 752 const XPath& theMatchPattern, 753 const XalanDOMString& thePatternString, 754 XPath::eMatchScore thePriority) = 0; 755 }; 756 757 758 759 } 760 761 762 763 #endif // STYLESHEETCONSTRUCTIONCONTEXT_HEADER_GUARD_1357924680 764