XmlDocument.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-30
  6. * Changed: 2021-07-16
  7. *
  8. * */
  9. #include <ls_std/io/xml/XmlDocument.hpp>
  10. #include <ls_std/exception/IllegalArgumentException.hpp>
  11. ls_std::XmlDocument::XmlDocument() : ls_std::Class("XmlDocument")
  12. {}
  13. std::shared_ptr<ls_std::XmlDeclaration> ls_std::XmlDocument::getDeclaration()
  14. {
  15. return this->declaration;
  16. }
  17. std::shared_ptr<ls_std::XmlNode> ls_std::XmlDocument::getRootElement()
  18. {
  19. return this->rootElement;
  20. }
  21. void ls_std::XmlDocument::setDeclaration(const std::shared_ptr<ls_std::XmlDeclaration> &_declaration)
  22. {
  23. this->_assignDeclaration(_declaration);
  24. }
  25. void ls_std::XmlDocument::setRootElement(const std::shared_ptr<ls_std::XmlNode> &_rootElement)
  26. {
  27. this->_assignRootElement(_rootElement);
  28. }
  29. std::string ls_std::XmlDocument::toXml()
  30. {
  31. std::string xmlString{};
  32. if (this->declaration != nullptr)
  33. {
  34. xmlString = this->declaration->toXml();
  35. if (!xmlString.empty())
  36. {
  37. xmlString += "\n";
  38. }
  39. }
  40. return xmlString + this->rootElement->toXml();
  41. }
  42. void ls_std::XmlDocument::_assignDeclaration(const std::shared_ptr<ls_std::XmlDeclaration> &_declaration)
  43. {
  44. if (_declaration == nullptr)
  45. {
  46. throw ls_std::IllegalArgumentException{};
  47. }
  48. this->declaration = _declaration;
  49. }
  50. void ls_std::XmlDocument::_assignRootElement(const std::shared_ptr<ls_std::XmlNode> &_rootElement)
  51. {
  52. if (_rootElement == nullptr)
  53. {
  54. throw ls_std::IllegalArgumentException{};
  55. }
  56. this->rootElement = _rootElement;
  57. }