00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999 The Apache Software Foundation. All rights 00006 * reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Apache Software Foundation (http://www.apache.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Xalan" and "Apache Software Foundation" must 00028 * not be used to endorse or promote products derived from this 00029 * software without prior written permission. For written 00030 * permission, please contact apache@apache.org. 00031 * 00032 * 5. Products derived from this software may not be called "Apache", 00033 * nor may "Apache" appear in their name, without prior written 00034 * permission of the Apache Software Foundation. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00040 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00043 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00044 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00045 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00046 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * ==================================================================== 00049 * 00050 * This software consists of voluntary contributions made by many 00051 * individuals on behalf of the Apache Software Foundation and was 00052 * originally based on software copyright (c) 1999, International 00053 * Business Machines, Inc., http://www.ibm.com. For more 00054 * information on the Apache Software Foundation, please see 00055 * <http://www.apache.org/>. 00056 */ 00057 #if !defined(XPATH_HEADER_GUARD_1357924680) 00058 #define XPATH_HEADER_GUARD_1357924680 00059 00060 00061 00062 // Base header file. Must be first. 00063 #include <XPath/XPathDefinitions.hpp> 00064 00065 00066 00067 #include <XalanDOM/XalanDOMString.hpp> 00068 00069 00070 00071 #include <PlatformSupport/DoubleSupport.hpp> 00072 00073 00074 00075 // Base class header files... 00076 #include <XPath/XPathExecutionContext.hpp> 00077 00078 00079 00080 #include <XPath/XPathExpression.hpp> 00081 #include <XPath/Function.hpp> 00082 #include <XPath/XPathFunctionTable.hpp> 00083 00084 00085 00086 class Locator; 00087 class PrefixResolver; 00088 class XObject; 00089 class XalanNode; 00090 00091 00092 00093 class XALAN_XPATH_EXPORT XPath 00094 { 00095 public: 00096 00097 static const XalanDOMString& PSEUDONAME_ANY; 00098 static const XalanDOMString& PSEUDONAME_ROOT; 00099 static const XalanDOMString& PSEUDONAME_TEXT; 00100 static const XalanDOMString& PSEUDONAME_COMMENT; 00101 static const XalanDOMString& PSEUDONAME_PI; 00102 static const XalanDOMString& PSEUDONAME_OTHER; 00103 static const XalanDOMString& PSEUDONAME_NODE; 00104 00105 #if defined(XALAN_NO_NAMESPACES) 00106 typedef vector<XalanDOMString> TargetElementStringsVectorType; 00107 #else 00108 typedef std::vector<XalanDOMString> TargetElementStringsVectorType; 00109 #endif 00110 00111 00115 static void 00116 initialize(); 00117 00121 static void 00122 terminate(); 00123 00129 explicit 00130 XPath(const Locator* theLocator = 0); 00131 00132 virtual 00133 ~XPath(); 00134 00138 void 00139 shrink(); 00140 00149 const XObjectPtr 00150 execute( 00151 XalanNode* context, 00152 const PrefixResolver& prefixResolver, 00153 XPathExecutionContext& executionContext) const; 00154 00164 const XObjectPtr 00165 execute( 00166 XalanNode* context, 00167 const PrefixResolver& prefixResolver, 00168 const NodeRefListBase& contextNodeList, 00169 XPathExecutionContext& executionContext) const 00170 { 00171 // Set and restore the context node list... 00172 XPathExecutionContext::ContextNodeListSetAndRestore theSetAndRestore( 00173 executionContext, 00174 contextNodeList); 00175 00176 return execute(context, prefixResolver, executionContext); 00177 } 00178 00187 const XObjectPtr 00188 execute(XPathExecutionContext& executionContext) const 00189 { 00190 assert(executionContext.getPrefixResolver() != 0); 00191 00192 return executeMore(executionContext.getCurrentNode(), 0, executionContext); 00193 } 00194 00203 const XObjectPtr 00204 executeMore( 00205 XalanNode* context, 00206 int opPos, 00207 XPathExecutionContext& executionContext) const; 00208 00217 const XObjectPtr 00218 locationPath( 00219 XalanNode* context, 00220 int opPos, 00221 XPathExecutionContext& executionContext) const; 00222 00228 XPathExpression& 00229 getExpression() 00230 { 00231 return m_expression; 00232 } 00233 00239 const XPathExpression& 00240 getExpression() const 00241 { 00242 return m_expression; 00243 } 00244 00245 enum eMatchScore 00246 { 00247 eMatchScoreNone, 00248 eMatchScoreNodeTest, 00249 eMatchScoreNSWild, 00250 eMatchScoreQName, 00251 eMatchScoreOther 00252 }; 00253 00254 static double 00255 getMatchScoreValue(eMatchScore score) 00256 { 00257 switch(score) 00258 { 00259 case eMatchScoreNone: 00260 return DoubleSupport::getNegativeInfinity(); 00261 break; 00262 00263 case eMatchScoreNodeTest: 00264 return -0.5; 00265 break; 00266 00267 case eMatchScoreNSWild: 00268 return -0.25; 00269 break; 00270 00271 case eMatchScoreOther: 00272 return 0.5; 00273 break; 00274 00275 case eMatchScoreQName: 00276 return 0.0; 00277 break; 00278 }; 00279 00280 assert(false); 00281 return 0.0; 00282 } 00283 00292 eMatchScore 00293 getMatchScore( 00294 XalanNode* node, 00295 const PrefixResolver& resolver, 00296 XPathExecutionContext& executionContext) const; 00297 00306 const XObjectPtr 00307 predicate( 00308 XalanNode* context, 00309 int opPos, 00310 XPathExecutionContext& executionContext) const 00311 { 00312 return executeMore(context, opPos + 2, executionContext); 00313 } 00314 00320 void 00321 getTargetElementStrings(TargetElementStringsVectorType& targetStrings) const; 00322 00329 static void 00330 installFunction( 00331 const XalanDOMString& funcName, 00332 const Function& func); 00333 00340 static bool 00341 uninstallFunction(const XalanDOMString& funcName); 00342 00349 static bool 00350 isInstalledFunction(const XalanDOMString& theFunctionName) 00351 { 00352 return s_functions.isInstalledFunction(theFunctionName); 00353 } 00354 00355 typedef XPathFunctionTable FunctionTableType; 00356 00362 static const FunctionTableType& 00363 getFunctionTable() 00364 { 00365 return s_functions; 00366 } 00367 00368 #if defined(XALAN_NO_MEMBER_TEMPLATES) 00369 typedef XPathFunctionTable::InstalledFunctionNameVectorType 00370 InstalledFunctionNameVectorType; 00371 00377 static void 00378 getInstalledFunctionNames(InstalledFunctionNameVectorType& theVector) 00379 { 00380 s_functions.getInstalledFunctionNames(theVector); 00381 } 00382 #else 00383 00388 template<class OutputIteratorType> 00389 static void 00390 getInstalledFunctionNames(OutputIteratorType theIterator) 00391 { 00392 s_functions.getInstalledFunctionNames(theIterator); 00393 } 00394 #endif 00395 00396 static void 00397 destroyTable() 00398 { 00399 s_functions.DestroyTable(); 00400 } 00401 00402 bool 00403 getInStylesheet() const 00404 { 00405 return m_inStylesheet; 00406 } 00407 00408 void 00409 setInStylesheet(bool fValue) 00410 { 00411 m_inStylesheet = fValue; 00412 } 00413 00414 const Locator* 00415 getLocator() const 00416 { 00417 return m_locator; 00418 } 00419 00420 void 00421 setLocator(const Locator* theLocator) 00422 { 00423 m_locator = theLocator; 00424 } 00425 00426 protected: 00427 00431 XLocator* 00432 createXLocatorHandler() const; 00433 00440 const XObjectPtr 00441 matchPattern( 00442 XalanNode* context, 00443 int opPos, 00444 XPathExecutionContext& executionContext) const; 00445 00446 protected: 00447 00454 void 00455 doGetMatchScore( 00456 XalanNode* context, 00457 XPathExecutionContext& executionContext, 00458 eMatchScore& score) const; 00459 00466 const XObjectPtr 00467 Or( 00468 XalanNode* context, 00469 int opPos, 00470 XPathExecutionContext& executionContext) const; 00471 00478 const XObjectPtr 00479 And( 00480 XalanNode* context, 00481 int opPos, 00482 XPathExecutionContext& executionContext) const; 00483 00490 const XObjectPtr 00491 notequals( 00492 XalanNode* context, 00493 int opPos, 00494 XPathExecutionContext& executionContext) const; 00495 00502 const XObjectPtr 00503 equals( 00504 XalanNode* context, 00505 int opPos, 00506 XPathExecutionContext& executionContext) const; 00507 00514 const XObjectPtr 00515 lte( 00516 XalanNode* context, 00517 int opPos, 00518 XPathExecutionContext& executionContext) const; 00519 00526 const XObjectPtr 00527 lt( 00528 XalanNode* context, 00529 int opPos, 00530 XPathExecutionContext& executionContext) const; 00531 00538 const XObjectPtr 00539 gte( 00540 XalanNode* context, 00541 int opPos, 00542 XPathExecutionContext& executionContext) const; 00543 00550 const XObjectPtr 00551 gt( 00552 XalanNode* context, 00553 int opPos, 00554 XPathExecutionContext& executionContext) const; 00555 00562 const XObjectPtr 00563 plus( 00564 XalanNode* context, 00565 int opPos, 00566 XPathExecutionContext& executionContext) const; 00567 00574 const XObjectPtr 00575 minus( 00576 XalanNode* context, 00577 int opPos, 00578 XPathExecutionContext& executionContext) const; 00579 00586 const XObjectPtr 00587 mult( 00588 XalanNode* context, 00589 int opPos, 00590 XPathExecutionContext& executionContext) const; 00591 00598 const XObjectPtr 00599 div( 00600 XalanNode* context, 00601 int opPos, 00602 XPathExecutionContext& executionContext) const; 00603 00610 const XObjectPtr 00611 mod( 00612 XalanNode* context, 00613 int opPos, 00614 XPathExecutionContext& executionContext) const; 00615 00622 const XObjectPtr 00623 neg( 00624 XalanNode* context, 00625 int opPos, 00626 XPathExecutionContext& executionContext) const; 00627 00634 const XObjectPtr 00635 string( 00636 XalanNode* context, 00637 int opPos, 00638 XPathExecutionContext& executionContext) const; 00639 00646 const XObjectPtr 00647 boolean( 00648 XalanNode* context, 00649 int opPos, 00650 XPathExecutionContext& executionContext) const; 00651 00658 const XObjectPtr 00659 Union( 00660 XalanNode* context, 00661 int opPos, 00662 XPathExecutionContext& executionContext) const; 00663 00670 const XObjectPtr 00671 literal( 00672 XalanNode* context, 00673 int opPos, 00674 XPathExecutionContext& executionContext) const; 00675 00682 const XObjectPtr 00683 variable( 00684 XalanNode* context, 00685 int opPos, 00686 XPathExecutionContext& executionContext) const; 00687 00694 const XObjectPtr 00695 group( 00696 XalanNode* context, 00697 int opPos, 00698 XPathExecutionContext& executionContext) const 00699 { 00700 return executeMore(context, opPos + 2, executionContext); 00701 } 00702 00709 const XObjectPtr 00710 numberlit( 00711 XalanNode* context, 00712 int opPos, 00713 XPathExecutionContext& executionContext) const; 00714 00721 const XObjectPtr 00722 arg( 00723 XalanNode* context, 00724 int opPos, 00725 XPathExecutionContext& executionContext) const 00726 { 00727 return executeMore(context, opPos + 2, executionContext); 00728 } 00729 00737 const XObjectPtr 00738 locationPathPattern( 00739 XalanNode* context, 00740 int opPos, 00741 XPathExecutionContext& executionContext) const; 00742 00746 const XObjectPtr 00747 runExtFunction( 00748 XalanNode* context, 00749 int opPos, 00750 XPathExecutionContext& executionContext) const; 00751 00755 const XObjectPtr 00756 extfunction( 00757 XalanNode* context, 00758 int /* opPos */, 00759 const XalanDOMString& theNamespace, 00760 const XalanDOMString& functionName, 00761 const Function::XObjectArgVectorType& argVec, 00762 XPathExecutionContext& executionContext) const 00763 { 00764 return executionContext.extFunction(theNamespace, 00765 functionName, 00766 context, 00767 argVec, 00768 m_locator); 00769 } 00770 00774 const XObjectPtr 00775 runFunction( 00776 XalanNode* context, 00777 int opPos, 00778 XPathExecutionContext& executionContext) const; 00779 00783 const XObjectPtr 00784 function( 00785 XalanNode* context, 00786 int funcID, 00787 const Function::XObjectArgVectorType& argVec, 00788 XPathExecutionContext& executionContext) const 00789 { 00790 return s_functions[funcID].execute(executionContext, context, argVec, m_locator); 00791 } 00792 00793 double 00794 getNumericOperand( 00795 XalanNode* context, 00796 int opPos, 00797 XPathExecutionContext& executionContext) const; 00798 00799 private: 00800 00801 // These are not implemented... 00802 XPath(const XPath&); 00803 00804 XPath& 00805 operator=(const XPath&); 00806 00807 bool 00808 operator==(const XPath&) const; 00809 00810 // Default vector allocation sizes. 00811 enum 00812 { 00813 eDefaultTargetStringsSize = 5 00814 }; 00815 00816 const XObjectPtr 00817 locationPath( 00818 XPathExecutionContext& executionContext, 00819 XalanNode& context, 00820 int opPos) const; 00821 00822 eMatchScore 00823 locationPathPattern( 00824 XPathExecutionContext& executionContext, 00825 XalanNode& context, 00826 int opPos) const; 00827 00828 class NodeTester 00829 { 00830 public: 00831 00832 NodeTester( 00833 const XPath& xpath, 00834 XPathExecutionContext& executionContext, 00835 int opPos, 00836 int argLen, 00837 int stepType); 00838 00839 eMatchScore 00840 operator()( 00841 const XalanNode& context, 00842 XalanNode::NodeType nodeType) const 00843 { 00844 assert(context.getNodeType() == nodeType); 00845 00846 return (this->*m_testFunction)(context, nodeType); 00847 } 00848 00849 private: 00850 00851 typedef eMatchScore (NodeTester::*MemberFunctionPtr)(const XalanNode&, XalanNode::NodeType) const; 00852 00853 00854 eMatchScore 00855 testComment( 00856 const XalanNode& context, 00857 XalanNode::NodeType nodeType) const; 00858 00859 eMatchScore 00860 testText( 00861 const XalanNode& context, 00862 XalanNode::NodeType nodeType) const; 00863 00864 eMatchScore 00865 testPI( 00866 const XalanNode& context, 00867 XalanNode::NodeType nodeType) const; 00868 00869 eMatchScore 00870 testPIName( 00871 const XalanNode& context, 00872 XalanNode::NodeType nodeType) const; 00873 00874 eMatchScore 00875 testNode( 00876 const XalanNode& context, 00877 XalanNode::NodeType nodeType) const; 00878 00879 eMatchScore 00880 testRoot( 00881 const XalanNode& context, 00882 XalanNode::NodeType nodeType) const; 00883 00884 eMatchScore 00885 testAttributeNCName( 00886 const XalanNode& context, 00887 XalanNode::NodeType nodeType) const; 00888 00889 eMatchScore 00890 testAttributeQName( 00891 const XalanNode& context, 00892 XalanNode::NodeType nodeType) const; 00893 00894 eMatchScore 00895 testAttributeNamespaceOnly( 00896 const XalanNode& context, 00897 XalanNode::NodeType nodeType) const; 00898 00899 eMatchScore 00900 testAttributeTotallyWild( 00901 const XalanNode& context, 00902 XalanNode::NodeType nodeType) const; 00903 00904 eMatchScore 00905 testElementNCName( 00906 const XalanNode& context, 00907 XalanNode::NodeType nodeType) const; 00908 00909 eMatchScore 00910 testElementQName( 00911 const XalanNode& context, 00912 XalanNode::NodeType nodeType) const; 00913 00914 eMatchScore 00915 testElementNamespaceOnly( 00916 const XalanNode& context, 00917 XalanNode::NodeType nodeType) const; 00918 00919 eMatchScore 00920 testElementTotallyWild( 00921 const XalanNode& context, 00922 XalanNode::NodeType nodeType) const; 00923 00924 eMatchScore 00925 testNamespaceNCName( 00926 const XalanNode& context, 00927 XalanNode::NodeType nodeType) const; 00928 00929 eMatchScore 00930 testNamespaceTotallyWild( 00931 const XalanNode& context, 00932 XalanNode::NodeType nodeType) const; 00933 00934 eMatchScore 00935 testDefault( 00936 const XalanNode& context, 00937 XalanNode::NodeType nodeType) const; 00938 00939 bool 00940 matchLocalName(const XalanNode& context) const; 00941 00942 bool 00943 matchNamespaceURI(const XalanNode& context) const; 00944 00945 bool 00946 matchLocalNameAndNamespaceURI(const XalanNode& context) const; 00947 00948 bool 00949 matchNamespace(const XalanNode& context) const; 00950 00951 bool 00952 shouldStripSourceNode(const XalanNode& context) const; 00953 00954 // Data members... 00955 XPathExecutionContext& m_executionContext; 00956 00957 const XalanDOMString* m_targetNamespace; 00958 00959 const XalanDOMString* m_targetLocalName; 00960 00961 MemberFunctionPtr m_testFunction; 00962 }; 00963 00964 protected: 00965 00966 void 00967 step( 00968 XPathExecutionContext& executionContext, 00969 XalanNode* context, 00970 int opPos, 00971 MutableNodeRefList& queryResults) const; 00972 00983 XalanNode* 00984 stepPattern( 00985 XPathExecutionContext& executionContext, 00986 XalanNode* context, 00987 int opPos, 00988 eMatchScore& scoreHolder) const; 00989 00990 int 00991 findNodeSet( 00992 XPathExecutionContext& executionContext, 00993 XalanNode* context, 00994 int opPos, 00995 int stepType, 00996 MutableNodeRefList& subQueryResults) const; 00997 00998 int 00999 findRoot( 01000 XPathExecutionContext& executionContext, 01001 XalanNode* context, 01002 int opPos, 01003 int stepType, 01004 MutableNodeRefList& subQueryResults) const; 01005 01006 int 01007 findParent( 01008 XPathExecutionContext& executionContext, 01009 XalanNode* context, 01010 int opPos, 01011 int stepType, 01012 MutableNodeRefList& subQueryResults) const; 01013 01014 int 01015 findSelf( 01016 XPathExecutionContext& executionContext, 01017 XalanNode* context, 01018 int opPos, 01019 int stepType, 01020 MutableNodeRefList& subQueryResults) const; 01021 01022 int 01023 findAncestors( 01024 XPathExecutionContext& executionContext, 01025 XalanNode* context, 01026 int opPos, 01027 int stepType, 01028 MutableNodeRefList& subQueryResults) const; 01029 01030 int 01031 findAncestorsOrSelf( 01032 XPathExecutionContext& executionContext, 01033 XalanNode* context, 01034 int opPos, 01035 int stepType, 01036 MutableNodeRefList& subQueryResults) const; 01037 01038 int 01039 findAttributes( 01040 XPathExecutionContext& executionContext, 01041 XalanNode* context, 01042 int opPos, 01043 int stepType, 01044 MutableNodeRefList& subQueryResults) const; 01045 01046 int 01047 findChildren( 01048 XPathExecutionContext& executionContext, 01049 XalanNode* context, 01050 int opPos, 01051 int stepType, 01052 MutableNodeRefList& subQueryResults) const; 01053 01054 int 01055 findDescendants( 01056 XPathExecutionContext& executionContext, 01057 XalanNode* context, 01058 int opPos, 01059 int stepType, 01060 MutableNodeRefList& subQueryResults) const; 01061 01062 int 01063 findFollowing( 01064 XPathExecutionContext& executionContext, 01065 XalanNode* context, 01066 int opPos, 01067 int stepType, 01068 MutableNodeRefList& subQueryResults) const; 01069 01070 int 01071 findFollowingSiblings( 01072 XPathExecutionContext& executionContext, 01073 XalanNode* context, 01074 int opPos, 01075 int stepType, 01076 MutableNodeRefList& subQueryResults) const; 01077 01078 int 01079 findPreceeding( 01080 XPathExecutionContext& executionContext, 01081 XalanNode* context, 01082 int opPos, 01083 int stepType, 01084 MutableNodeRefList& subQueryResults) const; 01085 01086 int 01087 findPreceedingSiblings( 01088 XPathExecutionContext& executionContext, 01089 XalanNode* context, 01090 int opPos, 01091 int stepType, 01092 MutableNodeRefList& subQueryResults) const; 01093 01094 int 01095 findNamespace( 01096 XPathExecutionContext& executionContext, 01097 XalanNode* context, 01098 int opPos, 01099 int stepType, 01100 MutableNodeRefList& subQueryResults) const; 01101 01102 int 01103 findNodesOnUnknownAxis( 01104 XPathExecutionContext& executionContext, 01105 XalanNode* context, 01106 int opPos, 01107 int stepType, 01108 MutableNodeRefList& subQueryResults) const; 01109 01110 eMatchScore 01111 nodeTest( 01112 XPathExecutionContext& executionContext, 01113 XalanNode* context, 01114 XalanNode::NodeType nodeType, 01115 int opPos, 01116 int argLen, 01117 int stepType) const; 01118 01119 void 01120 predicates( 01121 XPathExecutionContext& executionContext, 01122 XalanNode* context, 01123 int opPos, 01124 MutableNodeRefList& subQueryResults, 01125 int& endPredicatesPos) const; 01126 01127 eMatchScore 01128 handleFoundIndex( 01129 XPathExecutionContext& executionContext, 01130 XalanNode* localContext, 01131 int startOpPos) const; 01132 01133 // Data members... 01134 01140 XPathExpression m_expression; 01141 01145 const Locator* m_locator; 01146 01152 bool m_inStylesheet; 01153 01159 static FunctionTableType s_functions; 01160 01161 static const XalanDOMString s_emptyString; 01162 }; 01163 01164 01165 01166 #endif // XPATH_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.3 |
|