source: icXML/icXML-devel/src/xercesc/validators/schema/XSDErrorReporter.cpp

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

Original Xerces files with import mods for icxercesc

File size: 7.0 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//  Includes
20// ---------------------------------------------------------------------------
21#include <icxercesc/util/PlatformUtils.hpp>
22#include <icxercesc/util/XMLString.hpp>
23#include <xercesc/framework/XMLErrorCodes.hpp>
24#include <xercesc/framework/XMLValidityCodes.hpp>
25#include <xercesc/framework/XMLErrorReporter.hpp>
26#include <xercesc/util/XMLMsgLoader.hpp>
27#include <xercesc/util/XMLInitializer.hpp>
28#include <xercesc/validators/schema/XSDErrorReporter.hpp>
29#include <xercesc/validators/schema/XSDLocator.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33// ---------------------------------------------------------------------------
34//  Local static data
35// ---------------------------------------------------------------------------
36static XMLMsgLoader*  gErrMsgLoader = 0;
37static XMLMsgLoader*  gValidMsgLoader = 0;
38
39void XMLInitializer::initializeXSDErrorReporter()
40{
41    gErrMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLErrDomain);
42
43    if (!gErrMsgLoader)
44      XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
45
46    gValidMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgValidityDomain);
47
48    if (!gValidMsgLoader)
49      XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
50}
51
52void XMLInitializer::terminateXSDErrorReporter()
53{
54    delete gErrMsgLoader;
55    gErrMsgLoader = 0;
56
57    delete gValidMsgLoader;
58    gValidMsgLoader = 0;
59}
60
61// ---------------------------------------------------------------------------
62//  XSDErrorReporter: Constructors and Destructor
63// ---------------------------------------------------------------------------
64XSDErrorReporter::XSDErrorReporter(XMLErrorReporter* const errorReporter) :
65    fExitOnFirstFatal(false)
66    , fErrorReporter(errorReporter)
67{
68
69}
70
71
72// ---------------------------------------------------------------------------
73//  XSDErrorReporter: Error reporting
74// ---------------------------------------------------------------------------
75void XSDErrorReporter::emitError(const unsigned int toEmit,
76                                 const XMLCh* const msgDomain,
77                                 const Locator* const aLocator)
78{
79    // Bump the error count if it is not a warning
80//    if (XMLErrs::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
81//        incrementErrorCount();
82
83    //
84    //  Load the message into alocal and replace any tokens found in
85    //  the text.
86    //
87    const XMLSize_t msgSize = 1023;
88    XMLCh errText[msgSize + 1];
89    XMLMsgLoader* msgLoader = gErrMsgLoader;
90    XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit);
91
92    if (XMLString::equals(msgDomain, XMLUni::fgValidityDomain)) {
93
94        errType = XMLValid::errorType((XMLValid::Codes) toEmit);
95        msgLoader = gValidMsgLoader;
96    }
97
98    if (!msgLoader->loadMsg(toEmit, errText, msgSize))
99    {
100                // <TBD> Should probably load a default message here
101    }
102
103    if (fErrorReporter)
104        fErrorReporter->error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(),
105                              aLocator->getPublicId(), aLocator->getLineNumber(),
106                              aLocator->getColumnNumber());
107
108    // Bail out if its fatal an we are to give up on the first fatal error
109    if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal)
110        throw (XMLErrs::Codes) toEmit;
111}
112
113void XSDErrorReporter::emitError(const unsigned int toEmit,
114                                 const XMLCh* const msgDomain,
115                                 const Locator* const aLocator,
116                                 const XMLCh* const text1,
117                                 const XMLCh* const text2,
118                                 const XMLCh* const text3,
119                                 const XMLCh* const text4,
120                                 MemoryManager* const manager)
121{
122    // Bump the error count if it is not a warning
123//    if (XMLErrs::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
124//        incrementErrorCount();
125
126    //
127    //  Load the message into alocal and replace any tokens found in
128    //  the text.
129    //
130    const XMLSize_t maxChars = 2047;
131    XMLCh errText[maxChars + 1];
132    XMLMsgLoader* msgLoader = gErrMsgLoader;
133    XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit);
134
135    if (XMLString::equals(msgDomain, XMLUni::fgValidityDomain)) {
136
137        errType = XMLValid::errorType((XMLValid::Codes) toEmit);
138        msgLoader = gValidMsgLoader;
139    }
140
141    if (!msgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, manager))
142    {
143                // <TBD> Should probably load a default message here
144    }
145
146    if (fErrorReporter)
147        fErrorReporter->error(toEmit, msgDomain, errType, errText, aLocator->getSystemId(),
148                              aLocator->getPublicId(), aLocator->getLineNumber(),
149                              aLocator->getColumnNumber());
150
151    // Bail out if its fatal an we are to give up on the first fatal error
152    if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal)
153        throw (XMLErrs::Codes) toEmit;
154}
155
156void XSDErrorReporter::emitError(const XMLException&  except,
157                                 const Locator* const aLocator)
158{
159    const XMLCh* const  errText = except.getMessage();
160    const unsigned int  toEmit = except.getCode();
161    //Before the code was modified to call this routine it used to use
162    //the XMLErrs::DisplayErrorMessage error message, which is just {'0'}
163    //and that error message has errType of Error.  So to be consistent
164    //with previous behaviour set the errType to be Error instead of
165    //getting the error type off of the exception.
166    //XMLErrorReporter::ErrTypes errType = XMLErrs::errorType((XMLErrs::Codes) toEmit);
167    XMLErrorReporter::ErrTypes errType = XMLErrorReporter::ErrType_Error;
168
169    if (fErrorReporter)
170        fErrorReporter->error(toEmit, XMLUni::fgExceptDomain, errType, errText, aLocator->getSystemId(),
171                              aLocator->getPublicId(), aLocator->getLineNumber(),
172                              aLocator->getColumnNumber());
173
174    // Bail out if its fatal an we are to give up on the first fatal error
175    //if (errType == XMLErrorReporter::ErrType_Fatal && fExitOnFirstFatal)
176    //    throw (XMLErrs::Codes) toEmit;
177}
178
179XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.