Back to index

lightning-sunbird  0.9+nobinonly
txExecutionState.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  * Jonas Sicking.
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Jonas Sicking <jonas@sicking.cc>
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 TRANSFRMX_TXEXECUTIONSTATE_H
00040 #define TRANSFRMX_TXEXECUTIONSTATE_H
00041 
00042 #include "txCore.h"
00043 #include "txStack.h"
00044 #include "XMLUtils.h"
00045 #include "nsVoidArray.h"
00046 #include "txIXPathContext.h"
00047 #include "txVariableMap.h"
00048 #include "nsTHashtable.h"
00049 #include "nsHashKeys.h"
00050 #include "txKey.h"
00051 #include "txStylesheet.h"
00052 
00053 class txAOutputHandlerFactory;
00054 class txAXMLEventHandler;
00055 class txInstruction;
00056 class txIOutputHandlerFactory;
00057 class txExpandedNameMap;
00058 
00059 class txLoadedDocumentEntry : public nsStringHashKey
00060 {
00061 public:
00062     txLoadedDocumentEntry(KeyTypePointer aStr) : nsStringHashKey(aStr)
00063     {
00064     }
00065     txLoadedDocumentEntry(const txLoadedDocumentEntry& aToCopy)
00066         : nsStringHashKey(aToCopy)
00067     {
00068         NS_ERROR("We're horked.");
00069     }
00070     ~txLoadedDocumentEntry()
00071     {
00072         if (mDocument) {
00073             txXPathNodeUtils::release(mDocument);
00074         }
00075     }
00076 
00077     nsAutoPtr<txXPathNode> mDocument;
00078 };
00079 
00080 class txLoadedDocumentsHash : public nsTHashtable<txLoadedDocumentEntry>
00081 {
00082 public:
00083     ~txLoadedDocumentsHash();
00084     nsresult init(txXPathNode* aSourceDocument);
00085 
00086 private:
00087     friend class txExecutionState;
00088     txXPathNode* mSourceDocument;
00089 };
00090 
00091 
00092 class txExecutionState : public txIMatchContext
00093 {
00094 public:
00095     txExecutionState(txStylesheet* aStylesheet, PRBool aDisableLoads);
00096     ~txExecutionState();
00097     nsresult init(const txXPathNode& aNode, txExpandedNameMap* aGlobalParams);
00098     nsresult end(nsresult aResult);
00099 
00100     TX_DECL_MATCH_CONTEXT;
00101 
00105     struct TemplateRule {
00106         txStylesheet::ImportFrame* mFrame;
00107         PRInt32 mModeNsId;
00108         nsIAtom* mModeLocalName;
00109         txVariableMap* mParams;
00110     };
00111 
00112     // Stack functions
00113     nsresult pushEvalContext(txIEvalContext* aContext);
00114     txIEvalContext* popEvalContext();
00115     nsresult pushString(const nsAString& aStr);
00116     void popString(nsAString& aStr);
00117     nsresult pushInt(PRInt32 aInt);
00118     PRInt32 popInt();
00119     nsresult pushResultHandler(txAXMLEventHandler* aHandler);
00120     txAXMLEventHandler* popResultHandler();
00121     nsresult pushTemplateRule(txStylesheet::ImportFrame* aFrame,
00122                               const txExpandedName& aMode,
00123                               txVariableMap* aParams);
00124     void popTemplateRule();
00125     nsresult pushParamMap(txVariableMap* aParams);
00126     txVariableMap* popParamMap();
00127 
00128     // state-getting functions
00129     txIEvalContext* getEvalContext();
00130     txExpandedNameMap* getParamMap();
00131     const txXPathNode* retrieveDocument(const nsAString& aUri);
00132     nsresult getKeyNodes(const txExpandedName& aKeyName,
00133                          const txXPathNode& aDocument,
00134                          const nsAString& aKeyValue, PRBool aIndexIfNotFound,
00135                          txNodeSet** aResult);
00136     TemplateRule* getCurrentTemplateRule();
00137 
00138     // state-modification functions
00139     txInstruction* getNextInstruction();
00140     nsresult runTemplate(txInstruction* aInstruction);
00141     nsresult runTemplate(txInstruction* aInstruction,
00142                          txInstruction* aReturnTo);
00143     void gotoInstruction(txInstruction* aNext);
00144     void returnFromTemplate();
00145     nsresult bindVariable(const txExpandedName& aName,
00146                           txAExprResult* aValue);
00147     void removeVariable(const txExpandedName& aName);
00148 
00149     txAXMLEventHandler* mOutputHandler;
00150     txAXMLEventHandler* mResultHandler;
00151     txAOutputHandlerFactory* mOutputHandlerFactory;
00152 
00153     nsAutoPtr<txVariableMap> mTemplateParams;
00154 
00155     nsRefPtr<txStylesheet> mStylesheet;
00156 
00157 private:
00158     txStack mReturnStack;
00159     txStack mLocalVarsStack;
00160     txStack mEvalContextStack;
00161     txStack mIntStack;
00162     txStack mResultHandlerStack;
00163     txStack mParamStack;
00164     nsStringArray mStringStack;
00165     txInstruction* mNextInstruction;
00166     txVariableMap* mLocalVariables;
00167     txVariableMap mGlobalVariableValues;
00168     nsRefPtr<txAExprResult> mGlobalVarPlaceholderValue;
00169     PRInt32 mRecursionDepth;
00170 
00171     TemplateRule* mTemplateRules;
00172     PRInt32 mTemplateRulesBufferSize;
00173     PRInt32 mTemplateRuleCount;
00174 
00175     txIEvalContext* mEvalContext;
00176     txIEvalContext* mInitialEvalContext;
00177     //Document* mRTFDocument;
00178     txExpandedNameMap* mGlobalParams;
00179 
00180     txLoadedDocumentsHash mLoadedDocuments;
00181     txKeyHash mKeyHash;
00182     nsRefPtr<txResultRecycler> mRecycler;
00183     PRPackedBool mDisableLoads;
00184 
00185     static const PRInt32 kMaxRecursionDepth;
00186 };
00187 
00188 #endif