XmlReader.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-10-10
  6. * Changed: 2021-05-02
  7. *
  8. * */
  9. #include <ls_std/io/xml/XmlReader.hpp>
  10. #include <ls_std/exception/IllegalArgumentException.hpp>
  11. #include <ls_std/io/FileReader.hpp>
  12. #include <ls_std/boxing/String.hpp>
  13. #include <ls_std/io/xml/XmlParser.hpp>
  14. ls_std::XmlReader::XmlReader(const std::shared_ptr<ls_std::XmlDocument> &_document, const std::string &_absolutePath)
  15. : ls_std::Class("XmlReader"),
  16. xmlFile(ls_std::File{""})
  17. {
  18. this->_assignDocument(_document);
  19. this->_assignFile(ls_std::File{_absolutePath});
  20. }
  21. ls_std::byte_field ls_std::XmlReader::read()
  22. {
  23. ls_std::byte_field data = ls_std::FileReader{this->xmlFile}.read();
  24. ls_std::XmlParser{this->document}.parse(data);
  25. return data;
  26. }
  27. std::shared_ptr<ls_std::XmlDocument> ls_std::XmlReader::getDocument()
  28. {
  29. return this->document;
  30. }
  31. void ls_std::XmlReader::setDocument(const std::shared_ptr<ls_std::XmlDocument> &_document)
  32. {
  33. this->_assignDocument(_document);
  34. }
  35. void ls_std::XmlReader::setFile(const ls_std::File &_xmlFile)
  36. {
  37. this->_assignFile(_xmlFile);
  38. }
  39. void ls_std::XmlReader::_assignDocument(const std::shared_ptr<ls_std::XmlDocument> &_document)
  40. {
  41. if (_document == nullptr)
  42. {
  43. throw ls_std::IllegalArgumentException{};
  44. }
  45. this->document = _document;
  46. }
  47. void ls_std::XmlReader::_assignFile(ls_std::File _xmlFile)
  48. {
  49. if (!_xmlFile.exists())
  50. {
  51. throw ls_std::IllegalArgumentException{};
  52. }
  53. this->xmlFile = _xmlFile;
  54. }