1 /* 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET 4 * 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises 6 * 7 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * This file was originally licensed under the terms of the CeCILL v2.1, 10 * and continues to be available under such terms. 11 * For more information, see the COPYING file which you should have received 12 * along with this program. 13 * 14 */ 15 16 #ifndef __XMLVALIDATION_HXX__ 17 #define __XMLVALIDATION_HXX__ 18 19 #include <cstdio> 20 #include <list> 21 #include <string> 22 23 #include "xml.h" 24 25 namespace org_modules_xml 26 { 27 class XMLObject; 28 class XMLDocument; 29 30 /** 31 * @file 32 * @author Calixte DENIZET <calixte.denizet@scilab.org> 33 * 34 * Base class for the XML validation. 35 */ 36 class XMLValidation: public XMLObject 37 { 38 39 public: 40 /** 41 * Retrieve all the open validation files 42 * @return a list containing the validation objects 43 */ 44 static const std::list < XMLValidation * >&getOpenValidationFiles(); 45 46 /** 47 * Close all the validation files 48 */ 49 static void closeAllValidationFiles(); 50 51 /** 52 * Default constructor 53 */ 54 XMLValidation(); 55 56 /** 57 * Validate an already parsed document 58 * @param doc the document to validate 59 * @param error a string which will contain error messages 60 */ 61 virtual bool validate(const XMLDocument & doc, std::string * error) const = 0; 62 63 /** 64 * Validate a document accessed via a xmlTextReader 65 * @param reader the reader to use 66 * @param error a string which will contain error messages 67 */ 68 virtual bool validate(xmlTextReader * reader, std::string * error) const = 0; 69 70 /** 71 * Validate a document with a given path 72 * @param path the document path 73 * @param error a string which will contain error messages 74 */ 75 bool validate(const char *path, std::string * error) const; 76 77 /** 78 * Validate a document with a given content as string 79 * @param xmlCode the document code 80 * @param error a string which will contain error messages 81 */ 82 bool validate(const std::string & xmlCode, std::string * error) const; 83 84 /** 85 * @return the validation file 86 */ getValidationFile() const87 template < typename T > T * getValidationFile() const 88 { 89 return (T *) validationFile; 90 } 91 92 protected: 93 static std::string errorBuffer; 94 static std::list<XMLValidation *> openValidationFiles; 95 96 /** 97 * Error function for the XML parser 98 * @see http://xmlsoft.org/html/libxml-xmlerror.html#xmlGenericErrorFunc 99 */ 100 static void errorFunction(void *ctx, const char *msg, ...); 101 102 static void errorReaderFunction(void * arg, const char * msg, xmlParserSeverities severity, xmlTextReaderLocatorPtr locator); 103 104 void *validationFile; 105 }; 106 } 107 108 #endif 109 110