Back to index

lightning-sunbird  0.9+nobinonly
txStylesheet.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 TX_TXSTYLESHEET_H
00040 #define TX_TXSTYLESHEET_H
00041 
00042 #include "txOutputFormat.h"
00043 #include "txExpandedNameMap.h"
00044 #include "txList.h"
00045 #include "txXSLTPatterns.h"
00046 #include "XSLTFunctions.h"
00047 #include "nsVoidArray.h"
00048 
00049 class txInstruction;
00050 class txToplevelItem;
00051 class txTemplateItem;
00052 class txVariableItem;
00053 class txStripSpaceItem;
00054 class txAttributeSetItem;
00055 
00056 class txStylesheet
00057 {
00058 public:
00059     class ImportFrame;
00060     class GlobalVariable;
00061     friend class txStylesheetCompilerState;
00062     // To be able to do some cleaning up in destructor
00063     friend class ImportFrame;
00064 
00065     txStylesheet();
00066     ~txStylesheet();
00067     nsresult init();
00068 
00069     nsrefcnt AddRef()
00070     {
00071         return ++mRefCnt;
00072     }
00073     nsrefcnt Release()
00074     {
00075         if (--mRefCnt == 0) {
00076             mRefCnt = 1; //stabilize
00077             delete this;
00078             return 0;
00079         }
00080         return mRefCnt;
00081     }
00082 
00083     txInstruction* findTemplate(const txXPathNode& aNode,
00084                                 const txExpandedName& aMode,
00085                                 txIMatchContext* aContext,
00086                                 ImportFrame* aImportedBy,
00087                                 ImportFrame** aImportFrame);
00088     txDecimalFormat* getDecimalFormat(const txExpandedName& aName);
00089     txInstruction* getAttributeSet(const txExpandedName& aName);
00090     txInstruction* getNamedTemplate(const txExpandedName& aName);
00091     txOutputFormat* getOutputFormat();
00092     GlobalVariable* getGlobalVariable(const txExpandedName& aName);
00093     const txExpandedNameMap& getKeyMap();
00094     PRBool isStripSpaceAllowed(const txXPathNode& aNode,
00095                                txIMatchContext* aContext);
00096 
00100     nsresult doneCompiling();
00101 
00105     nsresult addKey(const txExpandedName& aName, nsAutoPtr<txPattern> aMatch,
00106                     nsAutoPtr<Expr> aUse);
00107 
00111     nsresult addDecimalFormat(const txExpandedName& aName,
00112                               nsAutoPtr<txDecimalFormat> aFormat);
00113 
00117     class ImportFrame {
00118     public:
00119         ImportFrame();
00120         ~ImportFrame();
00121 
00122         // List of toplevel items
00123         txList mToplevelItems;
00124 
00125         // Map of template modes, each item in the map is a txList
00126         // of templates
00127         txExpandedNameMap mMatchableTemplates;
00128 
00129         // ImportFrame which is the first one *not* imported by this frame
00130         ImportFrame* mFirstNotImported;
00131     };
00132 
00133     class GlobalVariable : public TxObject {
00134     public:
00135         GlobalVariable(nsAutoPtr<Expr> aExpr,
00136                        nsAutoPtr<txInstruction> aFirstInstruction,
00137                        PRBool aIsParam);
00138 
00139         nsAutoPtr<Expr> mExpr;
00140         nsAutoPtr<txInstruction> mFirstInstruction;
00141         PRBool mIsParam;
00142     };
00143 
00144 private:
00145     class MatchableTemplate {
00146     public:
00147         MatchableTemplate(txInstruction* aFirstInstruction,
00148                           nsAutoPtr<txPattern> aPattern,
00149                           double aPriority)
00150             : mFirstInstruction(aFirstInstruction),
00151               mMatch(aPattern),
00152               mPriority(aPriority)
00153         {
00154         }
00155         txInstruction* mFirstInstruction;
00156         nsAutoPtr<txPattern> mMatch;
00157         double mPriority;
00158     };
00159     
00160     nsresult addTemplate(txTemplateItem* aTemplate, ImportFrame* aImportFrame);
00161     nsresult addGlobalVariable(txVariableItem* aVariable);
00162     nsresult addFrames(txListIterator& aInsertIter);
00163     nsresult addStripSpace(txStripSpaceItem* aStripSpaceItem,
00164                            nsVoidArray& frameStripSpaceTests);
00165     nsresult addAttributeSet(txAttributeSetItem* aAttributeSetItem);
00166 
00167     // Refcount
00168     nsAutoRefCnt mRefCnt;
00169 
00170     // List of ImportFrames
00171     txList mImportFrames;
00172     
00173     // output format
00174     txOutputFormat mOutputFormat;
00175 
00176     // List of first instructions of templates. This is the owner of all
00177     // instructions used in templates
00178     txList mTemplateInstructions;
00179     
00180     // Root importframe
00181     ImportFrame* mRootFrame;
00182     
00183     // Named templates
00184     txExpandedNameMap mNamedTemplates;
00185     
00186     // Map with all decimal-formats
00187     txExpandedNameMap mDecimalFormats;
00188 
00189     // Map with all named attribute sets
00190     txExpandedNameMap mAttributeSets;
00191     
00192     // Map with all global variables and parameters
00193     txExpandedNameMap mGlobalVariables;
00194     
00195     // Map with all keys
00196     txExpandedNameMap mKeys;
00197     
00198     // Array of all txStripSpaceTests, sorted in acending order
00199     nsVoidArray mStripSpaceTests;
00200     
00201     // Default templates
00202     nsAutoPtr<txInstruction> mContainerTemplate;
00203     nsAutoPtr<txInstruction> mCharactersTemplate;
00204     nsAutoPtr<txInstruction> mEmptyTemplate;
00205 };
00206 
00207 
00212 class txStripSpaceTest {
00213 public:
00214     txStripSpaceTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID,
00215                      MBool stripSpace)
00216         : mNameTest(aPrefix, aLocalName, aNSID, txXPathNodeType::ELEMENT_NODE),
00217           mStrips(stripSpace)
00218     {
00219     }
00220 
00221     MBool matches(const txXPathNode& aNode, txIMatchContext* aContext) {
00222         return mNameTest.matches(aNode, aContext);
00223     }
00224 
00225     MBool stripsSpace() {
00226         return mStrips;
00227     }
00228 
00229     double getDefaultPriority() {
00230         return mNameTest.getDefaultPriority();
00231     }
00232 
00233 protected:
00234     txNameTest mNameTest;
00235     MBool mStrips;
00236 };
00237 
00241 class txIGlobalParameter : public TxObject
00242 {
00243 public:
00244     virtual nsresult getValue(txAExprResult** aValue) = 0;
00245 };
00246 
00247 
00248 #endif //TX_TXSTYLESHEET_H