XmlReader.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2020-10-10
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  11. #include <ls-std/core/exception/IllegalArgumentException.hpp>
  12. #include <ls-std/io/FileReader.hpp>
  13. #include <ls-std/io/xml/XmlParser.hpp>
  14. #include <ls-std/io/xml/XmlReader.hpp>
  15. using ls::standard::core::Class;
  16. using ls::standard::core::IllegalArgumentException;
  17. using ls::standard::core::NullPointerArgumentEvaluator;
  18. using ls::standard::core::type::byte_field;
  19. using ls::standard::io::File;
  20. using ls::standard::io::FileReader;
  21. using ls::standard::io::XmlDocument;
  22. using ls::standard::io::XmlParser;
  23. using ls::standard::io::XmlReader;
  24. using std::shared_ptr;
  25. using std::string;
  26. XmlReader::XmlReader(const shared_ptr<XmlDocument> &_document, const string &_absolutePath) : Class("XmlReader")
  27. {
  28. this->_assignDocument(_document);
  29. this->_assignFile(File{_absolutePath});
  30. }
  31. XmlReader::~XmlReader() noexcept = default;
  32. byte_field XmlReader::read()
  33. {
  34. byte_field data = FileReader{this->xmlFile}.read();
  35. XmlParser{this->document}.parse(data);
  36. return data;
  37. }
  38. shared_ptr<XmlDocument> XmlReader::getDocument() const
  39. {
  40. return this->document;
  41. }
  42. void XmlReader::setDocument(const shared_ptr<XmlDocument> &_document)
  43. {
  44. this->_assignDocument(_document);
  45. }
  46. void XmlReader::setFile(const File &_xmlFile)
  47. {
  48. this->_assignFile(_xmlFile);
  49. }
  50. void XmlReader::_assignDocument(const shared_ptr<XmlDocument> &_document)
  51. {
  52. NullPointerArgumentEvaluator{_document, "xml document reference is null!"}.evaluate();
  53. this->document = _document;
  54. }
  55. void XmlReader::_assignFile(const File &_xmlFile)
  56. {
  57. if (!_xmlFile.exists())
  58. {
  59. throw IllegalArgumentException{"file does not exist: " + _xmlFile.getAbsoluteFilePath()};
  60. }
  61. this->xmlFile = _xmlFile;
  62. }