nidas v1.2.3
XMLParser.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2005, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_CORE_XMLPARSER_H
28#define NIDAS_CORE_XMLPARSER_H
29
30#include "XMLException.h"
31
34
35#include <xercesc/dom/DOMImplementation.hpp>
36#include <xercesc/dom/DOMErrorHandler.hpp>
37#include <xercesc/dom/DOMDocument.hpp>
38#include <xercesc/sax/InputSource.hpp>
39
40#include <xercesc/dom/DOMLSParser.hpp>
41
42#include <string>
43#include <map>
44#include <list>
45
46namespace nidas { namespace core {
47
49public:
53 static xercesc::DOMImplementation *getImplementation();
54 static void terminate();
55
56private:
57 static xercesc::DOMImplementation *_impl;
59};
60
61class XMLErrorHandler : public xercesc::DOMErrorHandler
62{
63public:
64 // -----------------------
65 // Constructors and Destructor
66 // ----------------------
69
70 // --------------------------
71 // Implementation of the DOM ErrorHandler interface
72 // -------------------------
73 bool handleError(const xercesc::DOMError& domError);
74
75 void resetErrors();
76
77 int getWarningCount() const { return _warningMessages.size(); }
78
79 const std::list<std::string>& getWarningMessages() const
80 { return _warningMessages; }
81
82 const XMLException* getXMLException() const { return _xmlException; }
83
84private :
85
86 // -----------------------------
87 // Unimplemented constructors and operators
88 // ----------------------------
90
92
96 std::list<std::string> _warningMessages;
97
102
103};
104
111xercesc::DOMDocument* parseXMLConfigFile(const std::string& xmlFileName);
112
117public:
118
125 XMLParser();
126
131 virtual ~XMLParser();
132
146 void setDOMValidation(bool val);
147
158 void setDOMValidateIfSchema(bool val);
159
167 void setDOMNamespaces(bool val);
168
176 void setXercesSchema(bool val);
177
189 void setXercesSchemaFullChecking(bool val);
190
201 void setDOMDatatypeNormalization(bool val);
202
216 void setXercesUserAdoptsDOMDocument(bool val);
217
218 void setXercesHandleMultipleImports(bool val);
219
220 void setXercesDoXInclude(bool val);
221
225 xercesc::DOMDocument* parse(const std::string& xmlFile, bool verbose=true);
226
230 xercesc::DOMDocument* parse(xercesc::InputSource& source);
231
241 xercesc::DOMDocument* parseString(const std::string& xml);
242
249 static
250 xercesc::DOMDocument*
251 ParseString(const std::string& xml);
252
253protected:
254
255 xercesc::DOMImplementation *_impl;
256
257 xercesc::DOMLSParser *_parser;
259
260private:
261
264
267};
268
275public:
276
281
282 static void destroyInstance();
283
295 xercesc::DOMDocument* parse(const std::string& xmlFile);
296
300 /*
301 xercesc::DOMDocument* parse(xercesc::InputSource& source)
302 throw(nidas::core::XMLException)
303 {
304 return XMLParser::parse(source);
305 }
306 */
307
311 static time_t getFileModTime(const std::string& name);
312
313protected:
319
320protected:
323
324 std::map<std::string,time_t> _modTimeCache;
325 std::map<std::string,xercesc::DOMDocument*> _docCache;
326
328
329private:
332
335};
336
337}} // namespace nidas namespace core
338
339#endif
340
Derived class of XMLParser that keeps its DOMDocuments when parsing an XML disk file,...
Definition XMLParser.h:274
static XMLCachingParser * getInstance()
Definition XMLParser.cc:298
static nidas::util::Mutex _instanceLock
Definition XMLParser.h:322
static time_t getFileModTime(const std::string &name)
Parse from an InputSource.
Definition XMLParser.cc:358
~XMLCachingParser()
Definition XMLParser.cc:322
static void destroyInstance()
Definition XMLParser.cc:308
std::map< std::string, time_t > _modTimeCache
Definition XMLParser.h:324
static XMLCachingParser * _instance
Definition XMLParser.h:321
XMLCachingParser & operator=(const XMLCachingParser &)
No assignment.
nidas::util::Mutex _cacheLock
Definition XMLParser.h:327
std::map< std::string, xercesc::DOMDocument * > _docCache
Definition XMLParser.h:325
xercesc::DOMDocument * parse(const std::string &xmlFile)
Parse from a file.
Definition XMLParser.cc:332
XMLCachingParser()
Definition XMLParser.cc:317
XMLCachingParser(const XMLCachingParser &)
No copying.
Definition XMLParser.h:62
XMLException * _xmlException
Accumulated error messages.
Definition XMLParser.h:101
bool handleError(const xercesc::DOMError &domError)
Definition XMLParser.cc:258
const XMLException * getXMLException() const
Definition XMLParser.h:82
XMLErrorHandler(const XMLErrorHandler &)
~XMLErrorHandler()
Definition XMLParser.cc:249
const std::list< std::string > & getWarningMessages() const
Definition XMLParser.h:79
XMLErrorHandler()
Definition XMLParser.cc:245
std::list< std::string > _warningMessages
Accumulated warning messages.
Definition XMLParser.h:96
int getWarningCount() const
Definition XMLParser.h:77
void resetErrors()
Definition XMLParser.cc:284
void operator=(const XMLErrorHandler &)
Exception which can be built from an xerces::XMLException, xercesc::SAXException, or xercesc::DOMExce...
Definition XMLException.h:44
Definition XMLParser.h:48
static xercesc::DOMImplementation * _impl
Definition XMLParser.h:57
static xercesc::DOMImplementation * getImplementation()
Definition XMLParser.cc:55
static void terminate()
Definition XMLParser.cc:77
static nidas::util::Mutex _lock
Definition XMLParser.h:58
Wrapper class around xerces-c DOMBuilder to parse XML.
Definition XMLParser.h:116
void setDOMValidateIfSchema(bool val)
Enable/disable schema validation.
Definition XMLParser.cc:124
void setXercesHandleMultipleImports(bool val)
Definition XMLParser.cc:148
void setDOMDatatypeNormalization(bool val)
Enable/disable datatype normalization.
Definition XMLParser.cc:140
xercesc::DOMLSParser * _parser
Definition XMLParser.h:257
void setDOMNamespaces(bool val)
Enable/disable namespace processing.
Definition XMLParser.cc:128
xercesc::DOMDocument * parse(const std::string &xmlFile, bool verbose=true)
Definition XMLParser.cc:175
XMLParser()
Constructor.
Definition XMLParser.cc:90
XMLErrorHandler _errorHandler
Definition XMLParser.h:258
void setXercesSchemaFullChecking(bool val)
Enable/disable full schema constraint checking, including checking which may be time-consuming or mem...
Definition XMLParser.cc:136
xercesc::DOMImplementation * _impl
Definition XMLParser.h:255
XMLParser & operator=(const XMLParser &)
No assignment.
xercesc::DOMDocument * parseString(const std::string &xml)
Parse XML string into a document.
Definition XMLParser.cc:369
void setXercesSchema(bool val)
Enable/disable schema support.
Definition XMLParser.cc:132
static xercesc::DOMDocument * ParseString(const std::string &xml)
Call parseString() on a default XMLParser instance.
Definition XMLParser.cc:381
void setXercesUserAdoptsDOMDocument(bool val)
Control who owns DOMDocument pointer.
Definition XMLParser.cc:144
XMLParser(const XMLParser &)
No copying.
void setXercesDoXInclude(bool val)
Definition XMLParser.cc:156
virtual ~XMLParser()
Nuke the parser.
Definition XMLParser.cc:166
void setDOMValidation(bool val)
DOMBuilder::setFilter is not yet implemented in xerces c++ 2.6.0 void setFilter(xercesc::DOMBuilderFi...
Definition XMLParser.cc:120
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
static int verbose
Definition lidar_vel.cc:45
xercesc::DOMDocument * parseXMLConfigFile(const std::string &xmlFileName)
Utility function which creates a temporary XMLParser, sets the options we typically want and parses t...
Definition XMLParser.cc:223
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31