source: icXML/icXML-devel/tests/src/InitTermTest/InitTermTest.hpp @ 2726

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

Add original Xerces tests and samples directories

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