mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
new method readLanguageAndEncoding in FormatPlugin (synchronization with native branch)
This commit is contained in:
parent
ebeb1c517e
commit
86a5593153
6 changed files with 38 additions and 72 deletions
|
@ -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");
|
||||
}*/
|
||||
/*}
|
||||
|
||||
}*/
|
||||
}
|
||||
|
|
28
src/org/geometerplus/fbreader/formats/JavaFormatPlugin.java
Normal file
28
src/org/geometerplus/fbreader/formats/JavaFormatPlugin.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue