/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2020-10-10 * Changed: 2023-05-17 * * */ #include #include #include #include #include using ls::std::core::Class; using ls::std::core::IllegalArgumentException; using ls::std::core::NullPointerArgumentEvaluator; using ls::std::core::type::byte_field; using ls::std::io::File; using ls::std::io::FileReader; using ls::std::io::XmlDocument; using ls::std::io::XmlParser; using ls::std::io::XmlReader; using std::shared_ptr; using std::string; XmlReader::XmlReader(const shared_ptr &_document, const string &_absolutePath) : Class("XmlReader") { this->_assignDocument(_document); this->_assignFile(File{_absolutePath}); } XmlReader::~XmlReader() noexcept = default; byte_field XmlReader::read() { byte_field data = FileReader{this->xmlFile}.read(); XmlParser{this->document}.parse(data); return data; } shared_ptr XmlReader::getDocument() const { return this->document; } void XmlReader::setDocument(const shared_ptr &_document) { this->_assignDocument(_document); } void XmlReader::setFile(const File &_xmlFile) { this->_assignFile(_xmlFile); } void XmlReader::_assignDocument(const shared_ptr &_document) { NullPointerArgumentEvaluator{_document, "xml document reference is null!"}.evaluate(); this->document = _document; } void XmlReader::_assignFile(const File &_xmlFile) { if (!_xmlFile.exists()) { throw IllegalArgumentException{"file does not exist: " + _xmlFile.getAbsoluteFilePath()}; } this->xmlFile = _xmlFile; }