XMLReader.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-10-10
  6. * Changed: 2020-11-26
  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) : ls_std::Class("XMLReader"),
  15. xmlFile(ls_std::File {""})
  16. {
  17. this->_assignDocument(_document);
  18. this->_assignFile(ls_std::File {_absolutePath});
  19. }
  20. ls_std::byte_field ls_std::XMLReader::read()
  21. {
  22. ls_std::byte_field data = ls_std::FileReader {this->xmlFile}.read();
  23. ls_std::XMLParser {this->document}.parse(data);
  24. return data;
  25. }
  26. std::shared_ptr<ls_std::XMLDocument> ls_std::XMLReader::getDocument()
  27. {
  28. return this->document;
  29. }
  30. void ls_std::XMLReader::setDocument(const std::shared_ptr<ls_std::XMLDocument> &_document)
  31. {
  32. this->_assignDocument(_document);
  33. }
  34. void ls_std::XMLReader::setFile(const ls_std::File &_xmlFile)
  35. {
  36. this->_assignFile(_xmlFile);
  37. }
  38. void ls_std::XMLReader::_assignDocument(const std::shared_ptr<ls_std::XMLDocument> &_document)
  39. {
  40. if(_document == nullptr) {
  41. throw ls_std::IllegalArgumentException {};
  42. }
  43. this->document = _document;
  44. }
  45. void ls_std::XMLReader::_assignFile(ls_std::File _xmlFile)
  46. {
  47. if(!_xmlFile.exists()) {
  48. throw ls_std::IllegalArgumentException {};
  49. }
  50. this->xmlFile = _xmlFile;
  51. }