Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.5

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XPathProcessorImpl.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 1999-2002 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(XPATHPROCESSORIMPL_HEADER_GUARD_1357924680)
00058 #define XPATHPROCESSORIMPL_HEADER_GUARD_1357924680
00059 
00060 
00061 
00062 // Base header file.  Must be first.
00063 #include <XPath/XPathDefinitions.hpp>
00064 
00065 
00066 
00067 #include <cstdlib>
00068 #include <map>
00069 #include <vector>
00070 
00071 
00072 
00073 #include <XalanDOM/XalanDOMString.hpp>
00074 
00075 
00076 
00077 // Base class header file...
00078 #include <XPath/XPathProcessor.hpp>
00079 
00080 
00081 
00082 #include <XPath/XPath.hpp>
00083 
00084 
00085 
00086 XALAN_CPP_NAMESPACE_BEGIN
00087 
00088 
00089 
00090 class XalanNode;
00091 
00092 
00093 
00098 class XALAN_XPATH_EXPORT XPathProcessorImpl : public XPathProcessor
00099 {
00100 public:
00101 
00102 #if defined(XALAN_NO_STD_NAMESPACE)
00103     typedef map<XalanDOMString,
00104                 XalanDOMString,
00105                 less<XalanDOMString> >  StringToStringMapType;
00106 
00107 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
00108     typedef deque<bool>                 BoolVectorType;
00109 #else
00110     typedef vector<bool>                BoolVectorType;
00111 #endif
00112 #else
00113     typedef std::map<XalanDOMString,
00114                      XalanDOMString>    StringToStringMapType;
00115 
00116 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
00117     typedef std::deque<bool>            BoolVectorType;
00118 #else
00119     typedef std::vector<bool>           BoolVectorType;
00120 #endif
00121 #endif
00122 
00123     XPathProcessorImpl();
00124 
00125     virtual
00126     ~XPathProcessorImpl();
00127 
00128 
00129     // These are inherited from XPathProcessor...
00130 
00131     virtual void
00132     initXPath(
00133             XPath&                      pathObj,
00134             XPathConstructionContext&   constructionContext,
00135             const XalanDOMString&       expression,
00136             const PrefixResolver&       resolver,
00137             const LocatorType*          locator = 0);
00138 
00139     virtual void
00140     initMatchPattern(
00141             XPath&                      pathObj,
00142             XPathConstructionContext&   constructionContext,
00143             const XalanDOMString&       expression,
00144             const PrefixResolver&       resolver,
00145             const LocatorType*          locator = 0);
00146 
00147 private:
00148 
00155     void
00156     tokenize(const XalanDOMString&  pat);
00157   
00163     bool
00164     mapPatternElemPos(
00165             int     nesting,
00166             bool    isStart,
00167             bool    isAttrName) const;
00168 
00169     void
00170     addToTokenQueue(const XalanDOMString&   s) const;
00171 
00172     void
00173     replaceTokenWithNamespaceToken() const;
00174 
00179     int
00180     mapNSTokens(
00181             const XalanDOMString&   pat,
00182             int                     startSubstring,
00183             int                     posOfNSSep,
00184             int                     posOfScan);
00185 
00189     int
00190     getTokenQueuePosFromMap(int     i) const;
00191 
00197     int
00198     getNextTargetIndexInMap(int     i) const;
00199   
00204     int
00205     getNextIndexInMap(int   i) const;
00206   
00213     int
00214     getNextSubpatternStartIndexInMap(int    i) const;
00215 
00221     int
00222     getNextPatternPos(int   i) const;
00223 
00229     int
00230     getPrevMapIndex(int     i) const;
00231 
00237     bool
00238     tokenIs(const XalanDOMString&   s) const;
00239 
00245     bool
00246     tokenIs(const XalanDOMChar*     s) const;
00247 
00253     bool
00254     tokenIs(XalanDOMChar    c) const;
00255 
00263     bool
00264     lookahead(
00265             XalanDOMChar    c,
00266             int             n) const;
00267 
00275     bool
00276     lookahead(
00277             const XalanDOMChar*     s,
00278             int                     n) const;
00279 
00287     bool
00288     lookahead(
00289             const XalanDOMString&   s,
00290             int                     n) const;
00291 
00302     bool
00303     lookbehind( 
00304             char    c,
00305             int     n) const;
00306 
00317     bool
00318     lookbehindHasToken(int  n) const;
00319 
00324     void
00325     nextToken();
00326 
00331     const XalanDOMString&
00332     getTokenRelative(int    theOffset) const;
00333 
00338     void
00339     prevToken();
00340 
00345     void
00346     resetTokenMark(int  mark);
00347 
00352     void
00353     consumeExpected(XalanDOMChar    expected);
00354 
00355     bool
00356     isCurrentLiteral() const;
00357 
00364     static bool
00365     isAxis(const XalanDOMString&    theToken);
00366 
00373     static bool
00374     isNodeTest(const XalanDOMString&    theToken);
00375 
00379     void
00380     error(const XalanDOMString&     msg) const;
00381 
00385     void
00386     error(const char*   msg) const;
00387 
00391     static XPathExpression::eOpCodes
00392     getFunctionToken(const XalanDOMString&  key)
00393     {
00394         return searchTable(s_functionTable, s_functionTableSize, key).m_opCode;
00395     }
00396 
00400     static XPathExpression::eOpCodes
00401     getNodeTypeToken(const XalanDOMString&  key)
00402     {
00403         return searchTable(s_nodeTypeTable, s_nodeTypeTableSize, key).m_opCode;
00404     }
00405 
00409     static XPathExpression::eOpCodes
00410     getAxisToken(const XalanDOMString&  key)
00411     {
00412         return searchTable(s_axisTable, s_axisTableSize, key).m_opCode;
00413     }
00414 
00421     void
00422     Expr();
00423 
00424 
00432     void
00433     OrExpr();
00434 
00442     void
00443     AndExpr() ;
00444   
00454     int
00455     EqualityExpr(int    opCodePos = -1);
00456 
00469     int
00470     RelationalExpr(int  opCodePos = -1);
00471 
00482     int
00483     AdditiveExpr(int    opCodePos = -1);
00484 
00497     int
00498     MultiplicativeExpr(int  opCodePos = -1);
00499 
00509     void
00510     UnaryExpr();
00511 
00523     void
00524     UnionExpr();
00525 
00537     void
00538     PathExpr();
00539 
00549     void
00550     FilterExpr();
00551   
00561     void
00562     PrimaryExpr();
00563 
00564 
00570     void
00571     Argument();
00572   
00578     void
00579     FunctionCall();
00580 
00581     void
00582     FunctionPosition();
00583 
00584     void
00585     FunctionLast();
00586 
00587     void
00588     FunctionCount();
00589 
00590     void
00591     FunctionNot();
00592 
00593     void
00594     FunctionTrue();
00595 
00596     void
00597     FunctionFalse();
00598 
00599     void
00600     FunctionBoolean();
00601 
00602     void
00603     FunctionName(int    opPos);
00604 
00605     void
00606     FunctionLocalName(int   opPos);
00607 
00608     void
00609     FunctionNumber(int  opPos);
00610 
00611     void
00612     FunctionFloor();
00613 
00614     void
00615     FunctionCeiling();
00616 
00617     void
00618     FunctionRound();
00619 
00620     void
00621     FunctionString(int  opPos);
00622 
00623     void
00624     FunctionStringLength(int    opPos);
00625 
00626     void
00627     FunctionSum();
00628 
00629     void
00630     FunctionNamespaceURI(int    opPos);
00631 
00638     void
00639     LocationPath();
00640   
00648     void
00649     RelativeLocationPath();
00650   
00656     void
00657     Step();
00658   
00664     void
00665     Basis();
00666   
00672     XPathExpression::eOpCodes
00673     AxisName();
00674   
00681     int
00682     NodeTest();
00683 
00689     void
00690     Predicate();
00691 
00697     void
00698     PredicateExpr();
00699   
00705     void
00706     QName();
00707 
00712     void
00713     NCName();
00714   
00723     void
00724     Literal();
00725   
00731     void
00732     Number();
00733 
00740     void
00741     Pattern();
00742 
00751     void
00752     LocationPathPattern();
00753 
00761     void
00762     IdKeyPattern();
00763 
00771     void
00772     RelativePathPattern();
00773 
00779     void
00780     StepPattern();
00781 
00787     void
00788     AbbreviatedNodeTestStep();
00789 
00790     static bool
00791     isValidFunction(const XalanDOMString&   key);
00792 
00793 private:
00794 
00795     int
00796     FunctionCallArguments();
00797 
00798     struct TableEntry
00799     {
00800         const XalanDOMChar*         m_string;
00801 
00802         XPathExpression::eOpCodes   m_opCode;
00803     };
00804 
00805 #if defined(XALAN_STRICT_ANSI_HEADERS)
00806     typedef std::size_t             size_type;
00807 #else
00808     typedef size_t                  size_type;
00809 #endif
00810 
00811     static const TableEntry&
00812     searchTable(
00813         const TableEntry        theTable[],
00814         size_type               theTableSize,
00815         const XalanDOMString&   theString);
00816 
00820     XalanDOMString                  m_token;
00821   
00827     XalanDOMChar                    m_tokenChar;
00828 
00832     XPath*                          m_xpath;
00833 
00837     XPathConstructionContext*       m_constructionContext;
00838 
00842     XPathExpression*                m_expression;
00843 
00847     const PrefixResolver*           m_prefixResolver;
00848 
00849     bool                            m_requireLiterals;
00850 
00851     bool                            m_isMatchPattern;
00852 
00853     const LocatorType*              m_locator;
00854 
00855     BoolVectorType                  m_positionPredicateStack;
00856 
00857     StringToStringMapType           m_namespaces;
00858 
00859     enum eDummy
00860     {
00861         TARGETEXTRA = 10000
00862     };
00863 
00864     static const XalanDOMString     s_emptyString;
00865 
00866     static const XalanDOMChar       s_functionIDString[];
00867 
00868     // This shouldn't really be here, since it's not part of the XPath standard,
00869     // but rather a part ofthe XSLT standard.
00870     static const XalanDOMChar       s_functionKeyString[];
00871 
00872     static const XalanDOMChar       s_orString[];
00873 
00874     static const XalanDOMChar       s_andString[];
00875 
00876     static const XalanDOMChar       s_divString[];
00877 
00878     static const XalanDOMChar       s_modString[];
00879 
00880     static const XalanDOMChar       s_dotString[];
00881 
00882     static const XalanDOMChar       s_dotDotString[];
00883 
00884     static const XalanDOMChar       s_axisString[];
00885 
00886     static const XalanDOMChar       s_attributeString[];
00887 
00888     static const XalanDOMChar       s_childString[];
00889 
00890     static const XalanDOMChar       s_lastString[];
00891 
00892     static const XalanDOMChar       s_positionString[];
00893 
00894     static const XalanDOMChar       s_asteriskString[];
00895 
00896     static const XalanDOMChar       s_commentString[];
00897 
00898     static const XalanDOMChar       s_piString[];
00899 
00900     static const XalanDOMChar       s_nodeString[];
00901 
00902     static const XalanDOMChar       s_textString[];
00903 
00904     static const XalanDOMChar       s_ancestorString[];
00905 
00906     static const XalanDOMChar       s_ancestorOrSelfString[];
00907 
00908     static const XalanDOMChar       s_descendantString[];
00909 
00910     static const XalanDOMChar       s_descendantOrSelfString[];
00911 
00912     static const XalanDOMChar       s_followingString[];
00913 
00914     static const XalanDOMChar       s_followingSiblingString[];
00915 
00916     static const XalanDOMChar       s_parentString[];
00917 
00918     static const XalanDOMChar       s_precedingString[];
00919 
00920     static const XalanDOMChar       s_precedingSiblingString[];
00921 
00922     static const XalanDOMChar       s_selfString[];
00923 
00924     static const XalanDOMChar       s_namespaceString[];
00925 
00926     static const TableEntry         s_functionTable[];
00927 
00928     static const size_type          s_functionTableSize;
00929 
00930     static const TableEntry         s_nodeTypeTable[];
00931 
00932     static const size_type          s_nodeTypeTableSize;
00933 
00934     static const TableEntry         s_axisTable[];
00935 
00936     static const size_type          s_axisTableSize;
00937 
00938     static const TableEntry         s_dummyEntry;
00939 };
00940 
00941 
00942 
00943 XALAN_CPP_NAMESPACE_END
00944 
00945 
00946 
00947 #endif  // XPATHPROCESSORIMPL_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.5
Copyright © 2000, 2001, 2002, 2003 The Apache Software Foundation. All Rights Reserved.