+ content mgmt. last dev.

This commit is contained in:
kelson42 2011-05-08 18:45:26 +00:00
parent 804889d5dc
commit e6ff96ecb4
2 changed files with 65 additions and 35 deletions

View File

@ -18,7 +18,6 @@
*/ */
#include "manager.h" #include "manager.h"
#include <pugixml.hpp>
namespace kiwix { namespace kiwix {
@ -31,51 +30,70 @@ namespace kiwix {
Manager::~Manager() { Manager::~Manager() {
} }
bool Manager::parseXmlDom(const pugi::xml_document &doc, const bool readOnly) {
pugi::xml_node libraryNode = doc.child("library");
library.current = libraryNode.attribute("current").value();
string libraryVersion = libraryNode.attribute("version").value();
for (pugi::xml_node bookNode = libraryNode.child("book"); bookNode; bookNode = bookNode.next_sibling("book")) {
bool ok = true;
kiwix::Book book;
book.readOnly = readOnly;
book.id = bookNode.attribute("id").value();
book.path = bookNode.attribute("path").value();
book.last = (std::string(bookNode.attribute("last").value()) != "undefined" ? bookNode.attribute("last").value() : "");
book.indexPath = bookNode.attribute("indexPath").value();
book.indexType = (std::string(bookNode.attribute("indexType").value()) == "xapian" ? XAPIAN : CLUCENE);
book.title = bookNode.attribute("title").value();
book.description = bookNode.attribute("description").value();
book.language = bookNode.attribute("language").value();
book.date = bookNode.attribute("date").value();
book.creator = bookNode.attribute("creator").value();
book.url = bookNode.attribute("url").value();
book.articleCount = bookNode.attribute("articleCount").value();
book.mediaCount = bookNode.attribute("mediaCount").value();
book.size = bookNode.attribute("size").value();
/* Update the book properties with the new importer */
if (libraryVersion.empty() || atoi(libraryVersion.c_str()) < atoi(KIWIX_LIBRARY_VERSION)) {
if (!book.path.empty())
ok = this->readBookFromPath(book.path, book);
}
if (ok) {
library.addBook(book);
}
}
return true;
}
bool Manager::readXml(const string xml, const bool readOnly) {
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_buffer_inplace((void*)xml.data(), xml.size());
if (result) {
this->parseXmlDom(doc, readOnly);
}
return true;
}
bool Manager::readFile(const string path, const bool readOnly) { bool Manager::readFile(const string path, const bool readOnly) {
pugi::xml_document doc; pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(path.c_str()); pugi::xml_parse_result result = doc.load_file(path.c_str());
if (result) { if (result) {
pugi::xml_node libraryNode = doc.child("library"); // this->parseXmlDom(doc, readOnly);
library.current = libraryNode.attribute("current").value();
string libraryVersion = libraryNode.attribute("version").value();
bool ok = true;
for (pugi::xml_node bookNode = libraryNode.child("book"); bookNode; bookNode = bookNode.next_sibling("book")) {
kiwix::Book book;
book.readOnly = readOnly;
book.id = bookNode.attribute("id").value();
book.path = bookNode.attribute("path").value();
book.last = (std::string(bookNode.attribute("last").value()) != "undefined" ? bookNode.attribute("last").value() : "");
book.indexPath = bookNode.attribute("indexPath").value();
book.indexType = (std::string(bookNode.attribute("indexType").value()) == "xapian" ? XAPIAN : CLUCENE);
book.title = bookNode.attribute("title").value();
book.description = bookNode.attribute("description").value();
book.language = bookNode.attribute("language").value();
book.date = bookNode.attribute("date").value();
book.creator = bookNode.attribute("creator").value();
book.url = bookNode.attribute("url").value();
book.articleCount = bookNode.attribute("articleCount").value();
book.mediaCount = bookNode.attribute("mediaCount").value();
book.size = bookNode.attribute("size").value();
/* Update the book properties with the new importer */
if (libraryVersion.empty() || atoi(libraryVersion.c_str()) < atoi(KIWIX_LIBRARY_VERSION)) {
if (!book.path.empty())
ok = this->readBookFromPath(book.path, book);
}
if (ok) {
library.addBook(book);
}
}
} }
if (!readOnly) { if (!readOnly) {
this->writableLibraryPath = path; this->writableLibraryPath = path;
} }
return result; return true;
} }
bool Manager::writeFile(const string path) { bool Manager::writeFile(const string path) {
@ -259,6 +277,13 @@ namespace kiwix {
return false; return false;
} }
void Manager::removeBookPaths() {
std::vector<kiwix::Book>::iterator itr;
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
itr->path = "";
}
}
bool Manager::listBooks(const supportedListMode mode) { bool Manager::listBooks(const supportedListMode mode) {
this->bookIdList.clear(); this->bookIdList.clear();
std::vector<kiwix::Book>::iterator itr; std::vector<kiwix::Book>::iterator itr;

View File

@ -29,6 +29,8 @@
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <pugixml.hpp>
#include <kiwix/library.h> #include <kiwix/library.h>
#include <kiwix/reader.h> #include <kiwix/reader.h>
@ -45,6 +47,7 @@ namespace kiwix {
~Manager(); ~Manager();
bool readFile(const string path, const bool readOnly = true); bool readFile(const string path, const bool readOnly = true);
bool readXml(const string xml, const bool readOnly = true);
bool writeFile(const string path); bool writeFile(const string path);
bool removeBookByIndex(const unsigned int bookIndex); bool removeBookByIndex(const unsigned int bookIndex);
bool removeBookById(const string id); bool removeBookById(const string id);
@ -55,6 +58,7 @@ namespace kiwix {
Library cloneLibrary(); Library cloneLibrary();
bool getBookById(const string id, Book &book); bool getBookById(const string id, Book &book);
bool updateBookLastOpenDateById(const string id); bool updateBookLastOpenDateById(const string id);
void removeBookPaths();
bool listBooks(const supportedListMode); bool listBooks(const supportedListMode);
string writableLibraryPath; string writableLibraryPath;
@ -65,6 +69,7 @@ namespace kiwix {
kiwix::Library library; kiwix::Library library;
bool readBookFromPath(const string path, Book &book); bool readBookFromPath(const string path, Book &book);
bool parseXmlDom(const pugi::xml_document &doc, const bool readOnly);
}; };
} }