source: NonGTP/Xerces/xerces/samples/DOMCount/DOMCount.hpp @ 358

Revision 358, 5.6 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-2000,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 * $Log: DOMCount.hpp,v $
19 * Revision 1.11  2004/09/08 13:55:31  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.10  2003/05/30 09:36:35  gareth
23 * Use new macros for iostream.h and std:: issues.
24 *
25 * Revision 1.9  2003/02/05 18:53:22  tng
26 * [Bug 11915] Utility for freeing memory.
27 *
28 * Revision 1.8  2002/11/05 21:46:19  tng
29 * Explicit code using namespace in application.
30 *
31 * Revision 1.7  2002/06/18 16:19:40  knoaman
32 * Replace XercesDOMParser with DOMBuilder for parsing XML documents.
33 *
34 * Revision 1.6  2002/02/01 22:35:01  peiyongz
35 * sane_include
36 *
37 * Revision 1.5  2000/10/20 22:00:35  andyh
38 * DOMCount sample Minor cleanup - rename error handler class to say that it is an error handler.
39 *
40 * Revision 1.4  2000/03/02 19:53:39  roddey
41 * This checkin includes many changes done while waiting for the
42 * 1.1.0 code to be finished. I can't list them all here, but a list is
43 * available elsewhere.
44 *
45 * Revision 1.3  2000/02/11 02:43:55  abagchi
46 * Removed StrX::transcode
47 *
48 * Revision 1.2  2000/02/06 07:47:17  rahulj
49 * Year 2K copyright swat.
50 *
51 * Revision 1.1.1.1  1999/11/09 01:09:52  twl
52 * Initial checkin
53 *
54 * Revision 1.5  1999/11/08 20:43:35  rahul
55 * Swat for adding in Product name and CVS comment log variable.
56 *
57 */
58
59// ---------------------------------------------------------------------------
60//  Includes
61// ---------------------------------------------------------------------------
62#include <xercesc/dom/DOMErrorHandler.hpp>
63#include <xercesc/util/XMLString.hpp>
64#if defined(XERCES_NEW_IOSTREAMS)
65#include <iostream>
66#else
67#include <iostream.h>
68#endif
69
70XERCES_CPP_NAMESPACE_USE
71
72// ---------------------------------------------------------------------------
73//  Simple error handler deriviative to install on parser
74// ---------------------------------------------------------------------------
75class DOMCountErrorHandler : public DOMErrorHandler
76{
77public:
78    // -----------------------------------------------------------------------
79    //  Constructors and Destructor
80    // -----------------------------------------------------------------------
81    DOMCountErrorHandler();
82    ~DOMCountErrorHandler();
83
84
85    // -----------------------------------------------------------------------
86    //  Getter methods
87    // -----------------------------------------------------------------------
88    bool getSawErrors() const;
89
90
91    // -----------------------------------------------------------------------
92    //  Implementation of the DOM ErrorHandler interface
93    // -----------------------------------------------------------------------
94    bool handleError(const DOMError& domError);
95    void resetErrors();
96
97
98private :
99    // -----------------------------------------------------------------------
100    //  Unimplemented constructors and operators
101    // -----------------------------------------------------------------------
102    DOMCountErrorHandler(const DOMCountErrorHandler&);
103    void operator=(const DOMCountErrorHandler&);
104
105
106    // -----------------------------------------------------------------------
107    //  Private data members
108    //
109    //  fSawErrors
110    //      This is set if we get any errors, and is queryable via a getter
111    //      method. Its used by the main code to suppress output if there are
112    //      errors.
113    // -----------------------------------------------------------------------
114    bool    fSawErrors;
115};
116
117
118// ---------------------------------------------------------------------------
119//  This is a simple class that lets us do easy (though not terribly efficient)
120//  trancoding of XMLCh data to local code page for display.
121// ---------------------------------------------------------------------------
122class StrX
123{
124public :
125    // -----------------------------------------------------------------------
126    //  Constructors and Destructor
127    // -----------------------------------------------------------------------
128    StrX(const XMLCh* const toTranscode)
129    {
130        // Call the private transcoding method
131        fLocalForm = XMLString::transcode(toTranscode);
132    }
133
134    ~StrX()
135    {
136        XMLString::release(&fLocalForm);
137    }
138
139
140    // -----------------------------------------------------------------------
141    //  Getter methods
142    // -----------------------------------------------------------------------
143    const char* localForm() const
144    {
145        return fLocalForm;
146    }
147
148private :
149    // -----------------------------------------------------------------------
150    //  Private data members
151    //
152    //  fLocalForm
153    //      This is the local code page form of the string.
154    // -----------------------------------------------------------------------
155    char*   fLocalForm;
156};
157
158inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
159{
160    target << toDump.localForm();
161    return target;
162}
163
164inline bool DOMCountErrorHandler::getSawErrors() const
165{
166    return fSawErrors;
167}
Note: See TracBrowser for help on using the repository browser.