gui
[lbook_fbreader.git] / fbreader / src / formats / pdb / HtmlMetainfoReader.cpp
blob37c06ecb93e997b73fba5011c59db8648f01fab1
1 /*
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
17 * 02110-1301, USA.
20 #include <ZLUnicodeUtil.h>
22 #include "HtmlMetainfoReader.h"
24 HtmlMetainfoReader::HtmlMetainfoReader(BookDescription &description, ReadType readType) : HtmlReader(description.encoding()), myDescription(description), myReadType(readType) {
27 bool HtmlMetainfoReader::tagHandler(const HtmlReader::HtmlTag &tag) {
28 if (tag.Name == "BODY") {
29 return false;
30 } else if (((myReadType & TITLE) == TITLE) && (tag.Name == "DC:TITLE")) {
31 myReadTitle = tag.Start;
32 if (!tag.Start && !myTitle.empty()) {
33 myDescription.title() = myTitle;
34 myTitle.erase();
36 } else if (((myReadType & AUTHOR) == AUTHOR) && (tag.Name == "DC:CREATOR")) {
37 if (tag.Start) {
38 bool flag = false;
39 for (size_t i = 0; i < tag.Attributes.size(); ++i) {
40 if (tag.Attributes[i].Name == "ROLE") {
41 flag = ZLUnicodeUtil::toUpper(tag.Attributes[i].Value) == "AUT";
42 break;
45 if (flag) {
46 if (!myAuthor.empty()) {
47 myAuthor += ", ";
49 myReadAuthor = true;
51 } else {
52 myReadAuthor = false;
53 if (!myAuthor.empty()) {
54 myDescription.addAuthor(myAuthor);
58 return true;
61 void HtmlMetainfoReader::startDocumentHandler() {
62 myReadAuthor = false;
63 myReadTitle = false;
66 void HtmlMetainfoReader::endDocumentHandler() {
69 bool HtmlMetainfoReader::characterDataHandler(const char *text, int len, bool convert) {
70 if (myReadTitle) {
71 if (convert) {
72 myConverter->convert(myTitle, text, text + len);
73 } else {
74 myTitle.append(text, len);
76 } else if (myReadAuthor) {
77 if (convert) {
78 myConverter->convert(myAuthor, text, text + len);
79 } else {
80 myAuthor.append(text, len);
83 return true;