XmlDocument.cpp 1.8 KB

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