mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
FeedReader plugin
- reserved service id - reworked error codes - added xpath manipulation and basic gui elements in preview dialog git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5514 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
08904bf82f
commit
c7ed9c6df7
23 changed files with 1595 additions and 430 deletions
102
plugins/FeedReader/util/XPathWrapper.cpp
Normal file
102
plugins/FeedReader/util/XPathWrapper.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/****************************************************************
|
||||
* RetroShare GUI is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2012 by Thunder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include "XPathWrapper.h"
|
||||
#include "XMLWrapper.h"
|
||||
|
||||
XPathWrapper::XPathWrapper(XMLWrapper &xmlWrapper) : mXMLWrapper(xmlWrapper)
|
||||
{
|
||||
mContext = NULL;
|
||||
mResult = NULL;
|
||||
}
|
||||
|
||||
XPathWrapper::~XPathWrapper()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void XPathWrapper::cleanup()
|
||||
{
|
||||
if (mResult) {
|
||||
xmlXPathFreeObject(mResult);
|
||||
mResult = NULL;
|
||||
}
|
||||
if (mContext) {
|
||||
xmlXPathFreeContext(mContext);
|
||||
mContext = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool XPathWrapper::compile(const char *expression)
|
||||
{
|
||||
cleanup();
|
||||
|
||||
xmlDocPtr document = mXMLWrapper.getDocument();
|
||||
if (!document) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mContext = xmlXPathNewContext(document);
|
||||
if (!mContext) {
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlChar *xmlExpression = NULL;
|
||||
if (!mXMLWrapper.convertFromString(expression, xmlExpression)) {
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
mResult = xmlXPathEvalExpression(xmlExpression, mContext);
|
||||
xmlFree(xmlExpression);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int XPathWrapper::count()
|
||||
{
|
||||
if (!mResult) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (xmlXPathNodeSetIsEmpty(mResult->nodesetval)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mResult->nodesetval->nodeNr;
|
||||
}
|
||||
|
||||
xmlNodePtr XPathWrapper::node(unsigned int index)
|
||||
{
|
||||
if (!mResult) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (xmlXPathNodeSetIsEmpty(mResult->nodesetval)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (index >= (unsigned int) mResult->nodesetval->nodeNr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mResult->nodesetval->nodeTab[index];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue