Line data Source code
1 : // Snap Websites Servers -- handle messages for QXmlQuery
2 : // Copyright (c) 2014-2019 Made to Order Software Corp. All Rights Reserved
3 : //
4 : // This program is free software; you can redistribute it and/or modify
5 : // it under the terms of the GNU General Public License as published by
6 : // the Free Software Foundation; either version 2 of the License, or
7 : // (at your option) any later version.
8 : //
9 : // This program is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : // GNU General Public License for more details.
13 : //
14 : // You should have received a copy of the GNU General Public License
15 : // along with this program; if not, write to the Free Software
16 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 : #pragma once
18 :
19 : #include "snapwebsites/snap_exception.h"
20 :
21 : #include <QDomDocument>
22 : #include <QVariant>
23 : #include <QMap>
24 :
25 : namespace snap
26 : {
27 :
28 0 : class xslt_exception : public snap_exception
29 : {
30 : public:
31 0 : explicit xslt_exception(char const * what_msg) : snap_exception("xslt", what_msg) {}
32 : explicit xslt_exception(std::string const & what_msg) : snap_exception("xslt", what_msg) {}
33 0 : explicit xslt_exception(QString const & what_msg) : snap_exception("xslt", what_msg) {}
34 : };
35 :
36 0 : class xslt_initialization_error : public xslt_exception
37 : {
38 : public:
39 : explicit xslt_initialization_error(char const * whatmsg) : xslt_exception(whatmsg) {}
40 : explicit xslt_initialization_error(std::string const & whatmsg) : xslt_exception(whatmsg) {}
41 0 : explicit xslt_initialization_error(QString const & whatmsg) : xslt_exception(whatmsg) {}
42 : };
43 :
44 0 : class xslt_evaluation_error : public xslt_exception
45 : {
46 : public:
47 0 : explicit xslt_evaluation_error(char const * whatmsg) : xslt_exception(whatmsg) {}
48 : explicit xslt_evaluation_error(std::string const & whatmsg) : xslt_exception(whatmsg) {}
49 : explicit xslt_evaluation_error(QString const & whatmsg) : xslt_exception(whatmsg) {}
50 : };
51 :
52 :
53 :
54 : class xslt
55 : {
56 : public:
57 : void set_xsl(QString const & xsl);
58 : void set_xsl(QDomDocument const & xsl);
59 : void set_xsl_from_file(QString const & filename);
60 : void set_document(QString const & doc);
61 : void set_document(QDomDocument & doc);
62 : void add_variable(QString const & name, QVariant const & value);
63 : void clear_variables();
64 :
65 : QString evaluate_to_string();
66 : void evaluate_to_document(QDomDocument & output);
67 :
68 : static QString filter_entities_out(QString const & html);
69 : static QString convert_entity(QString const & entity_name);
70 :
71 : private:
72 : void evaluate(QString * output_string, QDomDocument * output_document);
73 :
74 : QString f_xsl = QString();
75 : QString f_input = QString(); // document as a string
76 : QMap<QString, QVariant> f_variables = {};
77 : QDomDocument f_doc = QDomDocument();
78 : };
79 :
80 : } // namespace snap
81 : // vim: ts=4 sw=4 et
|