~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): 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:
25
25
OEBDescriptionReader::OEBDescriptionReader(BookDescription &description) : myDescription(description) {
26
26
        myDescription.clearAuthor();
27
27
        myDescription.title().erase();
 
28
        myDescription.removeAllTags();
28
29
}
29
30
 
30
31
static const std::string METADATA = "metadata";
31
32
static const std::string DC_METADATA = "dc-metadata";
32
 
static const std::string TITLE = ":title";
 
33
static const std::string TITLE_TAG = ":title";
33
34
static const std::string AUTHOR_TAG = ":creator";
 
35
static const std::string SUBJECT_TAG = ":subject";
34
36
static const std::string AUTHOR_ROLE = "aut";
35
37
 
36
38
void OEBDescriptionReader::characterDataHandler(const char *text, int len) {
39
41
                        break;
40
42
                case READ_AUTHOR:
41
43
                case READ_AUTHOR2:
42
 
                        myCurrentAuthor.append(text, len);
 
44
                case READ_SUBJECT:
 
45
                        myBuffer.append(text, len);
43
46
                        break;
44
47
                case READ_TITLE:
45
48
                        myDescription.title().append(text, len);
47
50
        }
48
51
}
49
52
 
50
 
static const std::string DC_SCHEME_PREFIX = "http://purl.org/dc/elements";
 
53
bool OEBDescriptionReader::isDublinCoreNamespace(const std::string &nsId) const {
 
54
        static const std::string DC_SCHEME_PREFIX = "http://purl.org/dc/elements";
 
55
        const std::map<std::string,std::string> &namespaceMap = namespaces();
 
56
        std::map<std::string,std::string>::const_iterator iter = namespaceMap.find(nsId);
 
57
        return
 
58
                (iter != namespaceMap.end()) &&
 
59
                ZLStringUtil::stringStartsWith(iter->second, DC_SCHEME_PREFIX);
 
60
}
51
61
 
52
62
void OEBDescriptionReader::startElementHandler(const char *tag, const char **attributes) {
53
63
        const std::string tagString = ZLUnicodeUtil::toLower(tag);
55
65
                myDCMetadataTag = tagString;
56
66
                myReadMetaData = true;
57
67
        } else if (myReadMetaData) {
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)) {
 
68
                if (ZLStringUtil::stringEndsWith(tagString, TITLE_TAG)) {
 
69
                        if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - TITLE_TAG.length()))) {
63
70
                                myReadState = READ_TITLE;
64
71
                        }
65
72
                } 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)) {
 
73
                        if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - AUTHOR_TAG.length()))) {
70
74
                                const char *role = attributeValue(attributes, "role");
71
75
                                if (role == 0) {
72
76
                                        myReadState = READ_AUTHOR2;
74
78
                                        myReadState = READ_AUTHOR;
75
79
                                }
76
80
                        }
 
81
                } else if (ZLStringUtil::stringEndsWith(tagString, SUBJECT_TAG)) {
 
82
                        if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - SUBJECT_TAG.length()))) {
 
83
                                myReadState = READ_SUBJECT;
 
84
                        }
77
85
                }
78
86
        }
79
87
}
83
91
        if (myDCMetadataTag == tagString) {
84
92
                interrupt();
85
93
        } else {
86
 
                if (!myCurrentAuthor.empty()) {
 
94
                ZLStringUtil::stripWhiteSpaces(myBuffer);
 
95
                if (!myBuffer.empty()) {
87
96
                        if (myReadState == READ_AUTHOR) {
88
 
                                myAuthorList.push_back(myCurrentAuthor);
89
 
                        } else /* if (myReadState == READ_AUTHOR2) */ {
90
 
                                myAuthorList2.push_back(myCurrentAuthor);
 
97
                                myAuthorList.push_back(myBuffer);
 
98
                        } else if (myReadState == READ_AUTHOR2) {
 
99
                                myAuthorList2.push_back(myBuffer);
 
100
                        } else if (myReadState == READ_SUBJECT) {
 
101
                                myDescription.addTag(myBuffer);
91
102
                        }
92
 
                        myCurrentAuthor.erase();
 
103
                        myBuffer.erase();
93
104
                }
94
105
                myReadState = READ_NONE;
95
106
        }