Remove dynamic exceptions
[anna.git] / source / xml / DocumentMemory.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <libxml/parser.h>
10
11 #include <anna/core/tracing/Logger.hpp>
12 #include <anna/core/tracing/TraceMethod.hpp>
13 #include <anna/config/defines.hpp>
14 #include <anna/core/functions.hpp>
15
16 #include <anna/xml/DocumentMemory.hpp>
17
18 using namespace std;
19 using namespace anna;
20 using namespace anna::xml;
21
22 _xmlDoc* DocumentMemory::do_initialize(const char* content)
23 noexcept(false) {
24   LOGMETHOD(TraceMethod tf("anna::xml::DocumentMemory", "do_initialize (char*)", ANNA_FILE_LOCATION));
25   setContent(content);
26   _xmlDoc* result;
27   LOGDEBUG(
28     string msg("xml::DocumentMemory::do_initialize | Content (char*): ");
29     msg += content;
30     Logger::debug(msg, ANNA_FILE_LOCATION);
31   );
32
33   if((result = xmlParseMemory(content, anna_strlen(content))) == NULL) {
34     string msg("xml::DocumentMemory::do_initialize | Content: ");
35     msg += content;
36     msg += " | Error parsing";
37     throw RuntimeException(msg, ANNA_FILE_LOCATION);
38   }
39
40   return result;
41 }
42
43 _xmlDoc* DocumentMemory::do_initialize(const anna::DataBlock& content)
44 noexcept(false) {
45   LOGMETHOD(TraceMethod tf("anna::xml::DocumentMemory", "do_initialize (DataBlock)", ANNA_FILE_LOCATION));
46   setContent(content);
47   _xmlDoc* result;
48   LOGDEBUG(
49     string msg("xml::DocumentMemory::do_initialize | Content: ");
50     msg += functions::asString(content, 24);
51     Logger::debug(msg, ANNA_FILE_LOCATION);
52   );
53
54   if((result = xmlParseMemory(content.getData(), content.getSize())) == NULL) {
55     string msg("xml::DocumentMemory::do_initialize | Content: ");
56     msg += functions::asString(content, 24);
57     msg += " | Error parsing";
58     throw RuntimeException(msg, ANNA_FILE_LOCATION);
59   }
60
61   return result;
62 }