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