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-04-23
  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. }