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 <ZLStringUtil.h>
22 #include <ZLInputStream.h>
24 #include "HtmlPlugin.h"
25 #include "HtmlDescriptionReader.h"
26 #include "HtmlBookReader.h"
27 #include "../txt/PlainTextFormat.h"
28 #include "../../description/BookDescription.h"
29 #include "../util/MiscUtil.h"
31 bool HtmlPlugin::acceptsFile(const ZLFile
&file
) const {
32 const std::string
&extension
= file
.extension();
33 return ZLStringUtil::stringEndsWith(extension
, "html") || (extension
== "htm");
36 bool HtmlPlugin::readDescription(const std::string
&path
, BookDescription
&description
) const {
38 shared_ptr
<ZLInputStream
> stream
= file
.inputStream();
39 if (stream
.isNull()) {
43 detectEncodingAndLanguage(description
, *stream
);
44 if (description
.encoding().empty()) {
47 HtmlDescriptionReader(description
).readDocument(*stream
);
52 bool HtmlPlugin::readModel(const BookDescription
&description
, BookModel
&model
) const {
53 std::string fileName
= description
.fileName();
54 shared_ptr
<ZLInputStream
> stream
= ZLFile(fileName
).inputStream();
55 if (stream
.isNull()) {
59 PlainTextFormat
format(fileName
);
60 if (!format
.initialized()) {
61 PlainTextFormatDetector detector
;
62 detector
.detect(*stream
, format
);
65 std::string directoryPrefix
= MiscUtil::htmlDirectoryPrefix(fileName
);
66 HtmlBookReader
reader(directoryPrefix
, model
, format
, description
.encoding());
67 reader
.setFileName(MiscUtil::htmlFileName(fileName
));
68 reader
.readDocument(*stream
);
73 const std::string
&HtmlPlugin::iconName() const {
74 static const std::string ICON_NAME
= "html";
78 FormatInfoPage
*HtmlPlugin::createInfoPage(ZLOptionsDialog
&dialog
, const std::string
&fileName
) {
79 return new PlainTextInfoPage(dialog
, fileName
, ZLResourceKey("<PRE>"), false);