author | František Kučera <franta-hg@frantovo.cz> |
Fri, 11 Jan 2019 00:29:32 +0100 | |
branch | v_0 |
changeset 2 | 3ab78bf63467 |
parent 1 | 9aed8c2ea97d |
child 3 | 4b566dee1a57 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2018 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, either version 3 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
#pragma once |
|
19 |
||
20 |
#include <cstdlib> |
|
21 |
#include <iostream> |
|
22 |
#include <string> |
|
23 |
#include <vector> |
|
24 |
#include <algorithm> |
|
25 |
||
1
9aed8c2ea97d
add Xerces-C++ dependency
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
26 |
#include <xercesc/sax2/SAX2XMLReader.hpp> |
9aed8c2ea97d
add Xerces-C++ dependency
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
27 |
#include <xercesc/sax2/XMLReaderFactory.hpp> |
9aed8c2ea97d
add Xerces-C++ dependency
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
28 |
#include <xercesc/sax2/DefaultHandler.hpp> |
9aed8c2ea97d
add Xerces-C++ dependency
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
29 |
#include <xercesc/util/XMLString.hpp> |
9aed8c2ea97d
add Xerces-C++ dependency
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
30 |
|
0 | 31 |
#include <relpipe/writer/typedefs.h> |
32 |
||
2
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
33 |
#include "StreamInputSource.h" |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
34 |
|
0 | 35 |
namespace relpipe { |
36 |
namespace in { |
|
37 |
namespace xml { |
|
38 |
||
39 |
class XMLCommand { |
|
40 |
public: |
|
41 |
||
42 |
void process(std::istream& input, std::ostream& output) { |
|
43 |
using namespace relpipe::writer; |
|
1
9aed8c2ea97d
add Xerces-C++ dependency
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
44 |
using namespace xercesc; |
2
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
45 |
unique_ptr<RelationalWriter> writer(Factory::create(output)); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
46 |
XMLPlatformUtils::Initialize(); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
47 |
|
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
48 |
|
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
49 |
unique_ptr<SAX2XMLReader> parser(XMLReaderFactory::createXMLReader()); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
50 |
parser->setFeature(XMLUni::fgSAX2CoreValidation, true); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
51 |
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
52 |
|
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
53 |
// TODO: custom handler that reads |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
54 |
DefaultHandler defaultHandler; |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
55 |
parser->setContentHandler(&defaultHandler); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
56 |
parser->setErrorHandler(&defaultHandler); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
57 |
|
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
58 |
StreamInputSource inputSource(input); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
59 |
|
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
60 |
parser->parse(inputSource); |
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
61 |
|
0 | 62 |
|
63 |
// TODO: remove demo |
|
64 |
// Various data types passed as strings |
|
65 |
writer->startRelation(L"xml",{ |
|
66 |
{L"s", TypeId::STRING}, |
|
67 |
{L"i", TypeId::INTEGER}, |
|
68 |
{L"b", TypeId::BOOLEAN} |
|
69 |
}, true); |
|
70 |
||
71 |
writer->writeAttribute(L"a"); |
|
72 |
writer->writeAttribute(L"1"); |
|
73 |
writer->writeAttribute(L"true"); |
|
2
3ab78bf63467
read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
74 |
|
0 | 75 |
} |
76 |
}; |
|
77 |
||
78 |
} |
|
79 |
} |
|
80 |
} |