source: icXML/icXML-devel/samples/src/DOMCount/DOMCount.hpp @ 2733

Last change on this file since 2733 was 2733, checked in by cameron, 6 years ago

More path fixes.

File size: 4.5 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: DOMCount.hpp 471735 2006-11-06 13:53:58Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/dom/DOMErrorHandler.hpp>
26#include <icxercesc/util/XMLString.hpp>
27#if defined(XERCES_NEW_IOSTREAMS)
28#include <iostream>
29#else
30#include <iostream.h>
31#endif
32
33XERCES_CPP_NAMESPACE_USE
34
35// ---------------------------------------------------------------------------
36//  Simple error handler deriviative to install on parser
37// ---------------------------------------------------------------------------
38class DOMCountErrorHandler : public DOMErrorHandler
39{
40public:
41    // -----------------------------------------------------------------------
42    //  Constructors and Destructor
43    // -----------------------------------------------------------------------
44    DOMCountErrorHandler();
45    ~DOMCountErrorHandler();
46
47
48    // -----------------------------------------------------------------------
49    //  Getter methods
50    // -----------------------------------------------------------------------
51    bool getSawErrors() const;
52
53
54    // -----------------------------------------------------------------------
55    //  Implementation of the DOM ErrorHandler interface
56    // -----------------------------------------------------------------------
57    bool handleError(const DOMError& domError);
58    void resetErrors();
59
60
61private :
62    // -----------------------------------------------------------------------
63    //  Unimplemented constructors and operators
64    // -----------------------------------------------------------------------
65    DOMCountErrorHandler(const DOMCountErrorHandler&);
66    void operator=(const DOMCountErrorHandler&);
67
68
69    // -----------------------------------------------------------------------
70    //  Private data members
71    //
72    //  fSawErrors
73    //      This is set if we get any errors, and is queryable via a getter
74    //      method. Its used by the main code to suppress output if there are
75    //      errors.
76    // -----------------------------------------------------------------------
77    bool    fSawErrors;
78};
79
80
81// ---------------------------------------------------------------------------
82//  This is a simple class that lets us do easy (though not terribly efficient)
83//  trancoding of XMLCh data to local code page for display.
84// ---------------------------------------------------------------------------
85class StrX
86{
87public :
88    // -----------------------------------------------------------------------
89    //  Constructors and Destructor
90    // -----------------------------------------------------------------------
91    StrX(const XMLCh* const toTranscode)
92    {
93        // Call the private transcoding method
94        fLocalForm = XMLString::transcode(toTranscode);
95    }
96
97    ~StrX()
98    {
99        XMLString::release(&fLocalForm);
100    }
101
102
103    // -----------------------------------------------------------------------
104    //  Getter methods
105    // -----------------------------------------------------------------------
106    const char* localForm() const
107    {
108        return fLocalForm;
109    }
110
111private :
112    // -----------------------------------------------------------------------
113    //  Private data members
114    //
115    //  fLocalForm
116    //      This is the local code page form of the string.
117    // -----------------------------------------------------------------------
118    char*   fLocalForm;
119};
120
121inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
122{
123    target << toDump.localForm();
124    return target;
125}
126
127inline bool DOMCountErrorHandler::getSawErrors() const
128{
129    return fSawErrors;
130}
Note: See TracBrowser for help on using the repository browser.