~ubuntu-branches/ubuntu/vivid/fbreader/vivid-proposed

« back to all changes in this revision

Viewing changes to fbreader/src/migration/OEBMigrationReader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Eugene V. Lyubimkin
  • Date: 2008-06-17 23:01:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617230153-a16c45tq69j8geru
Tags: 0.8.17-11
* debian/control:
  - Enhanced all ZLibrary descriptions, not the main one.
  - Done some renaming to use canonical names of libraries and toolkits in
    decriptions, as suggested by developers-reference:
    'qt' -> 'Qt', 'gtk' -> 'GTK+', 'zlibrary' -> 'ZLibrary'.
  - Bump 'Depends' on quilt to (>= 0.24).
* debian/rules:
  - Included quilt makefile instead of quilt makefile instead
    of copy&paste'ing it.
* debian/fbreader.links:
  - Added this file to relay on dh_link's work instead of using 'ln -sf'
    directly in the debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 * 02110-1301, USA.
 
18
 */
 
19
 
 
20
#include <ZLStringUtil.h>
 
21
#include <ZLUnicodeUtil.h>
 
22
 
 
23
#include "OEBMigrationReader.h"
 
24
 
 
25
OEBMigrationReader::OEBMigrationReader(BookInfo &info) : myInfo(info) {
 
26
}
 
27
 
 
28
static const std::string METADATA = "metadata";
 
29
static const std::string DC_METADATA = "dc-metadata";
 
30
static const std::string SUBJECT_TAG = ":subject";
 
31
 
 
32
void OEBMigrationReader::characterDataHandler(const char *text, int len) {
 
33
        if (myReadSubject) {
 
34
                myBuffer.append(text, len);
 
35
        }
 
36
}
 
37
 
 
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);
 
42
        return
 
43
                (iter != namespaceMap.end()) &&
 
44
                ZLStringUtil::stringStartsWith(iter->second, DC_SCHEME_PREFIX);
 
45
}
 
46
 
 
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()))) {
 
55
                                myReadSubject = true;
 
56
                        }
 
57
                }
 
58
        }
 
59
}
 
60
 
 
61
void OEBMigrationReader::endElementHandler(const char *tag) {
 
62
        const std::string tagString = ZLUnicodeUtil::toLower(tag);
 
63
        if (myDCMetadataTag == tagString) {
 
64
                interrupt();
 
65
        } else if (myReadSubject) {
 
66
                ZLStringUtil::stripWhiteSpaces(myBuffer);
 
67
                if (!myBuffer.empty()) {
 
68
                        if (!myTagList.empty()) {
 
69
                                myTagList += ',';
 
70
                        }
 
71
                        myTagList += myBuffer;
 
72
                        myBuffer.erase();
 
73
                }
 
74
                myReadSubject = false;
 
75
        }
 
76
}
 
77
 
 
78
bool OEBMigrationReader::processNamespaces() const {
 
79
        return true;
 
80
}
 
81
 
 
82
void OEBMigrationReader::doRead(const std::string &fileName) {
 
83
        myReadMetaData = false;
 
84
        myReadSubject = false;
 
85
        readDocument(fileName);
 
86
        myInfo.TagsOption.setValue(myTagList);
 
87
}