[358] | 1 | /*
|
---|
| 2 | * Copyright 1999-2002,2004 The Apache Software Foundation.
|
---|
| 3 | *
|
---|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 5 | * you may not use this file except in compliance with the License.
|
---|
| 6 | * You may obtain a copy of the License at
|
---|
| 7 | *
|
---|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 9 | *
|
---|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
---|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 13 | * See the License for the specific language governing permissions and
|
---|
| 14 | * limitations under the License.
|
---|
| 15 | */
|
---|
| 16 |
|
---|
| 17 | /*
|
---|
| 18 | * $Id: DOMTreeErrorReporter.hpp,v 1.12 2004/09/08 13:55:31 peiyongz Exp $
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | #include <xercesc/util/XercesDefs.hpp>
|
---|
| 22 | #include <xercesc/sax/ErrorHandler.hpp>
|
---|
| 23 | #if defined(XERCES_NEW_IOSTREAMS)
|
---|
| 24 | #include <iostream>
|
---|
| 25 | #else
|
---|
| 26 | #include <iostream.h>
|
---|
| 27 | #endif
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | XERCES_CPP_NAMESPACE_USE
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | class DOMTreeErrorReporter : public ErrorHandler
|
---|
| 34 | {
|
---|
| 35 | public:
|
---|
| 36 | // -----------------------------------------------------------------------
|
---|
| 37 | // Constructors and Destructor
|
---|
| 38 | // -----------------------------------------------------------------------
|
---|
| 39 | DOMTreeErrorReporter() :
|
---|
| 40 | fSawErrors(false)
|
---|
| 41 | {
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | ~DOMTreeErrorReporter()
|
---|
| 45 | {
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | // -----------------------------------------------------------------------
|
---|
| 50 | // Implementation of the error handler interface
|
---|
| 51 | // -----------------------------------------------------------------------
|
---|
| 52 | void warning(const SAXParseException& toCatch);
|
---|
| 53 | void error(const SAXParseException& toCatch);
|
---|
| 54 | void fatalError(const SAXParseException& toCatch);
|
---|
| 55 | void resetErrors();
|
---|
| 56 |
|
---|
| 57 | // -----------------------------------------------------------------------
|
---|
| 58 | // Getter methods
|
---|
| 59 | // -----------------------------------------------------------------------
|
---|
| 60 | bool getSawErrors() const;
|
---|
| 61 |
|
---|
| 62 | // -----------------------------------------------------------------------
|
---|
| 63 | // Private data members
|
---|
| 64 | //
|
---|
| 65 | // fSawErrors
|
---|
| 66 | // This is set if we get any errors, and is queryable via a getter
|
---|
| 67 | // method. Its used by the main code to suppress output if there are
|
---|
| 68 | // errors.
|
---|
| 69 | // -----------------------------------------------------------------------
|
---|
| 70 | bool fSawErrors;
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | inline bool DOMTreeErrorReporter::getSawErrors() const
|
---|
| 74 | {
|
---|
| 75 | return fSawErrors;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | // ---------------------------------------------------------------------------
|
---|
| 79 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
| 80 | // trancoding of XMLCh data to local code page for display.
|
---|
| 81 | // ---------------------------------------------------------------------------
|
---|
| 82 | class StrX
|
---|
| 83 | {
|
---|
| 84 | public :
|
---|
| 85 | // -----------------------------------------------------------------------
|
---|
| 86 | // Constructors and Destructor
|
---|
| 87 | // -----------------------------------------------------------------------
|
---|
| 88 | StrX(const XMLCh* const toTranscode)
|
---|
| 89 | {
|
---|
| 90 | // Call the private transcoding method
|
---|
| 91 | fLocalForm = XMLString::transcode(toTranscode);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | ~StrX()
|
---|
| 95 | {
|
---|
| 96 | XMLString::release(&fLocalForm);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | // -----------------------------------------------------------------------
|
---|
| 101 | // Getter methods
|
---|
| 102 | // -----------------------------------------------------------------------
|
---|
| 103 | const char* localForm() const
|
---|
| 104 | {
|
---|
| 105 | return fLocalForm;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | private :
|
---|
| 109 | // -----------------------------------------------------------------------
|
---|
| 110 | // Private data members
|
---|
| 111 | //
|
---|
| 112 | // fLocalForm
|
---|
| 113 | // This is the local code page form of the string.
|
---|
| 114 | // -----------------------------------------------------------------------
|
---|
| 115 | char* fLocalForm;
|
---|
| 116 | };
|
---|
| 117 |
|
---|
| 118 | inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
| 119 | {
|
---|
| 120 | target << toDump.localForm();
|
---|
| 121 | return target;
|
---|
| 122 | }
|
---|
| 123 |
|
---|