diff --git a/src/org/geometerplus/fbreader/formats/FormatPlugin.java b/src/org/geometerplus/fbreader/formats/FormatPlugin.java index e2210788d..56c925008 100644 --- a/src/org/geometerplus/fbreader/formats/FormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/FormatPlugin.java @@ -26,71 +26,9 @@ import org.geometerplus.zlibrary.core.image.ZLImage; public abstract class FormatPlugin { public abstract boolean acceptsFile(ZLFile file); - public abstract boolean readMetaInfo(Book book); + public abstract boolean readMetaInfo(Book book); + public abstract boolean readLanguageAndEncoding(Book book); public abstract boolean readModel(BookModel model); public abstract ZLImage readCover(ZLFile file); public abstract String readAnnotation(ZLFile file); - - /* - public static void detectEncodingAndLanguage(Book book, InputStream stream) throws IOException { - String language = book.getLanguage(); - String encoding = book.getEncoding(); - if (encoding.length() == 0 || language.length() == 0) { - PluginCollection collection = PluginCollection.Instance(); - if (language.length() == 0) { - language = collection.DefaultLanguageOption.getValue(); - } - if (encoding.length() == 0) { - encoding = collection.DefaultEncodingOption.getValue(); - } - if (collection.LanguageAutoDetectOption.getValue() && stream != null) { - int BUFSIZE = 65536; - byte[] buffer = new byte[BUFSIZE]; - int size = stream.read(buffer, 0, BUFSIZE); - stream.close(); - ZLLanguageDetector.LanguageInfo info = - new ZLLanguageDetector().findInfo(buffer, 0, size); - buffer = null; - if (info != null) { - language = info.Language; - encoding = info.Encoding; - if ((encoding == "US-ASCII") || (encoding == "ISO-8859-1")) { - encoding = "windows-1252"; - } - } - } - book.setEncoding(encoding); - book.setLanguage(language); - } - } - //Last working version - public static void detectEncodingAndLanguage(Book book, InputStream stream) { - String encoding = book.getEncoding(); - if (encoding.length() == 0) { - encoding = EncodingDetector.detect(stream, PluginCollection.Instance().DefaultLanguageOption.getValue()); - if (encoding == "unknown") { - encoding = "windows-1252"; - } - book.setEncoding(encoding); - } - - if (book.getLanguage() == "") { - if ((encoding.equals("US-ASCII")) || - (encoding.equals("ISO-8859-1"))) { - book.setLanguage("en"); - } else if ((book.getEncoding().equals("KOI8-R")) || - (encoding.equals("windows-1251")) || - (encoding.equals("ISO-8859-5")) || - (encoding.equals("IBM866"))) { - book.setLanguage("ru"); - } /*else if ( - (PluginCollection.Instance().DefaultLanguageOption.getValue() == EncodingDetector.Language.CZECH) && - ((encoding == "windows-1250") || - (encoding == "ISO-8859-2") || - (encoding == "IBM852"))) { - book.setLanguage("cs"); - }*/ - /*} - - }*/ } diff --git a/src/org/geometerplus/fbreader/formats/JavaFormatPlugin.java b/src/org/geometerplus/fbreader/formats/JavaFormatPlugin.java new file mode 100644 index 000000000..72f7c3a06 --- /dev/null +++ b/src/org/geometerplus/fbreader/formats/JavaFormatPlugin.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2007-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.fbreader.formats; + +import org.geometerplus.fbreader.library.Book; + +public abstract class JavaFormatPlugin extends FormatPlugin { + public boolean readLanguageAndEncoding(Book book) { + return true; + } +} diff --git a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java index 7b2cdc620..2aa2dddea 100644 --- a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java +++ b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java @@ -21,11 +21,11 @@ package org.geometerplus.fbreader.formats.fb2; import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.library.Book; -import org.geometerplus.fbreader.formats.FormatPlugin; +import org.geometerplus.fbreader.formats.JavaFormatPlugin; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.image.ZLImage; -public class FB2Plugin extends FormatPlugin { +public class FB2Plugin extends JavaFormatPlugin { @Override public boolean acceptsFile(ZLFile file) { return "fb2".equals(file.getExtension()); diff --git a/src/org/geometerplus/fbreader/formats/html/HtmlPlugin.java b/src/org/geometerplus/fbreader/formats/html/HtmlPlugin.java index bd40eaac8..8df334648 100644 --- a/src/org/geometerplus/fbreader/formats/html/HtmlPlugin.java +++ b/src/org/geometerplus/fbreader/formats/html/HtmlPlugin.java @@ -23,11 +23,11 @@ import java.io.IOException; import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.library.Book; -import org.geometerplus.fbreader.formats.FormatPlugin; +import org.geometerplus.fbreader.formats.JavaFormatPlugin; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.image.ZLImage; -public class HtmlPlugin extends FormatPlugin { +public class HtmlPlugin extends JavaFormatPlugin { @Override public boolean acceptsFile(ZLFile file) { diff --git a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java index c1feec5f7..33fc0b5dd 100644 --- a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java +++ b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java @@ -21,11 +21,11 @@ package org.geometerplus.fbreader.formats.oeb; import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.library.Book; -import org.geometerplus.fbreader.formats.FormatPlugin; +import org.geometerplus.fbreader.formats.JavaFormatPlugin; import org.geometerplus.zlibrary.core.filesystem.*; import org.geometerplus.zlibrary.core.image.ZLImage; -public class OEBPlugin extends FormatPlugin { +public class OEBPlugin extends JavaFormatPlugin { public boolean acceptsFile(ZLFile file) { final String extension = file.getExtension(); return diff --git a/src/org/geometerplus/fbreader/formats/pdb/PdbPlugin.java b/src/org/geometerplus/fbreader/formats/pdb/PdbPlugin.java index 38a60cc6b..81400a731 100644 --- a/src/org/geometerplus/fbreader/formats/pdb/PdbPlugin.java +++ b/src/org/geometerplus/fbreader/formats/pdb/PdbPlugin.java @@ -25,9 +25,9 @@ import java.io.InputStream; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.options.ZLStringOption; -import org.geometerplus.fbreader.formats.FormatPlugin; +import org.geometerplus.fbreader.formats.JavaFormatPlugin; -public abstract class PdbPlugin extends FormatPlugin { +public abstract class PdbPlugin extends JavaFormatPlugin { @Override public boolean acceptsFile(ZLFile file) { final String extension = file.getExtension();