Back to index

lightning-sunbird  0.9+nobinonly
txIXPathContext.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_I_XPATH_CONTEXT
00040 #define __TX_I_XPATH_CONTEXT
00041 
00042 #include "txCore.h"
00043 
00044 class FunctionCall;
00045 class nsIAtom;
00046 class txAExprResult;
00047 class txResultRecycler;
00048 class txXPathNode;
00049 
00050 /*
00051  * txIParseContext
00052  *
00053  * This interface describes the context needed to create
00054  * XPath Expressions and XSLT Patters.
00055  * (not completely though. key() requires the ProcessorState, which is 
00056  * not part of this interface.)
00057  */
00058 
00059 class txIParseContext
00060 {
00061 public:
00062     virtual ~txIParseContext()
00063     {
00064     }
00065 
00066     /*
00067      * Return a namespaceID for a given prefix.
00068      */
00069     virtual nsresult resolveNamespacePrefix(nsIAtom* aPrefix, PRInt32& aID) = 0;
00070 
00071     /*
00072      * Create a FunctionCall, needed for extension function calls and
00073      * XSLT. XPath function calls are resolved by the Parser.
00074      */
00075     virtual nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID,
00076                                          FunctionCall*& aFunction) = 0;
00077 
00081     virtual PRBool caseInsensitiveNameTests() = 0;
00082 
00083     /*
00084      * Callback to be used by the Parser if errors are detected.
00085      */
00086     virtual void SetErrorOffset(PRUint32 aOffset) = 0;
00087 };
00088 
00089 /*
00090  * txIMatchContext
00091  *
00092  * Interface used for matching XSLT Patters.
00093  * This is the part of txIEvalContext (see below), that is independent
00094  * of the context node when evaluating a XPath expression, too.
00095  * When evaluating a XPath expression, |txIMatchContext|s are used
00096  * to transport the information from Step to Step.
00097  */
00098 class txIMatchContext
00099 {
00100 public:
00101     virtual ~txIMatchContext()
00102     {
00103     }
00104 
00105     /*
00106      * Return the ExprResult associated with the variable with the 
00107      * given namespace and local name.
00108      */
00109     virtual nsresult getVariable(PRInt32 aNamespace, nsIAtom* aLName,
00110                                  txAExprResult*& aResult) = 0;
00111 
00112     /*
00113      * Is whitespace stripping allowed for the given node?
00114      * See http://www.w3.org/TR/xslt#strip
00115      */
00116     virtual MBool isStripSpaceAllowed(const txXPathNode& aNode) = 0;
00117 
00121     virtual void* getPrivateContext() = 0;
00122 
00123     virtual txResultRecycler* recycler() = 0;
00124 
00125     /*
00126      * Callback to be used by the expression/pattern if errors are detected.
00127      */
00128     virtual void receiveError(const nsAString& aMsg, nsresult aRes) = 0;
00129 };
00130 
00131 #define TX_DECL_MATCH_CONTEXT \
00132     nsresult getVariable(PRInt32 aNamespace, nsIAtom* aLName, \
00133                          txAExprResult*& aResult); \
00134     MBool isStripSpaceAllowed(const txXPathNode& aNode); \
00135     void* getPrivateContext(); \
00136     txResultRecycler* recycler(); \
00137     void receiveError(const nsAString& aMsg, nsresult aRes)
00138 
00139 class txIEvalContext : public txIMatchContext
00140 {
00141 public:
00142     virtual ~txIEvalContext()
00143     {
00144     }
00145 
00146     /*
00147      * Get the context node.
00148      */
00149     virtual const txXPathNode& getContextNode() = 0;
00150 
00151     /*
00152      * Get the size of the context node set.
00153      */
00154     virtual PRUint32 size() = 0;
00155 
00156     /*
00157      * Get the position of the context node in the context node set,
00158      * starting with 1.
00159      */
00160     virtual PRUint32 position() = 0;
00161 };
00162 
00163 #define TX_DECL_EVAL_CONTEXT \
00164     TX_DECL_MATCH_CONTEXT; \
00165     const txXPathNode& getContextNode(); \
00166     PRUint32 size(); \
00167     PRUint32 position()
00168 
00169 #endif // __TX_I_XPATH_CONTEXT