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");
|
||||
}*/
|
||||
/*}
|
||||
|
||||
}*/
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue