2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Sablotron XSLT Processor.
14 * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16 * Ginger Alliance Ltd. All Rights Reserved.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU General Public License Version 2 or later (the
22 * "GPL"), in which case the provisions of the GPL are applicable
23 * instead of those above. If you wish to allow use of your
24 * version of this file only under the terms of the GPL and not to
25 * allow others to use your version of this file under the MPL,
26 * indicate your decision by deleting the provisions above and
27 * replace them with the notice and other provisions required by
28 * the GPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under either the MPL or the
38 #define PROC_ARENA_SIZE 0x10000
49 PHRASE_SABEXT_NAMESPACE,
65 //#include "context.h"
67 extern const char *theXSLTNamespace;
70 class TreeConstructer;
78 typedef PList<Expression*> ExprList;
80 /*****************************************************************
83 an item of RuleSList describing a rule
85 *****************************************************************/
90 RuleItem(XSLElement *,double, QName &, QName *);
102 /*****************************************************************
107 *****************************************************************/
109 class RuleSList : public SList<RuleItem*>
114 int compare(int first, int second, void *data);
115 XSLElement* findByName(const Tree &t, const QName &q) const;
118 /*****************************************************************
122 *****************************************************************/
128 DataLineItem(Sit S_);
138 class DataLinesList: public PList<DataLineItem*>
141 int findNum(Str &absoluteURI, Bool _isXSL,
143 Tree* getTree(Str &absoluteURI, Bool _isXSL, DLAccessMode _mode);
144 eFlag addLine(Sit S, DataLine *d, Tree *t, Bool isXSL,
145 Bool preparsedTree = FALSE);
149 /*****************************************************************
153 *****************************************************************/
155 class OutputDocumentList: public PList<OutputDocument*>
162 /*****************************************************************
166 *****************************************************************/
173 class Processor /* : public SabObj */
180 eFlag open(Sit S, const char *sheetURI, const char *inputURI);
181 eFlag run(Sit S, const char* resultURI, NodeHandle doc = NULL);
182 eFlag execute(Sit S, Vertex *, Context *&, Bool resolvingGlobals);
183 eFlag execute(Sit S, VertexList&, Context *&, Bool resolvingGlobals);
185 // finds the best matching rule imported into styleSheet
186 // and applies it to the current node of c
187 eFlag execApplyImports(Sit S, Context *c, SubtreeInfo *subtree,
188 Bool resolvingGlobals);
190 // executes the default rule for the current node of c
191 eFlag builtinRule(Sit S, Context *c, Bool resolvingGlobals);
194 unsigned long allocObjects,
198 Expression* getVarBinding(QName &);
200 OutputterObj* outputter()
202 if (outputters_.number())
203 return outputters_.last();
206 QName* getCurrentMode();
207 void pushMode(QName *);
209 eFlag readTreeFromURI(Sit S, Tree*& newTree, const Str& location,
210 const Str& base, Bool isXSL,
211 Bool ignoreErr = FALSE);
212 eFlag pushOutputterForURI(Sit S, Str& location, Str& base,
213 OutputDefinition *outDef = NULL);
214 eFlag createOutputterForURI(Sit S, Str& location, Str& base,
215 OutputterObj*& result,
216 OutputDefinition *outDef = NULL);
217 eFlag pushTreeConstructer(Sit S, TreeConstructer *&newTC, Tree *t,
218 SAXOutputType ot = SAXOUTPUT_COPY_TREE);
219 eFlag pushOutputter(Sit S, OutputterObj* out_);
220 eFlag popOutputter(Sit S);
221 eFlag popOutputterNoFree(Sit S);
222 eFlag popTreeConstructer(Sit S, TreeConstructer *theTC);
223 eFlag processVertexAfterParse(Sit S, Vertex *, Tree *, TreeConstructer *tc);
225 eFlag setHandler(Sit S, HandlerType type, void *handler, void *userData);
226 SchemeHandler* getSchemeHandler(void **udata);
227 MessageHandler* getMessageHandler(void **udata);
228 SAXHandler* getSAXHandler(void **udata);
229 MiscHandler* getMiscHandler(void **udata);
230 EncHandler* getEncHandler(void **udata);
232 void* getHandlerUserData(HandlerType type, void *handler);
234 void setHardEncoding(const Str& hardEncoding_);
235 const Str& getHardEncoding() const;
237 eFlag addLineNoTree(Sit S, DataLine *&d, Str &absolute, Bool isXSL);
238 eFlag addLineParse(Sit S, Tree *& newTree, Str &absolute,
239 Bool isXSL, Bool ignoreErr = FALSE);
240 eFlag addLineTreeOnly(Sit S, DataLine *&d, Str &absolute, Bool isXSL,
242 void copyArg(Sit S, const Str& argName, int* argOrdinal, char*& newCopy);
243 eFlag getArg(Sit S, const char*, char*&, Bool);
244 eFlag useArg(Sit S, const char *name, const char *val);
245 eFlag useTree(Sit S, const char *name, Tree *t);
246 eFlag freeResultArgs(Sit S);
247 eFlag addGlobalParam(Sit S, const char *name, const char *val);
248 eFlag useGlobalParam(Sit S, const char *name, const char *val);
249 eFlag useGlobalParams(Sit S);
250 const Str& baseForVertex(Sit S, Element *v);
251 const Str& findBaseURI(Sit S, const Str& unmappedBase);
252 void addBaseURIMapping(const Str& scheme, const Str& mapping);
253 void setHardBaseURI(const char* hardBase);
255 void setInstanceData(void *idata)
257 instanceData = idata;
260 void* getInstanceData()
265 void rememberSituation(Situation *SP)
267 instanceSituation = SP;
270 void rememberMasterSituation(Situation *SP)
272 instanceSituation = SP;
273 hasMasterSituation = TRUE;
276 Situation* recallSituation()
278 return instanceSituation;
281 Bool situationIsMaster()
283 return hasMasterSituation;
286 void prepareForRun();
287 void cleanupAfterRun(Situation *Sp);
288 const QName theEmptyQName;
289 SabArena* getArena();
290 //Str getAliasedName(const EQName& name, NamespaceStack& currNamespaces,
292 void getAliasedName(EQName & name, Bool & aliased);
293 void report(Sit S, MsgType type, MsgCode code,
294 const Str &arg1, const Str &arg2) const;
295 Bool getAddedFlag() {return addedFlag;}
296 eFlag addKey(Sit S, const EQName& ename,
297 Expression& match, Expression &use);
298 eFlag getKeyNodes(Sit S, const EQName& ename,
299 const Str& value, Context& result, SXP_Document doc) const;
300 eFlag makeKeysForDoc(Sit S, SXP_Document doc);
301 DecimalFormatList& decimals()
305 void initForSXP(Tree *baseTree);
306 void cleanupAfterSXP();
307 Bool supportsFunction(Str &uri, Str &name);
309 eFlag evaluateJavaScript(Sit S, Str &uri, DStr &script);
310 eFlag callJSFunction(Sit S, Context *c, Str &uri, Str &name,
311 ExprList &atoms, Expression &retxpr);
313 StrStrList &getArgList() {return argList;};
314 Str getNextNSPrefix();
315 // resolve a global variable identified by name and possibly pointer
316 // if varElem != NULL. sets 'name' accordingly
317 eFlag resolveGlobal(Sit S, Context *c, QName &name, XSLElement *varElem = NULL);
318 // resolve all global vars before executing
319 //eFlag resolveGlobals(Sit S, Context *c);
320 eFlag stripTree(Sit S, Tree &tree);
321 eFlag stripElement(Sit S, Daddy *e);
322 Bool processingExternal() { return runsOnExternal; };
323 void pushInBinding(Bool val);
326 eFlag pushDocumentDefinition(Sit S, OutputDefinition *def,
328 eFlag popDocumentDefinition(Sit S);
329 eFlag createOutputDocument(Sit S, Str& href, OutputDocument*& doc,
330 OutputDefinition *def);
331 eFlag startDocument(Sit S, OutputDocument *doc);
332 eFlag finishDocument(Sit S, OutputDocument *doc, Bool canClose);
333 eFlag prefixIsAliasTarget(Sit S, const Str& prefix, Bool& result);
336 eFlag openCommon(Sit S);
337 eFlag execApplyTemplates(Sit S, Context *c, Bool resolvingGlobals);
338 eFlag execApply(Sit S, Context *c, Bool resolvingGlobals);
341 DataLinesList datalines;
342 PList<OutputterObj*> outputters_;
344 SchemeHandler *theSchemeHandler;
345 MessageHandler *theMessageHandler;
346 SAXHandler *theSAXHandler;
347 MiscHandler *theMiscHandler;
348 EncHandler *theEncHandler;
356 void freeNonArgDatalines();
357 StrStrList baseURIMappings, globalParamsList;
360 Situation *instanceSituation;
361 Bool hasMasterSituation;
364 DecimalFormatList decimalsList;
366 JSContextList jscontexts;
369 NodeHandle inputRoot;
370 List<Bool> inBinding;
371 PList<OutputDefinition*> documentDefinitions;
372 OutputDocumentList outputDocuments;
375 #endif //ifndef ProcHIncl