fw4spl
Validator.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWRUNTIME_IO_VALIDATOR_HPP__
8 #define __FWRUNTIME_IO_VALIDATOR_HPP__
9 
10 #include <string>
11 #include <sstream>
12 
13 #include <boost/filesystem/path.hpp>
14 #include <libxml/tree.h>
15 #include <libxml/xmlschemastypes.h>
16 
17 #include "fwRuntime/config.hpp"
18 
19 namespace fwRuntime
20 {
21 
22 namespace io
23 {
24 
25 
26 
37 struct Validator
38 {
39 
47  FWRUNTIME_API Validator( const Validator &validator );
48 
56  FWRUNTIME_API Validator( const std::string & schema );
57 
65  FWRUNTIME_API Validator( const boost::filesystem::path & path );
66 
70  FWRUNTIME_API ~Validator();
71 
75  void clearErrorLog();
76 
82  FWRUNTIME_API const std::string getErrorLog() const;
83 
91  FWRUNTIME_API bool validate( const boost::filesystem::path & xmlFile );
92 
100  FWRUNTIME_API bool validate( xmlNodePtr node );
101 
107  FWRUNTIME_API std::string getXsdContent();
108 
109 
110  private:
111 
112  void initializeContext();
113 
114  std::string m_xsd_content;
115  std::ostringstream m_errorLog;
116 
117  typedef std::shared_ptr< xmlSchemaParserCtxt > SchemaParserCtxtSptr;
118  typedef std::shared_ptr< xmlSchema > SchemaSptr;
119  typedef std::shared_ptr< xmlSchemaValidCtxt > SchemaValidCtxtSptr;
120 
121  SchemaParserCtxtSptr m_schemaParserContext;
122  SchemaSptr m_schema;
123  SchemaValidCtxtSptr m_schemaValidContext;
124 
125  static void ErrorHandler( void * userData, xmlErrorPtr error );
126 
127 };
128 
129 
130 
131 } // namespace io
132 
133 } // namespace fwRuntime
134 
135 
136 
137 #endif /*__FWRUNTIME_IO_VALIDATOR_HPP__*/
void clearErrorLog()
Clears the error log.
Definition: Validator.cpp:66
FWRUNTIME_API const std::string getErrorLog() const
Retrieves the error log content.
Definition: Validator.cpp:73
FWRUNTIME_API bool validate(const boost::filesystem::path &xmlFile)
Validates the given file.
Definition: Validator.cpp:120
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
Implements an XML validator.
Definition: Validator.hpp:37
FWRUNTIME_API Validator(const Validator &validator)
Copy Constructor.
Definition: Validator.cpp:31
FWRUNTIME_API ~Validator()
Destructor.
Definition: Validator.cpp:60
FWRUNTIME_API std::string getXsdContent()
Returns the xsd content in string format.
Definition: Validator.cpp:196