XmlDocument.cpp 1.7 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: 2022-05-20
  7. *
  8. * */
  9. #include <ls_std/io/xml/XmlDocument.hpp>
  10. #include <ls_std/core/exception/IllegalArgumentException.hpp>
  11. ls::std::io::XmlDocument::XmlDocument() : ls::std::core::Class("XmlDocument")
  12. {}
  13. ::std::shared_ptr<ls::std::io::XmlDeclaration> ls::std::io::XmlDocument::getDeclaration()
  14. {
  15. return this->declaration;
  16. }
  17. ::std::shared_ptr<ls::std::io::XmlNode> ls::std::io::XmlDocument::getRootElement()
  18. {
  19. return this->rootElement;
  20. }
  21. void ls::std::io::XmlDocument::setDeclaration(const ::std::shared_ptr<ls::std::io::XmlDeclaration> &_declaration)
  22. {
  23. this->_assignDeclaration(_declaration);
  24. }
  25. void ls::std::io::XmlDocument::setRootElement(const ::std::shared_ptr<ls::std::io::XmlNode> &_rootElement)
  26. {
  27. this->_assignRootElement(_rootElement);
  28. }
  29. ::std::string ls::std::io::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::io::XmlDocument::_assignDeclaration(const ::std::shared_ptr<ls::std::io::XmlDeclaration> &_declaration)
  43. {
  44. if (_declaration == nullptr)
  45. {
  46. throw ls::std::core::IllegalArgumentException{};
  47. }
  48. this->declaration = _declaration;
  49. }
  50. void ls::std::io::XmlDocument::_assignRootElement(const ::std::shared_ptr<ls::std::io::XmlNode> &_rootElement)
  51. {
  52. if (_rootElement == nullptr)
  53. {
  54. throw ls::std::core::IllegalArgumentException{};
  55. }
  56. this->rootElement = _rootElement;
  57. }