FeedReader:

- Added error handling to xml functions
- Added xslt transformation
- Added retransform of existing messages
- Redesigned preview dialog
- Enabled embed images for forum feeds
- Changed config format, switching back to an older version results in a loss of all data of the FeedReader

Added new base class RSPlainTextEdit with placeholder text.
New library libxslt needed

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6081 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-01-22 00:11:43 +00:00
parent 919fb3f62d
commit ef49000b9a
28 changed files with 1549 additions and 849 deletions

View file

@ -32,7 +32,10 @@ bool HTMLWrapper::readHTML(const char *html, const char *url)
{
cleanup();
mDocument = htmlReadMemory(html, strlen(html), url, "", HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_COMPACT | HTML_PARSE_NONET | HTML_PARSE_NOBLANKS);
handleError(true, mLastErrorString);
mDocument = htmlReadMemory(html, strlen(html), url, "", /*HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | */HTML_PARSE_COMPACT | HTML_PARSE_NONET | HTML_PARSE_NOBLANKS);
handleError(false, mLastErrorString);
if (mDocument) {
return true;
}
@ -48,7 +51,10 @@ bool HTMLWrapper::saveHTML(std::string &html)
xmlChar *newHtml = NULL;
int newHtmlSize = 0;
handleError(true, mLastErrorString);
htmlDocDumpMemoryFormat(mDocument, &newHtml, &newHtmlSize, 0);
handleError(false, mLastErrorString);
if (newHtml) {
convertToString(newHtml, html);
xmlFree(newHtml);

View file

@ -25,6 +25,14 @@
#include "XMLWrapper.h"
#include "XPathWrapper.h"
#include <util/rsstring.h>
#include <util/rsthreads.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
static RsMutex xmlMtx("XMLWrapper");
static std::string xmlErrorString;
XMLWrapper::XMLWrapper()
{
mDocument = NULL;
@ -42,6 +50,35 @@ XMLWrapper::~XMLWrapper()
xmlCharEncCloseFunc(mCharEncodingHandler);
}
static void xmlErrorHandler(void */*context*/, const char *msg, ...)
{
va_list vl;
va_start(vl, msg);
rs_sprintf_append_args(xmlErrorString, msg, vl);
va_end(vl);
}
void XMLWrapper::handleError(bool init, std::string &errorString)
{
if (init) {
xmlMtx.lock();
xmlErrorString.clear();
errorString.clear();
xsltSetGenericErrorFunc(this, xmlErrorHandler);
xmlSetGenericErrorFunc(this, xmlErrorHandler);
} else {
xsltSetGenericErrorFunc(NULL, NULL);
xmlSetGenericErrorFunc(NULL, NULL);
errorString = xmlErrorString;
xmlErrorString.clear();
xmlMtx.unlock();
}
}
void XMLWrapper::trimString(std::string &string)
{
/* trim left */
@ -59,7 +96,6 @@ void XMLWrapper::trimString(std::string &string)
}
}
XMLWrapper &XMLWrapper::operator=(const XMLWrapper &xml)
{
cleanup();
@ -80,6 +116,13 @@ void XMLWrapper::cleanup()
}
}
void XMLWrapper::attach(xmlDocPtr document)
{
cleanup();
mDocument = document;
}
bool XMLWrapper::convertToString(const xmlChar *xmlText, std::string &text)
{
bool result = false;
@ -138,7 +181,10 @@ bool XMLWrapper::readXML(const char *xml)
{
cleanup();
mDocument = xmlReadDoc(BAD_CAST xml, "", NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_COMPACT | XML_PARSE_NOENT | XML_PARSE_NOCDATA);
handleError(true, mLastErrorString);
mDocument = xmlReadDoc(BAD_CAST xml, "", NULL, /*XML_PARSE_NOERROR | XML_PARSE_NOWARNING | */XML_PARSE_COMPACT | XML_PARSE_NOENT | XML_PARSE_NOCDATA);
handleError(false, mLastErrorString);
if (mDocument) {
return true;
}
@ -358,3 +404,23 @@ XPathWrapper *XMLWrapper::createXPath()
return NULL;
}
bool XMLWrapper::transform(const XMLWrapper &style, XMLWrapper &result)
{
handleError(true, mLastErrorString);
xmlDocPtr resultDoc = NULL;
xsltStylesheetPtr stylesheet = xsltParseStylesheetDoc(style.getDocument());
if (stylesheet) {
resultDoc = xsltApplyStylesheet(stylesheet, getDocument(), NULL);
stylesheet->doc = NULL; // xsltFreeStylesheet is freeing doc
xsltFreeStylesheet(stylesheet);
}
result.attach(resultDoc);
handleError(false, mLastErrorString);
return resultDoc ? true : false;
}

View file

@ -39,12 +39,16 @@ public:
XMLWrapper &operator=(const XMLWrapper &xml);
void cleanup();
std::string lastError() { return mLastErrorString; }
bool readXML(const char *xml);
xmlDocPtr getDocument() const;
xmlNodePtr getRootElement() const;
bool convertToString(const xmlChar *xmlText, std::string &text);
bool convertFromString(const char *text, xmlChar *&xmlText);
std::string nodeName(xmlNodePtr node);
std::string attrName(xmlAttrPtr attr);
@ -62,12 +66,16 @@ public:
XPathWrapper *createXPath();
bool convertToString(const xmlChar *xmlText, std::string &text);
bool convertFromString(const char *text, xmlChar *&xmlText);
bool transform(const XMLWrapper &style, XMLWrapper &result);
protected:
void attach(xmlDocPtr document);
void handleError(bool init, std::string &errorString);
protected:
xmlDocPtr mDocument;
xmlCharEncodingHandlerPtr mCharEncodingHandler;
std::string mLastErrorString;
};
#endif
#endif