From ead44bdb1e79f6acde62e4a0cc70ea3e92edf426 Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 26 May 2011 17:45:43 +0000 Subject: Allow specification of encoding of documents in XslRows Allow specification of encoding of web sites in artfulseller --- project2/xslRows.cpp | 11 ++++++----- project2/xslRows.h | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/project2/xslRows.cpp b/project2/xslRows.cpp index 82c9d4a..7a46fae 100644 --- a/project2/xslRows.cpp +++ b/project2/xslRows.cpp @@ -21,7 +21,8 @@ XslRows::XslRows(const xmlpp::Element * p) : RowSet(p), CurlHelper(p), html(p->get_attribute_value("html") == "true"), - warnings(p->get_attribute_value("warnings") != "false") + warnings(p->get_attribute_value("warnings") != "false"), + encoding(p, "encoding", false) { BOOST_FOREACH(const xmlpp::Node * node, p->find("filterview")) { const xmlpp::Element * elem = dynamic_cast(node); @@ -66,7 +67,7 @@ XslRows::handleDataHelper(const char * ptr, size_t size, size_t nmemb, void *str } xmlDocPtr -XslRows::getDocument(const Glib::ustring & url) const +XslRows::getDocument(const Glib::ustring & url, const char * encoding) const { Documents::const_iterator i = documents.find(url); if (i == documents.end()) { @@ -79,8 +80,8 @@ XslRows::getDocument(const Glib::ustring & url) const int flags = 0; flags |= warnings ? 0 : XML_PARSE_NOWARNING | XML_PARSE_NOERROR; xmlDocPtr doc = html ? - htmlReadMemory(buf.c_str(), buf.length(), url.c_str(), NULL, flags) : - xmlReadMemory(buf.c_str(), buf.length(), url.c_str(), NULL, flags); + htmlReadMemory(buf.c_str(), buf.length(), url.c_str(), encoding, flags) : + xmlReadMemory(buf.c_str(), buf.length(), url.c_str(), encoding, flags); if (!doc) { throw XmlParseError(xmlGetLastError()->message); } @@ -97,7 +98,7 @@ XslRows::execute(const RowProcessor * rp) const { typedef boost::shared_ptr xmlXPathObjectSPtr; typedef boost::shared_ptr xmlXPathContextSPtr; - xmlDocPtr doc = getDocument(url()); + xmlDocPtr doc = getDocument(url(), encoding()); xmlXPathContextSPtr xpathCtx = xmlXPathContextSPtr(xmlXPathNewContext(doc), xmlXPathFreeContext); if (!xpathCtx) { throw XpathInitError(xmlGetLastError()->message); diff --git a/project2/xslRows.h b/project2/xslRows.h index 7aeb4e4..5075386 100644 --- a/project2/xslRows.h +++ b/project2/xslRows.h @@ -51,7 +51,8 @@ class XslRows : public RowSet, CurlHelper { typedef std::map > Documents; mutable Documents documents; static size_t handleDataHelper(const char * ptr, size_t size, size_t nmemb, void *stream); - xmlDocPtr getDocument(const Glib::ustring & url) const; + xmlDocPtr getDocument(const Glib::ustring & url, const char * encoding) const; + const Variable encoding; }; #endif -- cgit v1.2.3