source: icXML/icXML-devel/src/xercesc/framework/XMLValidator.cpp @ 2732

Last change on this file since 2732 was 2722, checked in by cameron, 7 years ago

Original Xerces files with import mods for icxercesc

File size: 9.9 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (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 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XMLValidator.cpp 635560 2008-03-10 14:10:09Z borisk $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <icxercesc/framework/XMLValidator.hpp>
26#include <icxercesc/util/PlatformUtils.hpp>
27#include <xercesc/util/XMLInitializer.hpp>
28#include <xercesc/util/XMLMsgLoader.hpp>
29#include <icxercesc/internal/XMLScanner.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33static XMLMsgLoader* sMsgLoader = 0;
34
35void XMLInitializer::initializeXMLValidator()
36{
37    sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgValidityDomain);
38
39    if (!sMsgLoader)
40      XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
41}
42
43void XMLInitializer::terminateXMLValidator()
44{
45    delete sMsgLoader;
46    sMsgLoader = 0;
47}
48
49// ---------------------------------------------------------------------------
50//  XMLValidator: Error emitting methods
51// ---------------------------------------------------------------------------
52
53//
54//  These methods are called whenever the scanner wants to emit an error.
55//  It handles getting the message loaded, doing token replacement, etc...
56//  and then calling the error handler, if its installed.
57//
58void XMLValidator::emitError(const XMLValid::Codes toEmit)
59{
60    // Bump the error count if it is not a warning
61    if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
62        fScanner->incrementErrorCount();
63
64    //  Call error reporter if we have one
65    if (fErrorReporter)
66    {
67        // Load the message into a local for display
68        const XMLSize_t msgSize = 1023;
69        XMLCh errText[msgSize + 1];
70
71        // load the text
72        if (!sMsgLoader->loadMsg(toEmit, errText, msgSize))
73        {
74          // <TBD> Probably should load a default msg here
75        }
76
77        //
78        //  Create a LastExtEntityInfo structure and get the reader manager
79        //  to fill it in for us. This will give us the information about
80        //  the last reader on the stack that was an external entity of some
81        //  sort (i.e. it will ignore internal entities.
82        //
83        ReaderMgr::LastExtEntityInfo lastInfo;
84        fReaderMgr->getLastExtEntityInfo(lastInfo);
85
86        fErrorReporter->error
87        (
88            toEmit
89            , XMLUni::fgValidityDomain
90            , XMLValid::errorType(toEmit)
91            , errText
92            , lastInfo.systemId
93            , lastInfo.publicId
94            , lastInfo.lineNumber
95            , lastInfo.colNumber
96        );
97    }
98
99    // Bail out if its fatal an we are to give up on the first fatal error
100    if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
101         || XMLValid::isFatal(toEmit))
102    &&  fScanner->getExitOnFirstFatal()
103    &&  !fScanner->getInException())
104    {
105        throw toEmit;
106    }
107}
108
109void XMLValidator::emitError(const  XMLValid::Codes toEmit
110                            , const XMLCh* const    text1
111                            , const XMLCh* const    text2
112                            , const XMLCh* const    text3
113                            , const XMLCh* const    text4)
114{
115    // Bump the error count if it is not a warning
116    if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
117        fScanner->incrementErrorCount();
118
119    //  Call error reporter if we have one
120    if (fErrorReporter)
121    {
122        //
123        //  Load the message into alocal and replace any tokens found in
124        //  the text.
125        //
126        const XMLSize_t maxChars = 2047;
127        XMLCh errText[maxChars + 1];
128
129        // load the text
130        if (!sMsgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, fScanner->getMemoryManager()))
131        {
132          // <TBD> Should probably load a default message here
133        }
134
135        //
136        //  Create a LastExtEntityInfo structure and get the reader manager
137        //  to fill it in for us. This will give us the information about
138        //  the last reader on the stack that was an external entity of some
139        //  sort (i.e. it will ignore internal entities.
140        //
141        ReaderMgr::LastExtEntityInfo lastInfo;
142        fReaderMgr->getLastExtEntityInfo(lastInfo);
143
144        fErrorReporter->error
145        (
146            toEmit
147            , XMLUni::fgValidityDomain
148            , XMLValid::errorType(toEmit)
149            , errText
150            , lastInfo.systemId
151            , lastInfo.publicId
152            , lastInfo.lineNumber
153            , lastInfo.colNumber
154        );
155    }
156
157    // Bail out if its fatal an we are to give up on the first fatal error
158    if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
159         || XMLValid::isFatal(toEmit))
160    &&  fScanner->getExitOnFirstFatal()
161    &&  !fScanner->getInException())
162    {
163        throw toEmit;
164    }
165}
166
167void XMLValidator::emitError(const  XMLValid::Codes toEmit
168                            , const char* const     text1
169                            , const char* const     text2
170                            , const char* const     text3
171                            , const char* const     text4)
172{
173    // Bump the error count if it is not a warning
174    if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
175        fScanner->incrementErrorCount();
176
177    //  Call error reporter if we have one
178    if (fErrorReporter)
179    {
180        //
181        //  Load the message into alocal and replace any tokens found in
182        //  the text.
183        //
184        const XMLSize_t maxChars = 2047;
185        XMLCh errText[maxChars + 1];
186
187        // load the text
188        if (!sMsgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, fScanner->getMemoryManager()))
189        {
190          // <TBD> Should probably load a default message here
191        }
192
193        //
194        //  Create a LastExtEntityInfo structure and get the reader manager
195        //  to fill it in for us. This will give us the information about
196        //  the last reader on the stack that was an external entity of some
197        //  sort (i.e. it will ignore internal entities.
198        //
199        ReaderMgr::LastExtEntityInfo lastInfo;
200        fReaderMgr->getLastExtEntityInfo(lastInfo);
201
202        fErrorReporter->error
203        (
204            toEmit
205            , XMLUni::fgValidityDomain
206            , XMLValid::errorType(toEmit)
207            , errText
208            , lastInfo.systemId
209            , lastInfo.publicId
210            , lastInfo.lineNumber
211            , lastInfo.colNumber
212        );
213    }
214
215    // Bail out if its fatal an we are to give up on the first fatal error
216    if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
217         || XMLValid::isFatal(toEmit))
218    &&  fScanner->getExitOnFirstFatal()
219    &&  !fScanner->getInException())
220    {
221        throw toEmit;
222    }
223}
224
225void XMLValidator::emitError(const  XMLValid::Codes toEmit
226                            , const XMLExcepts::Codes   originalExceptCode
227                            , const XMLCh* const    text1
228                            , const XMLCh* const    text2
229                            , const XMLCh* const    text3
230                            , const XMLCh* const    text4)
231{
232    // Bump the error count if it is not a warning
233    if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
234        fScanner->incrementErrorCount();
235
236    //  Call error reporter if we have one
237    if (fErrorReporter)
238    {
239        //
240        //  Load the message into alocal and replace any tokens found in
241        //  the text.
242        //
243        const XMLSize_t maxChars = 2047;
244        XMLCh errText[maxChars + 1];
245
246        // load the text
247        if (!sMsgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, fScanner->getMemoryManager()))
248        {
249          // <TBD> Should probably load a default message here
250        }
251
252        //
253        //  Create a LastExtEntityInfo structure and get the reader manager
254        //  to fill it in for us. This will give us the information about
255        //  the last reader on the stack that was an external entity of some
256        //  sort (i.e. it will ignore internal entities.
257        //
258        ReaderMgr::LastExtEntityInfo lastInfo;
259        fReaderMgr->getLastExtEntityInfo(lastInfo);
260
261        fErrorReporter->error
262        (
263            originalExceptCode
264            , XMLUni::fgExceptDomain    //XMLUni::fgValidityDomain
265            , XMLValid::errorType(toEmit)
266            , errText
267            , lastInfo.systemId
268            , lastInfo.publicId
269            , lastInfo.lineNumber
270            , lastInfo.colNumber
271        );
272    }
273
274    // Bail out if its fatal an we are to give up on the first fatal error
275    if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
276         || XMLValid::isFatal(toEmit))
277    &&  fScanner->getExitOnFirstFatal()
278    &&  !fScanner->getInException())
279    {
280        throw toEmit;
281    }
282}
283
284// ---------------------------------------------------------------------------
285//  XMLValidator: Hidden Constructors
286// ---------------------------------------------------------------------------
287XMLValidator::XMLValidator(XMLErrorReporter* const errReporter) :
288
289    fBufMgr(0)
290    , fErrorReporter(errReporter)
291    , fReaderMgr(0)
292    , fScanner(0)
293{
294}
295
296XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.