src/XMLDocumentConstructor.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 12 Jun 2021 20:43:07 +0200
branchv_0
changeset 7 afb7f3a4981a
parent 5 15c3221e66af
child 10 6904e4448807
permissions -rw-r--r--
rename SAXContentHandler to XMLContentHandler

/**
 * Relational pipes
 * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once

#include <memory>

#include <libxml++-2.6/libxml++/libxml++.h>

#include "lib/BasicASN1Reader.h"
#include "lib/GenericASN1ContentHandler.h"
#include "lib/DOMBuildingXMLContentHandler.h"

namespace relpipe {
namespace in {
namespace xmltable {

class XMLDocumentConstructor {
private:
	std::istream* input = nullptr;
	xmlpp::DomParser* parser = nullptr;
public:

	XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) {
	}

	void setOption(const std::string& uri, const std::string& value) {
	}

	void process() {

		relpipe::in::asn1::lib::BasicASN1Reader reader;
		std::shared_ptr<relpipe::in::asn1::lib::GenericASN1ContentHandler> asn1handler = make_shared<relpipe::in::asn1::lib::GenericASN1ContentHandler>();
		std::shared_ptr<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler> saxHandler = make_shared<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler>(parser->get_document());

		asn1handler->addHandler(saxHandler);
		reader.addHandler(asn1handler);


		// TODO: buffering? (reader itself also buffers)
		for (char ch = input->get(); input->good(); ch = input->get()) reader.write(&ch, 1);

		reader.close();
	}
};

}
}
}