Initial commit. FBReader 0.8.12
[lbook_fbreader.git] / fbreader / src / formats / docbook / DocBookDescriptionReader.cpp
blobd4310cc5e9cd28bf6d53edc9cb448746c6a36357
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 <ZLInputStream.h>
22 #include "DocBookDescriptionReader.h"
24 DocBookDescriptionReader::DocBookDescriptionReader(BookDescription &description) : myDescription(description) {
25 myReadTitle = false;
26 myReadAuthor = false;
27 for (int i = 0; i < 3; ++i) {
28 myReadAuthorName[i] = false;
30 myDescription.language() = "en";
31 myDepth = 0;
34 void DocBookDescriptionReader::characterDataHandler(const char *text, int len) {
35 if (myReadTitle) {
36 myDescription.title().append(text, len);
37 } else {
38 for (int i = 0; i < 3; ++i) {
39 if (myReadAuthorName[i]) {
40 myAuthorNames[i].append(text, len);
41 break;
47 void DocBookDescriptionReader::startElementHandler(int tag, const char **) {
48 ++myDepth;
49 switch (tag) {
50 case _SECT1:
51 myReturnCode = true;
52 myDoBreak = true;
53 break;
54 case _TITLE:
55 if (myDepth == 2) {
56 myReadTitle = true;
58 break;
59 case _AUTHOR:
60 if (myDepth == 3) {
61 myReadAuthor = true;
63 break;
64 case _FIRSTNAME:
65 if (myReadAuthor) {
66 myReadAuthorName[0] = true;
68 break;
69 case _OTHERNAME:
70 if (myReadAuthor) {
71 myReadAuthorName[1] = true;
73 break;
74 case _SURNAME:
75 if (myReadAuthor) {
76 myReadAuthorName[2] = true;
78 break;
79 default:
80 break;
84 void DocBookDescriptionReader::endElementHandler(int tag) {
85 --myDepth;
86 switch (tag) {
87 case _TITLE:
88 myReadTitle = false;
89 break;
90 case _AUTHOR:
91 myDescription.addAuthor(myAuthorNames[0], myAuthorNames[1], myAuthorNames[2]);
92 myAuthorNames[0].erase();
93 myAuthorNames[1].erase();
94 myAuthorNames[2].erase();
95 myReadAuthor = false;
96 break;
97 case _FIRSTNAME:
98 myReadAuthorName[0] = false;
99 break;
100 case _OTHERNAME:
101 myReadAuthorName[1] = false;
102 break;
103 case _SURNAME:
104 myReadAuthorName[2] = false;
105 break;
106 default:
107 break;
111 bool DocBookDescriptionReader::readDescription(shared_ptr<ZLInputStream> stream) {
112 return readDocument(stream);