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 //
11 #include <sys/types.h>
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 <libxml/parser.h>
21 #include <anna/xml/DTDMemory.hpp>
25 using namespace anna::xml;
27 DTDMemory::DTDMemory(const char *dtd) {
28 a_filename = "/tmp/anna.xml.";
29 a_filename += functions::asString((int) getpid());
31 if (dtd) initialize(dtd);
34 //---------------------------------------------------------------------------------------------
35 // Aunque la libXML ofrece funciones para analizar una DTD a partir de un buffer de memoria
36 // hemos sido incapaces de hacerla funcionar correctamente. As� que nos vemos obligados
37 // a volcar el buffer en un archivo .. y una vez all� analizarlo con la funci�n que analiza
38 // la DTD a partir de un archivo.
39 //---------------------------------------------------------------------------------------------
40 _xmlDtd* DTDMemory::parse(const char* content) const
41 throw(RuntimeException) {
42 LOGMETHOD(TraceMethod tf("anna::xml::DTDMemory", "parse", ANNA_FILE_LOCATION));
46 Logger::write(Logger::Debug, "DTD", content, ANNA_FILE_LOCATION);
47 Logger::write(Logger::Debug, "Temporary file", a_filename.c_str(), ANNA_FILE_LOCATION)
50 if((stream = open(a_filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1)
51 throw RuntimeException(a_filename, errno, ANNA_FILE_LOCATION);
53 if(write(stream, content, anna_strlen(content)) == -1) {
54 const int xerrno = errno;
56 unlink(a_filename.c_str());
57 throw RuntimeException(a_filename, xerrno, ANNA_FILE_LOCATION);
62 if((result = xmlParseDTD(NULL, BAD_CAST(a_filename.c_str()))) == NULL) {
63 unlink(a_filename.c_str());
64 throw RuntimeException("DTD is wrong", ANNA_FILE_LOCATION);
67 unlink(a_filename.c_str());