Imported Upstream version 2.91.2
[platform/upstream/libxml++.git] / libxml++ / validators / validator.h
1 /* validator.h
2  * libxml++ and this file are copyright (C) 2000 by Ari Johnson,
3  * (C) 2002-2004 by the libxml dev team and
4  * are covered by the GNU Lesser General Public License, which should be
5  * included with libxml++ as the file COPYING.
6  */
7
8 #ifndef __LIBXMLPP_VALIDATOR_H
9 #define __LIBXMLPP_VALIDATOR_H
10
11 #ifdef _MSC_VER //Ignore warnings about the Visual C++ Bug, where we can not do anything
12 #pragma warning (disable : 4786)
13 #endif
14
15 #include <libxml++/noncopyable.h>
16 #include <libxml++/exceptions/validity_error.h>
17 #include <libxml++/exceptions/internal_error.h>
18 #include <memory> // std::unique_ptr
19 #include <string>
20
21 extern "C" {
22   struct _xmlValidCtxt;
23 }
24
25 namespace xmlpp {
26
27 class Document;
28
29 /** Base class for XML validators.
30  */
31 class Validator : public NonCopyable
32 {
33 public:
34   Validator();
35   ~Validator() override;
36
37   /** Parse a schema definition file or an external subset (DTD file).
38    * @param filename The URL of the schema or the DTD.
39    * @throws xmlpp::parse_error
40    */
41   virtual void parse_file(const std::string& filename) = 0;
42
43   /** Parse a schema definition or a DTD from a string.
44    * @param contents The schema definition or the DTD as a string.
45    * @throws xmlpp::parse_error
46    */
47   virtual void parse_memory(const Glib::ustring& contents) = 0;
48
49   /** Validate a document, using a previously parsed schema or DTD.
50    * @param document Pointer to the document.
51    * @throws xmlpp::internal_error
52    * @throws xmlpp::validity_error
53    */
54   virtual void validate(const Document* document) = 0;
55
56   /** Test whether a schema or a DTD has been parsed.
57    * For instance
58    * @code
59    * if (validator)
60    *   do_something();
61    * @endcode
62    */
63   explicit virtual operator bool() const noexcept = 0;
64
65 protected:
66   virtual void initialize_context();
67   virtual void release_underlying();
68
69   virtual void on_validity_error(const Glib::ustring& message);
70   virtual void on_validity_warning(const Glib::ustring& message);
71
72   /// To be called in an exception handler.
73   virtual void handle_exception();
74   virtual void check_for_exception();
75   virtual void check_for_validity_messages();
76
77   static void callback_validity_error(void* ctx, const char* msg, ...);
78   static void callback_validity_warning(void* ctx, const char* msg, ...);
79
80   std::unique_ptr<exception> exception_;
81   // Built gradually - used in an exception at the end of validation.
82   Glib::ustring validate_error_;
83   Glib::ustring validate_warning_;
84 };
85
86 } // namespace xmlpp
87
88 #endif //__LIBXMLPP_VALIDATOR_H