1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is TransforMiiX XSLT processor code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Jonas Sicking.
19 : * Portions created by the Initial Developer are Copyright (C) 2002
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Jonas Sicking <jonas@sicking.cc>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef TX_TXSTYLESHEET_H
40 : #define TX_TXSTYLESHEET_H
41 :
42 : #include "txOutputFormat.h"
43 : #include "txExpandedNameMap.h"
44 : #include "txList.h"
45 : #include "txXSLTPatterns.h"
46 : #include "nsISupportsImpl.h"
47 :
48 : class txInstruction;
49 : class txToplevelItem;
50 : class txTemplateItem;
51 : class txVariableItem;
52 : class txStripSpaceItem;
53 : class txAttributeSetItem;
54 : class txDecimalFormat;
55 : class txStripSpaceTest;
56 : class txXSLKey;
57 :
58 : class txStylesheet
59 : {
60 : public:
61 : class ImportFrame;
62 : class GlobalVariable;
63 : friend class txStylesheetCompilerState;
64 : // To be able to do some cleaning up in destructor
65 : friend class ImportFrame;
66 :
67 : txStylesheet();
68 : ~txStylesheet();
69 : nsresult init();
70 :
71 0 : NS_INLINE_DECL_REFCOUNTING(txStylesheet)
72 :
73 : txInstruction* findTemplate(const txXPathNode& aNode,
74 : const txExpandedName& aMode,
75 : txIMatchContext* aContext,
76 : ImportFrame* aImportedBy,
77 : ImportFrame** aImportFrame);
78 : txDecimalFormat* getDecimalFormat(const txExpandedName& aName);
79 : txInstruction* getAttributeSet(const txExpandedName& aName);
80 : txInstruction* getNamedTemplate(const txExpandedName& aName);
81 : txOutputFormat* getOutputFormat();
82 : GlobalVariable* getGlobalVariable(const txExpandedName& aName);
83 : const txOwningExpandedNameMap<txXSLKey>& getKeyMap();
84 : bool isStripSpaceAllowed(const txXPathNode& aNode,
85 : txIMatchContext* aContext);
86 :
87 : /**
88 : * Called by the stylesheet compiler once all stylesheets has been read.
89 : */
90 : nsresult doneCompiling();
91 :
92 : /**
93 : * Add a key to the stylesheet
94 : */
95 : nsresult addKey(const txExpandedName& aName, nsAutoPtr<txPattern> aMatch,
96 : nsAutoPtr<Expr> aUse);
97 :
98 : /**
99 : * Add a decimal-format to the stylesheet
100 : */
101 : nsresult addDecimalFormat(const txExpandedName& aName,
102 : nsAutoPtr<txDecimalFormat> aFormat);
103 :
104 0 : struct MatchableTemplate {
105 : txInstruction* mFirstInstruction;
106 : nsAutoPtr<txPattern> mMatch;
107 : double mPriority;
108 : };
109 :
110 : /**
111 : * Contain information that is import precedence dependant.
112 : */
113 : class ImportFrame {
114 : public:
115 0 : ImportFrame()
116 0 : : mFirstNotImported(nsnull)
117 : {
118 0 : }
119 : ~ImportFrame();
120 :
121 : // List of toplevel items
122 : txList mToplevelItems;
123 :
124 : // Map of template modes
125 : txOwningExpandedNameMap< nsTArray<MatchableTemplate> > mMatchableTemplates;
126 :
127 : // ImportFrame which is the first one *not* imported by this frame
128 : ImportFrame* mFirstNotImported;
129 : };
130 :
131 0 : class GlobalVariable : public txObject {
132 : public:
133 : GlobalVariable(nsAutoPtr<Expr> aExpr,
134 : nsAutoPtr<txInstruction> aFirstInstruction,
135 : bool aIsParam);
136 :
137 : nsAutoPtr<Expr> mExpr;
138 : nsAutoPtr<txInstruction> mFirstInstruction;
139 : bool mIsParam;
140 : };
141 :
142 : private:
143 : nsresult addTemplate(txTemplateItem* aTemplate, ImportFrame* aImportFrame);
144 : nsresult addGlobalVariable(txVariableItem* aVariable);
145 : nsresult addFrames(txListIterator& aInsertIter);
146 : nsresult addStripSpace(txStripSpaceItem* aStripSpaceItem,
147 : nsTArray<txStripSpaceTest*>& aFrameStripSpaceTests);
148 : nsresult addAttributeSet(txAttributeSetItem* aAttributeSetItem);
149 :
150 : // List of ImportFrames
151 : txList mImportFrames;
152 :
153 : // output format
154 : txOutputFormat mOutputFormat;
155 :
156 : // List of first instructions of templates. This is the owner of all
157 : // instructions used in templates
158 : txList mTemplateInstructions;
159 :
160 : // Root importframe
161 : ImportFrame* mRootFrame;
162 :
163 : // Named templates
164 : txExpandedNameMap<txInstruction> mNamedTemplates;
165 :
166 : // Map with all decimal-formats
167 : txOwningExpandedNameMap<txDecimalFormat> mDecimalFormats;
168 :
169 : // Map with all named attribute sets
170 : txExpandedNameMap<txInstruction> mAttributeSets;
171 :
172 : // Map with all global variables and parameters
173 : txOwningExpandedNameMap<GlobalVariable> mGlobalVariables;
174 :
175 : // Map with all keys
176 : txOwningExpandedNameMap<txXSLKey> mKeys;
177 :
178 : // Array of all txStripSpaceTests, sorted in acending order
179 : nsTArray<nsAutoPtr<txStripSpaceTest> > mStripSpaceTests;
180 :
181 : // Default templates
182 : nsAutoPtr<txInstruction> mContainerTemplate;
183 : nsAutoPtr<txInstruction> mCharactersTemplate;
184 : nsAutoPtr<txInstruction> mEmptyTemplate;
185 : };
186 :
187 :
188 : /**
189 : * txStripSpaceTest holds both an txNameTest and a bool for use in
190 : * whitespace stripping.
191 : */
192 0 : class txStripSpaceTest {
193 : public:
194 0 : txStripSpaceTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID,
195 : bool stripSpace)
196 : : mNameTest(aPrefix, aLocalName, aNSID, txXPathNodeType::ELEMENT_NODE),
197 0 : mStrips(stripSpace)
198 : {
199 0 : }
200 :
201 0 : bool matches(const txXPathNode& aNode, txIMatchContext* aContext) {
202 0 : return mNameTest.matches(aNode, aContext);
203 : }
204 :
205 0 : bool stripsSpace() {
206 0 : return mStrips;
207 : }
208 :
209 0 : double getDefaultPriority() {
210 0 : return mNameTest.getDefaultPriority();
211 : }
212 :
213 : protected:
214 : txNameTest mNameTest;
215 : bool mStrips;
216 : };
217 :
218 : /**
219 : * Value of a global parameter
220 : */
221 : class txIGlobalParameter
222 : {
223 : public:
224 0 : txIGlobalParameter()
225 0 : {
226 0 : MOZ_COUNT_CTOR(txIGlobalParameter);
227 0 : }
228 0 : virtual ~txIGlobalParameter()
229 0 : {
230 0 : MOZ_COUNT_DTOR(txIGlobalParameter);
231 0 : }
232 : virtual nsresult getValue(txAExprResult** aValue) = 0;
233 : };
234 :
235 :
236 : #endif //TX_TXSTYLESHEET_H
|