25
25
OEBDescriptionReader::OEBDescriptionReader(BookDescription &description) : myDescription(description) {
26
26
myDescription.clearAuthor();
27
27
myDescription.title().erase();
28
myDescription.removeAllTags();
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";
36
38
void OEBDescriptionReader::characterDataHandler(const char *text, int len) {
42
myCurrentAuthor.append(text, len);
45
myBuffer.append(text, len);
45
48
myDescription.title().append(text, len);
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);
58
(iter != namespaceMap.end()) &&
59
ZLStringUtil::stringStartsWith(iter->second, DC_SCHEME_PREFIX);
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;
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");
72
76
myReadState = READ_AUTHOR2;
74
78
myReadState = READ_AUTHOR;
81
} else if (ZLStringUtil::stringEndsWith(tagString, SUBJECT_TAG)) {
82
if (isDublinCoreNamespace(tagString.substr(0, tagString.length() - SUBJECT_TAG.length()))) {
83
myReadState = READ_SUBJECT;
83
91
if (myDCMetadataTag == tagString) {
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);
92
myCurrentAuthor.erase();
94
105
myReadState = READ_NONE;