2
* Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include <ZLStringUtil.h>
21
#include <ZLUnicodeUtil.h>
23
#include "OEBMigrationReader.h"
25
OEBMigrationReader::OEBMigrationReader(BookInfo &info) : myInfo(info) {
28
static const std::string METADATA = "metadata";
29
static const std::string DC_METADATA = "dc-metadata";
30
static const std::string SUBJECT_TAG = ":subject";
32
void OEBMigrationReader::characterDataHandler(const char *text, int len) {
34
myBuffer.append(text, len);
38
bool OEBMigrationReader::isDublinCoreNamespace(const std::string &nsId) const {
39
static const std::string DC_SCHEME_PREFIX = "http://purl.org/dc/elements";
40
const std::map<std::string,std::string> &namespaceMap = namespaces();
41
std::map<std::string,std::string>::const_iterator iter = namespaceMap.find(nsId);
43
(iter != namespaceMap.end()) &&
44
ZLStringUtil::stringStartsWith(iter->second, DC_SCHEME_PREFIX);
47
void OEBMigrationReader::startElementHandler(const char *tag, const char**) {
48
const std::string tagString = ZLUnicodeUtil::toLower(tag);
49
if ((METADATA == tagString) || (DC_METADATA == tagString)) {
50
myDCMetadataTag = tagString;
51
myReadMetaData = true;
52
} else if (myReadMetaData) {
53
if (ZLStringUtil::stringEndsWith(tagString, SUBJECT_TAG)) {
54
if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - SUBJECT_TAG.length()))) {
61
void OEBMigrationReader::endElementHandler(const char *tag) {
62
const std::string tagString = ZLUnicodeUtil::toLower(tag);
63
if (myDCMetadataTag == tagString) {
65
} else if (myReadSubject) {
66
ZLStringUtil::stripWhiteSpaces(myBuffer);
67
if (!myBuffer.empty()) {
68
if (!myTagList.empty()) {
71
myTagList += myBuffer;
74
myReadSubject = false;
78
bool OEBMigrationReader::processNamespaces() const {
82
void OEBMigrationReader::doRead(const std::string &fileName) {
83
myReadMetaData = false;
84
myReadSubject = false;
85
readDocument(fileName);
86
myInfo.TagsOption.setValue(myTagList);