Initial revision
[TestXSLT.git] / libsablot / src / engine / situa.h
1 /* 
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/
6  * 
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.
11  * 
12  * The Original Code is the Sablotron XSLT Processor.
13  * 
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.
17  * 
18  * Contributor(s):
19  * 
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
30  * GPL.
31  */
32
33 #ifndef SituaHIncl
34 #define SituaHIncl
35
36 // GP: clean
37
38 #include "base.h"
39 #include "error.h"
40 #include "sxpath.h"
41
42 //enum ErrCode;
43
44 /*
45 Mode constants for the situation object.
46 */
47
48 enum MsgType
49 {
50     MT_ERROR,
51         MT_WARN,
52         MT_LOG
53 };
54
55 enum MsgDestination
56 {
57     MD_NONE,
58         MD_FILE,
59         MD_CHERROR
60 };
61
62 /*
63 The following class keeps track of the current situation: which vertex
64 is currently being parsed/processed etc. This is used solely for error reporting.
65 */
66
67 class XSLElement;
68 class Vertex;
69 #include "datastr.h"
70
71 class Processor;
72 class DOMProvider;
73 class DOMProviderStandard;
74 class DOMProviderUniversal;
75
76 class SituaInfo
77 {
78 public:
79     MsgCode pending;
80     Vertex *currV;
81     Str currFile;
82     Str currMsg;
83     int currLine;
84     int currSAXLine;
85     int SDOMExceptionCode;
86     SituaInfo()
87     {
88         pending = E_OK;
89         currLine = 0;
90         currSAXLine = 0;
91         SDOMExceptionCode = 0;
92     }
93     SituaInfo& operator= (const SituaInfo& other);
94     void clear();
95 };
96
97 class Recoder;
98
99 class Situation
100 {
101 public:
102     Situation();
103     ~Situation();
104     
105     Recoder& recoder() const;
106     
107     void setFlag(SablotFlag f);
108     Bool hasFlag(SablotFlag f);
109     void resetFlag(SablotFlag f);
110     void setFlags(int f);
111     int getFlags();
112
113     // set vertex information for the current message 
114     void setCurrV(Vertex *v);
115     
116     // same, including the document identification 
117     void setCurrVDoc(Vertex *v);
118     
119     // set file (URI) information for the current message 
120     void setCurrFile(const Str &);
121     
122     // set line number information for the current message 
123     void setCurrLine(int);
124
125     // set line number information while SAX parsing is in progress
126     void setCurrSAXLine(int);
127     int getCurrSAXLine();
128     
129     // set pointer to associated Processor (will be NULL if not processing)
130     void setProcessor(Processor *P) {proc = P;}
131     
132     // get pointer to associated Processor
133     Processor* getProcessor() const {return proc;}
134     
135     // common messaging routine for reporting errors, warnings and log messages
136     // (distinguished by 'type')
137     void message(MsgType type, MsgCode code, const Str &arg1, const Str &arg2);
138     
139     // reset the situation's state
140     void clear();
141     
142     // clear the error-related information
143     void clearError();
144     
145     // detect pending error
146     Bool isError();
147     
148     // get pending error code
149     int getError() const;
150     
151     // set output files for errors and for log messages
152     eFlag msgOutputFile(char *_errwfn, char *_logfn);
153     
154     // erase the log
155     eFlag eraseLog(char *newLogFile);
156     
157     // return current time
158     Str timeStr();
159     
160     // open the default output files
161     eFlag openDefaultFiles();
162     
163     // close files in use
164     eFlag closeFiles();
165     
166     // return the pending error message (with all substitutions)
167     const Str& getMessage();
168     
169     void setSXPOptions(unsigned long options);
170     unsigned long getSXPOptions();
171     void setSXPMaskBit(int mask);
172     int getSXPMaskBit();
173
174     void setSDOMExceptionCode(int code);
175     
176     int getSDOMExceptionCode() const;
177     
178     void getSDOMExceptionExtra(MsgCode& theCode, 
179                                Str& theMessage, Str& theDocument, 
180                                int& theLine) const;
181     
182     void swapProcessor(void *&proc_);
183     
184     const Str& findBaseURI(const Str& unmappedBase);
185     
186     void setDOMProvider(DOMHandler *domh, void* udata);
187     
188     DOMProvider& dom() {return *(DOMProvider*)theProvider; }
189     
190     Bool domExternal(NodeHandle n) {return (unsigned long)n & 1;}
191 private:
192     Processor* proc;
193     SituaInfo info, infoDOM;
194     
195     void generateMessage(MsgType, MsgCode, const Str &arg1, const Str &arg2,
196         Str &theMessage);
197     
198     // report error (in this case to self)
199     void report(Situation *S, MsgType, MsgCode, const Str &, const Str &);
200     FILE *logfile, *errwfile;
201     int flags;
202     unsigned long sxpOptions;
203     Recoder *theRecoder;
204     DOMProviderUniversal *theProvider;
205 };
206
207 typedef Situation & Sit;
208
209 #endif // SituaHIncl