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

« back to all changes in this revision

Viewing changes to fbreader/src/formats/oeb/OEBDescriptionReader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2008-01-23 16:51:07 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123165107-5q19etahzd72c33a
Tags: 0.8.12-3
* Add libzlui-maemo which allows using fbreader on the maemo platform, on
  Debian. Thanks, Riku Voipio. Closes: #462299
* makefiles/arch/maemo.mk: Don't build with -thumb. (Riku)
* Loosen dependency versions some more, so it only depends on the current
  upstream version or higher, ignoring the Debian revision.
* Use binary:Version instead of deprecated Source-Version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * FBReader -- electronic book reader
3
 
 * Copyright (C) 2004-2007 Nikolay Pultsin <geometer@mawhrin.net>
4
 
 * Copyright (C) 2005 Mikhail Sobolev <mss@mawhrin.net>
 
2
 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or modify
7
5
 * it under the terms of the GNU General Public License as published by
29
27
        myDescription.title().erase();
30
28
}
31
29
 
32
 
// TODO: replace "dc" by real DC scheme name
33
30
static const std::string METADATA = "metadata";
34
31
static const std::string DC_METADATA = "dc-metadata";
35
32
static const std::string TITLE = ":title";
50
47
        }
51
48
}
52
49
 
53
 
static const std::string XMLNS_PREFIX = "xmlns:";
54
50
static const std::string DC_SCHEME_PREFIX = "http://purl.org/dc/elements";
55
51
 
56
52
void OEBDescriptionReader::startElementHandler(const char *tag, const char **attributes) {
57
53
        const std::string tagString = ZLUnicodeUtil::toLower(tag);
58
54
        if ((METADATA == tagString) || (DC_METADATA == tagString)) {
59
 
                if (attributes != 0) {
60
 
                        for (; *attributes != 0; attributes += 2) {
61
 
                                if (ZLStringUtil::stringStartsWith(*attributes, XMLNS_PREFIX) &&
62
 
                                                ZLStringUtil::stringStartsWith(*(attributes + 1), DC_SCHEME_PREFIX)) {
63
 
                                        myDCSchemeName = *attributes + 6;
64
 
                                        myDCMetadataTag = tagString;
65
 
                                        break;
66
 
                                }
67
 
                        }
68
 
                }
 
55
                myDCMetadataTag = tagString;
69
56
                myReadMetaData = true;
70
57
        } else if (myReadMetaData) {
71
 
                if (myDCSchemeName + TITLE == tagString) {
72
 
                        myReadState = READ_TITLE;
73
 
                } else if (myDCSchemeName + AUTHOR_TAG == tagString) {
74
 
                        const char *role = attributeValue(attributes, "role");
75
 
                        if (role == 0) {
76
 
                                myReadState = READ_AUTHOR2;
77
 
                        } else if (AUTHOR_ROLE == role) {
78
 
                                myReadState = READ_AUTHOR;
 
58
                if (ZLStringUtil::stringEndsWith(tagString, TITLE)) {
 
59
                        const std::string namespaceId = tagString.substr(0, tagString.length() - TITLE.length());
 
60
                        const std::map<std::string,std::string> &namespaceMap = namespaces();
 
61
                        const std::map<std::string,std::string>::const_iterator iter = namespaceMap.find(namespaceId);
 
62
                        if ((iter != namespaceMap.end()) && ZLStringUtil::stringStartsWith(iter->second, DC_SCHEME_PREFIX)) {
 
63
                                myReadState = READ_TITLE;
 
64
                        }
 
65
                } else if (ZLStringUtil::stringEndsWith(tagString, AUTHOR_TAG)) {
 
66
                        const std::string namespaceId = tagString.substr(0, tagString.length() - AUTHOR_TAG.length());
 
67
                        const std::map<std::string,std::string> &namespaceMap = namespaces();
 
68
                        const std::map<std::string,std::string>::const_iterator iter = namespaceMap.find(namespaceId);
 
69
                        if ((iter != namespaceMap.end()) && ZLStringUtil::stringStartsWith(iter->second, DC_SCHEME_PREFIX)) {
 
70
                                const char *role = attributeValue(attributes, "role");
 
71
                                if (role == 0) {
 
72
                                        myReadState = READ_AUTHOR2;
 
73
                                } else if (AUTHOR_ROLE == role) {
 
74
                                        myReadState = READ_AUTHOR;
 
75
                                }
79
76
                        }
80
77
                }
81
78
        }
98
95
        }
99
96
}
100
97
 
 
98
bool OEBDescriptionReader::processNamespaces() const {
 
99
        return true;
 
100
}
 
101
 
101
102
bool OEBDescriptionReader::readDescription(const std::string &fileName) {
102
103
        myReadMetaData = false;
103
104
        myReadState = READ_NONE;