0
|
1 |
/**
|
|
2 |
* Relational pipes
|
|
3 |
* Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation, version 3 of the License.
|
|
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, see <http://www.gnu.org/licenses/>.
|
|
16 |
*/
|
|
17 |
#pragma once
|
|
18 |
|
|
19 |
#include <codecvt>
|
|
20 |
#include <vector>
|
|
21 |
|
|
22 |
#include <libxml++-2.6/libxml++/libxml++.h>
|
|
23 |
|
|
24 |
#include <vmime/vmime.hpp>
|
|
25 |
|
|
26 |
#include "XMLNameCodec.h"
|
|
27 |
|
|
28 |
namespace relpipe {
|
|
29 |
namespace in {
|
|
30 |
namespace xmltable {
|
|
31 |
|
|
32 |
class XMLDocumentConstructor {
|
|
33 |
private:
|
|
34 |
std::istream* input = nullptr;
|
|
35 |
xmlpp::DomParser* parser = nullptr;
|
|
36 |
XMLNameCodec nameCodec;
|
|
37 |
|
|
38 |
enum class Mode {
|
|
39 |
ROOT,
|
|
40 |
SEQUENCE,
|
|
41 |
MAPPING,
|
|
42 |
MAP_KEY
|
|
43 |
};
|
|
44 |
|
|
45 |
std::string rootName = "mime";
|
|
46 |
xmlpp::Element* current;
|
|
47 |
std::vector<Mode> mode;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Both MIME and XML strings are in UTF-8.
|
|
51 |
const char* y2x(mime_char_t* value) {
|
|
52 |
return value ? (const char*) value : "";
|
|
53 |
}
|
|
54 |
|
|
55 |
const Glib::ustring y2xname(mime_char_t* value) {
|
|
56 |
return nameCodec.encode(y2x(value));
|
|
57 |
}
|
|
58 |
*/
|
|
59 |
|
|
60 |
xmlpp::Element* parentOrSelf(xmlpp::Element* current) {
|
|
61 |
return current->get_parent() == nullptr ? current : current->get_parent();
|
|
62 |
}
|
|
63 |
|
|
64 |
public:
|
|
65 |
|
|
66 |
XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) {
|
|
67 |
}
|
|
68 |
|
|
69 |
virtual ~XMLDocumentConstructor() {
|
|
70 |
}
|
|
71 |
|
|
72 |
void setOption(const std::string& uri, const std::string& value) {
|
|
73 |
if (uri == "root-name") rootName = value;
|
|
74 |
else throw std::invalid_argument(std::string("Invalid parser option: „") + uri + "“ with value: „" + value + "“");
|
|
75 |
}
|
|
76 |
|
|
77 |
void process() {
|
|
78 |
current = parser->get_document()->create_root_node(rootName);
|
|
79 |
}
|
|
80 |
};
|
|
81 |
|
|
82 |
}
|
|
83 |
}
|
|
84 |
}
|