1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
9 #include <anna/core/tracing/Logger.hpp>
10 #include <anna/core/tracing/TraceMethod.hpp>
11 #include <anna/config/defines.hpp>
13 #include <libxml/parser.h>
15 #include <anna/xml/Document.hpp>
16 #include <anna/xml/Parser.hpp>
20 using namespace anna::xml;
22 Document::Document() :
23 anna::DataBlock(true),
27 a_contentIsCString(false),
32 Document::~Document() {
33 if(a_handle != NULL) {
43 void Document::initialize(const char* content)
44 throw(RuntimeException) {
45 LOGMETHOD(TraceMethod tf("anna::xml::Document", "initialize (char*)", ANNA_FILE_LOCATION));
47 a_handle = do_initialize(content);
48 setEncoding((char*) a_handle->encoding);
49 setVersion((char*) a_handle->version);
52 void Document::initialize(const DataBlock& content)
53 throw(RuntimeException) {
54 LOGMETHOD(TraceMethod tf("anna::xml::Document", "initialize (DataBlock)", ANNA_FILE_LOCATION));
56 a_handle = do_initialize(content);
57 setEncoding((char*) a_handle->encoding);
58 setVersion((char*) a_handle->version);
61 const xml::Node* Document::parse()
62 throw(RuntimeException) {
64 a_parser = new Parser;
66 return a_parser->apply(*this);
69 const xml::Node* Document::parse(const xml::DTD& dtd)
70 throw(RuntimeException) {
72 a_parser = new Parser;
74 return a_parser->apply(*this, dtd);
77 void Document::clear()
79 if(a_handle != NULL) {
84 if(a_encoding != NULL)
91 a_contentIsCString = false;
94 const char* Document::getEncoding() const
96 return (a_encoding == NULL) ? NULL : ((a_encoding->empty() == true) ? NULL : a_encoding->c_str());
99 const char* Document::getVersion() const
101 return (a_version == NULL) ? NULL : ((a_version->empty() == true) ? NULL : a_version->c_str());
104 const char* Document::getContentAsCString() const
105 throw(RuntimeException) {
106 const char* result = NULL;
108 if(a_contentIsCString == false) {
109 Document* _this = const_cast <Document*>(this);
111 if(a_asCString == NULL)
112 _this->a_asCString = new DataBlock(true);
114 *(_this->a_asCString) = *this;
115 *(_this->a_asCString) += '\0';
116 result = a_asCString->getData();
123 void Document::setEncoding(const char* encoding)
125 if(a_encoding == NULL) {
127 a_encoding = new string(encoding);
130 *a_encoding = encoding;
136 void Document::setVersion(const char* version)
138 if(a_version == NULL) {
140 a_version = new string(version);
143 *a_version = version;