Back to index

lightning-sunbird  0.9+nobinonly
txXSLTPatterns.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is TransforMiiX XSLT processor code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Axel Hecht.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Axel Hecht <axel@pike.org>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef TX_XSLT_PATTERNS_H
00040 #define TX_XSLT_PATTERNS_H
00041 
00042 #include "Expr.h"
00043 #include "XMLUtils.h"
00044 #include "nsVoidArray.h"
00045 
00046 class ProcessorState;
00047 
00048 class txPattern : public TxObject
00049 {
00050 public:
00051     virtual ~txPattern();
00052 
00053     /*
00054      * Determines whether this Pattern matches the given node.
00055      */
00056     virtual MBool matches(const txXPathNode& aNode,
00057                           txIMatchContext* aContext) = 0;
00058 
00059     /*
00060      * Returns the default priority of this Pattern.
00061      *
00062      * Simple Patterns return the values as specified in XPath 5.5.
00063      * Returns -Inf for union patterns, as it shouldn't be called on them.
00064      */
00065     virtual double getDefaultPriority() = 0;
00066 
00067     /*
00068      * Adds the simple Patterns to the List.
00069      * For union patterns, add all sub patterns,
00070      * all other (simple) patterns just add themselves.
00071      * This cuts the ownership of the union pattern and it's
00072      * simple patterns, leaving union patterns empty after a call
00073      * to this function.
00074      */
00075     virtual nsresult getSimplePatterns(txList &aList);
00076 
00077 #ifdef TX_TO_STRING
00078     /*
00079      * Returns the String representation of this Pattern.
00080      * @param dest the String to use when creating the String
00081      * representation. The String representation will be appended to
00082      * any data in the destination String, to allow cascading calls to
00083      * other #toString() methods for Patterns.
00084      * @return the String representation of this Pattern.
00085      */
00086     virtual void toString(nsAString& aDest) = 0;
00087 #endif
00088 };
00089 
00090 #define TX_DECL_PATTERN_BASE \
00091     MBool matches(const txXPathNode& aNode, txIMatchContext* aContext); \
00092     double getDefaultPriority()
00093 
00094 #ifndef TX_TO_STRING
00095 #define TX_DECL_PATTERN TX_DECL_PATTERN_BASE
00096 #else
00097 #define TX_DECL_PATTERN \
00098     TX_DECL_PATTERN_BASE; \
00099     void toString(nsAString& aDest)
00100 #endif
00101 
00102 #define TX_DECL_PATTERN2 \
00103     TX_DECL_PATTERN; \
00104     nsresult getSimplePatterns(txList &aList)
00105 
00106 
00107 class txUnionPattern : public txPattern
00108 {
00109 public:
00110     txUnionPattern()
00111     {
00112     }
00113 
00114     ~txUnionPattern();
00115 
00116     nsresult addPattern(txPattern* aPattern);
00117 
00118     TX_DECL_PATTERN2;
00119 
00120 private:
00121     txList mLocPathPatterns;
00122 };
00123 
00124 class txLocPathPattern : public txPattern
00125 {
00126 public:
00127     txLocPathPattern()
00128     {
00129     }
00130 
00131     ~txLocPathPattern();
00132 
00133     nsresult addStep(txPattern* aPattern, MBool isChild);
00134 
00135     TX_DECL_PATTERN;
00136 
00137 private:
00138     class Step {
00139     public:
00140         Step(txPattern* aPattern, MBool aIsChild)
00141             : pattern(aPattern), isChild(aIsChild)
00142         {
00143         }
00144 
00145         ~Step()
00146         {
00147             delete pattern;
00148         }
00149 
00150         txPattern* pattern;
00151         MBool isChild;
00152     };
00153 
00154     txList mSteps;
00155 };
00156 
00157 class txRootPattern : public txPattern
00158 {
00159 public:
00160     txRootPattern()
00161 #ifdef TX_TO_STRING
00162         : mSerialize(PR_TRUE)
00163 #endif
00164     {
00165     }
00166 
00167     ~txRootPattern();
00168 
00169     TX_DECL_PATTERN;
00170 
00171 #ifdef TX_TO_STRING
00172 public:
00173     void setSerialize(PRBool aSerialize)
00174     {
00175         mSerialize = aSerialize;
00176     }
00177 
00178 private:
00179     // Don't serialize txRootPattern if it's used in a txLocPathPattern
00180     PRBool mSerialize;
00181 #endif
00182 };
00183 
00184 class txIdPattern : public txPattern
00185 {
00186 public:
00187     txIdPattern(const nsAString& aString);
00188 
00189     ~txIdPattern();
00190 
00191     TX_DECL_PATTERN;
00192 
00193 private:
00194     nsStringArray mIds;
00195 };
00196 
00197 class txKeyPattern : public txPattern
00198 {
00199 public:
00200     txKeyPattern(nsIAtom* aPrefix, nsIAtom* aLocalName,
00201                  PRInt32 aNSID, const nsAString& aValue)
00202         : mName(aNSID, aLocalName), mPrefix(aPrefix), mValue(aValue)
00203     {
00204     }
00205 
00206     ~txKeyPattern();
00207 
00208     TX_DECL_PATTERN;
00209 
00210 private:
00211     txExpandedName mName;
00212     nsIAtom* mPrefix;
00213     nsString mValue;
00214 };
00215 
00216 class txStepPattern : public PredicateList, public txPattern
00217 {
00218 public:
00219     txStepPattern(txNodeTest* aNodeTest, MBool isAttr)
00220         :mNodeTest(aNodeTest), mIsAttr(isAttr)
00221     {
00222     }
00223 
00224     ~txStepPattern();
00225 
00226     TX_DECL_PATTERN;
00227 
00228 private:
00229     txNodeTest* mNodeTest;
00230     MBool mIsAttr;
00231 };
00232 
00233 #endif // TX_XSLT_PATTERNS_H