Ginga  0.13.6
 All Classes Namespaces Functions Variables
DOMTreeErrorReporter.h
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.h,v 1.1 2008/10/01 20:54:36 marcio Exp $
19  */
20 #ifndef DOMTreeErrorReporter_H
21 #define DOMTreeErrorReporter_H
22 
23 #include <xercesc/util/XercesDefs.hpp>
24 #include <xercesc/sax/ErrorHandler.hpp>
25 #include <iostream>
26 using namespace std;
27 
28 XERCES_CPP_NAMESPACE_USE
29 
30 class DOMTreeErrorReporter : public ErrorHandler{
31 public:
32  // -----------------------------------------------------------------------
33  // Constructors and Destructor
34  // -----------------------------------------------------------------------
36  fSawErrors(false)
37  {
38  }
39 
41  {
42  }
43 
44 
45  // -----------------------------------------------------------------------
46  // Implementation of the error handler interface
47  // -----------------------------------------------------------------------
48  void warning(const SAXParseException& toCatch);
49  void error(const SAXParseException& toCatch);
50  void fatalError(const SAXParseException& toCatch);
51  void resetErrors();
52 
53  // -----------------------------------------------------------------------
54  // Getter methods
55  // -----------------------------------------------------------------------
56  bool getSawErrors() const;
57 
58  // -----------------------------------------------------------------------
59  // Private data members
60  //
61  // fSawErrors
62  // This is set if we get any errors, and is queryable via a getter
63  // method. Its used by the main code to suppress output if there are
64  // errors.
65  // -----------------------------------------------------------------------
66  bool fSawErrors;
67 };
68 
69 inline bool DOMTreeErrorReporter::getSawErrors() const
70 {
71  return fSawErrors;
72 }
73 
74 // ---------------------------------------------------------------------------
75 // This is a simple class that lets us do easy (though not terribly efficient)
76 // trancoding of XMLCh data to local code page for display.
77 // ---------------------------------------------------------------------------
78 class StrX
79 {
80 public :
81  // -----------------------------------------------------------------------
82  // Constructors and Destructor
83  // -----------------------------------------------------------------------
84  StrX(const XMLCh* const toTranscode)
85  {
86  // Call the private transcoding method
87  fLocalForm = XMLString::transcode(toTranscode);
88  }
89 
90  ~StrX()
91  {
92  XMLString::release(&fLocalForm);
93  }
94 
95 
96  // -----------------------------------------------------------------------
97  // Getter methods
98  // -----------------------------------------------------------------------
99  const char* localForm() const
100  {
101  return fLocalForm;
102  }
103 
104 private :
105  // -----------------------------------------------------------------------
106  // Private data members
107  //
108  // fLocalForm
109  // This is the local code page form of the string.
110  // -----------------------------------------------------------------------
111  char* fLocalForm;
112 };
113 
114 inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
115 {
116  target << toDump.localForm();
117  return target;
118 }
119 
120 #endif //DOMTreeErrorReporter_H
121 
Definition: DOMTreeErrorReporter.h:78
Definition: DOMTreeErrorReporter.h:30