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
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") {
30 } else if (((myReadType
& TITLE
) == TITLE
) && (tag
.Name
== "DC:TITLE")) {
31 myReadTitle
= tag
.Start
;
32 if (!tag
.Start
&& !myTitle
.empty()) {
33 myDescription
.title() = myTitle
;
36 } else if (((myReadType
& AUTHOR
) == AUTHOR
) && (tag
.Name
== "DC:CREATOR")) {
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";
46 if (!myAuthor
.empty()) {
53 if (!myAuthor
.empty()) {
54 myDescription
.addAuthor(myAuthor
);
61 void HtmlMetainfoReader::startDocumentHandler() {
66 void HtmlMetainfoReader::endDocumentHandler() {
69 bool HtmlMetainfoReader::characterDataHandler(const char *text
, int len
, bool convert
) {
72 myConverter
->convert(myTitle
, text
, text
+ len
);
74 myTitle
.append(text
, len
);
76 } else if (myReadAuthor
) {
78 myConverter
->convert(myAuthor
, text
, text
+ len
);
80 myAuthor
.append(text
, len
);