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 //
14 #include <anna/core/tracing/Logger.hpp>
15 #include <anna/core/tracing/TraceMethod.hpp>
16 #include <anna/config/defines.hpp>
17 #include <anna/core/functions.hpp>
19 #include <anna/io/functions.hpp>
21 #include <libxml/HTMLparser.h>
23 #include <anna/xml/DocumentFile.hpp>
27 using namespace anna::xml;
29 _xmlDoc* DocumentFile::do_initialize(const char* filename)
30 throw(RuntimeException) {
31 LOGMETHOD(TraceMethod tf("anna::xml::DocumentFile", "do_initialize", ANNA_FILE_LOCATION));
33 a_filename = filename;
35 string msg("xml::DocumentFile::do_initialize | Filename: ");
37 Logger::debug(msg, ANNA_FILE_LOCATION);
40 if(io::functions::exists(filename) == false) {
41 string msg("xml::DocumentFile::do_initialize | File: ");
43 msg += " | Not found";
44 throw RuntimeException(msg, ANNA_FILE_LOCATION);
47 result = xmlParseFile(filename);
50 throw RuntimeException(functions::asString("Error analyzing XML document: %s", filename), ANNA_FILE_LOCATION);
55 _xmlDoc* DocumentFile::do_initialize(const anna::DataBlock&)
56 throw(RuntimeException) {
57 throw RuntimeException("xml::DocumentFile::do_initialize | Not implemented", ANNA_FILE_LOCATION);
62 const anna::DataBlock& DocumentFile::getContent() const
63 throw(RuntimeException) {
64 const anna::DataBlock& result = Document::getContent();
66 if(result.isEmpty() == false)
71 if((stream = open(a_filename.c_str(), O_RDONLY)) == -1)
72 throw RuntimeException(a_filename, errno, ANNA_FILE_LOCATION);
74 const int size = lseek(stream, 0, SEEK_END);
75 lseek(stream, 0, SEEK_SET);
76 char* buffer = new char [size];
77 ssize_t r = read(stream, buffer, size);
79 const_cast <DocumentFile*>(this)->setContent(buffer, size);