32 |
32 |
33 class XMLDocumentConstructor { |
33 class XMLDocumentConstructor { |
34 private: |
34 private: |
35 std::istream* input = nullptr; |
35 std::istream* input = nullptr; |
36 xmlpp::DomParser* parser = nullptr; |
36 xmlpp::DomParser* parser = nullptr; |
|
37 relpipe::in::asn1::lib::BasicASN1Reader reader; |
|
38 std::shared_ptr<relpipe::in::asn1::lib::GenericASN1ContentHandler> asn1handler; |
|
39 std::shared_ptr<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler> saxHandler; |
37 public: |
40 public: |
38 |
41 |
39 XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) { |
42 XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) { |
|
43 asn1handler = make_shared<relpipe::in::asn1::lib::GenericASN1ContentHandler>(); |
|
44 saxHandler = make_shared<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler>(parser->get_document()); |
|
45 asn1handler->addHandler(saxHandler); |
|
46 reader.addHandler(asn1handler); |
40 } |
47 } |
41 |
48 |
42 void setOption(const std::string& uri, const std::string& value) { |
49 void setOption(const std::string& uri, const std::string& value) { |
|
50 int n = 0; |
|
51 n += reader.setOption(uri, value); |
|
52 n += asn1handler->setOption(uri, value); |
|
53 n += saxHandler->setOption(uri, value); |
|
54 if (n == 0) throw std::invalid_argument(std::string("Invalid parser option: „") + uri + "“ with value: „" + value + "“"); |
43 } |
55 } |
44 |
56 |
45 void process() { |
57 void process() { |
46 |
|
47 relpipe::in::asn1::lib::BasicASN1Reader reader; |
|
48 std::shared_ptr<relpipe::in::asn1::lib::GenericASN1ContentHandler> asn1handler = make_shared<relpipe::in::asn1::lib::GenericASN1ContentHandler>(); |
|
49 std::shared_ptr<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler> saxHandler = make_shared<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler>(parser->get_document()); |
|
50 |
|
51 asn1handler->addHandler(saxHandler); |
|
52 reader.addHandler(asn1handler); |
|
53 |
|
54 |
|
55 try { |
58 try { |
56 // TODO: buffering? (reader itself also buffers) |
59 // TODO: buffering? (reader itself also buffers) |
57 for (uint8_t b = input->get(); input->good(); b = input->get()) reader.write(&b, 1); |
60 for (uint8_t b = input->get(); input->good(); b = input->get()) reader.write(&b, 1); |
58 } catch (const relpipe::in::asn1::lib::TransactionalBuffer::WriteBufferOverflowException& e) { |
61 } catch (const relpipe::in::asn1::lib::TransactionalBuffer::WriteBufferOverflowException& e) { |
59 // TODO: avoid leaky abstraction and use different exception |
62 // TODO: avoid leaky abstraction and use different exception |