mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
FormatPlugin.realBookFile() method
This commit is contained in:
parent
cf849068bd
commit
02a2b5c6cd
10 changed files with 111 additions and 8 deletions
|
@ -16,6 +16,7 @@ litres: author photos
|
|||
* ePubs in zips
|
||||
* scale-to-fullscreen for all pictures
|
||||
* show-hide temporary activity after brightness changing (to switch off the button lights)
|
||||
* encodings list for native plugins
|
||||
|
||||
* API от Paragon
|
||||
* rtf: cover?
|
||||
|
|
|
@ -34,7 +34,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginColl
|
|||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
jstring fileType = AndroidUtil::createJavaString(env, plugins[i]->supportedFileType());
|
||||
jobject p = AndroidUtil::Constructor_NativeFormatPlugin->call(fileType);
|
||||
jobject p = AndroidUtil::StaticMethod_NativeFormatPlugin_create->call(fileType);
|
||||
env->SetObjectArrayElement(javaPlugins, i, p);
|
||||
env->DeleteLocalRef(p);
|
||||
env->DeleteLocalRef(fileType);
|
||||
|
|
|
@ -66,7 +66,7 @@ shared_ptr<LongMethod> AndroidUtil::Method_java_io_InputStream_skip;
|
|||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_ZLibrary_Instance;
|
||||
shared_ptr<StringMethod> AndroidUtil::Method_ZLibrary_getVersionName;
|
||||
|
||||
shared_ptr<Constructor> AndroidUtil::Constructor_NativeFormatPlugin;
|
||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_NativeFormatPlugin_create;
|
||||
shared_ptr<StringMethod> AndroidUtil::Method_NativeFormatPlugin_supportedFileType;
|
||||
|
||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_PluginCollection_Instance;
|
||||
|
@ -142,7 +142,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
StaticMethod_ZLibrary_Instance = new StaticObjectMethod(Class_ZLibrary, "Instance", Class_ZLibrary, "()");
|
||||
Method_ZLibrary_getVersionName = new StringMethod(Class_ZLibrary, "getVersionName", "()");
|
||||
|
||||
Constructor_NativeFormatPlugin = new Constructor(Class_NativeFormatPlugin, "(Ljava/lang/String;)V");
|
||||
StaticMethod_NativeFormatPlugin_create = new StaticObjectMethod(Class_NativeFormatPlugin, "create", Class_NativeFormatPlugin, "(Ljava/lang/String;)");
|
||||
Method_NativeFormatPlugin_supportedFileType = new StringMethod(Class_NativeFormatPlugin, "supportedFileType", "()");
|
||||
|
||||
StaticMethod_PluginCollection_Instance = new StaticObjectMethod(Class_PluginCollection, "Instance", Class_PluginCollection, "()");
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
|
||||
static shared_ptr<Constructor> Constructor_ZLFileImage;
|
||||
|
||||
static shared_ptr<Constructor> Constructor_NativeFormatPlugin;
|
||||
static shared_ptr<StaticObjectMethod> StaticMethod_NativeFormatPlugin_create;
|
||||
static shared_ptr<StringMethod> Method_NativeFormatPlugin_supportedFileType;
|
||||
|
||||
static shared_ptr<StaticObjectMethod> StaticMethod_PluginCollection_Instance;
|
||||
|
|
|
@ -40,6 +40,10 @@
|
|||
-keepclassmembers class org.geometerplus.fbreader.formats.FormatPlugin {
|
||||
public ** supportedFileType();
|
||||
}
|
||||
-keep class org.geometerplus.fbreader.formats.NativeFormatPlugin
|
||||
-keepclassmembers class org.geometerplus.fbreader.formats.NativeFormatPlugin {
|
||||
public static ** create(**);
|
||||
}
|
||||
-keep class org.geometerplus.zlibrary.core.encodings.Encoding
|
||||
-keepclassmembers class org.geometerplus.zlibrary.core.encodings.Encoding {
|
||||
public ** createConverter();
|
||||
|
|
|
@ -38,6 +38,9 @@ public abstract class FormatPlugin {
|
|||
return myFileType;
|
||||
}
|
||||
|
||||
public ZLFile realBookFile(ZLFile file) throws BookReadingException {
|
||||
return file;
|
||||
}
|
||||
public abstract void readMetaInfo(Book book) throws BookReadingException;
|
||||
public abstract void readModel(BookModel model) throws BookReadingException;
|
||||
public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.geometerplus.fbreader.formats;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.encodings.JavaEncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.image.*;
|
||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||
|
@ -27,12 +28,18 @@ import org.geometerplus.zlibrary.core.util.MimeType;
|
|||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.fb2.FB2NativePlugin;
|
||||
|
||||
public class NativeFormatPlugin extends FormatPlugin {
|
||||
// No free method because all plugins' instances are freed by
|
||||
// PluginCollection::deleteInstance method (C++)
|
||||
public static NativeFormatPlugin create(String fileType) {
|
||||
if ("fb2".equals(fileType)) {
|
||||
return new FB2NativePlugin();
|
||||
} else {
|
||||
return new NativeFormatPlugin(fileType);
|
||||
}
|
||||
}
|
||||
|
||||
public NativeFormatPlugin(String fileType) {
|
||||
protected NativeFormatPlugin(String fileType) {
|
||||
super(fileType);
|
||||
}
|
||||
|
||||
|
@ -97,7 +104,7 @@ public class NativeFormatPlugin extends FormatPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public JavaEncodingCollection supportedEncodings() {
|
||||
public EncodingCollection supportedEncodings() {
|
||||
// TODO: implement
|
||||
return JavaEncodingCollection.Instance();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2011-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.fb2;
|
||||
|
||||
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
import org.geometerplus.fbreader.formats.NativeFormatPlugin;
|
||||
|
||||
public class FB2NativePlugin extends NativeFormatPlugin {
|
||||
public FB2NativePlugin() {
|
||||
super("fb2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLFile realBookFile(ZLFile file) {
|
||||
return FB2Util.getRealFB2File(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncodingCollection supportedEncodings() {
|
||||
return new AutoEncodingCollection();
|
||||
}
|
||||
}
|
|
@ -33,6 +33,11 @@ public class FB2Plugin extends JavaFormatPlugin {
|
|||
super("fb2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLFile realBookFile(ZLFile file) {
|
||||
return FB2Util.getRealFB2File(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMetaInfo(Book book) throws BookReadingException {
|
||||
new FB2MetaInfoReader(book).readMetaInfo();
|
||||
|
|
40
src/org/geometerplus/fbreader/formats/fb2/FB2Util.java
Normal file
40
src/org/geometerplus/fbreader/formats/fb2/FB2Util.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 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.fb2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
abstract class FB2Util {
|
||||
static ZLFile getRealFB2File(ZLFile file) {
|
||||
final String name = file.getShortName().toLowerCase();
|
||||
if (name.endsWith(".fb2.zip") && file.isArchive()) {
|
||||
final List<ZLFile> children = file.children();
|
||||
if (children != null && children.size() == 1) {
|
||||
return children.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue