mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
FileTypes are used in plugins
This commit is contained in:
parent
e85d43941e
commit
836653a30b
9 changed files with 36 additions and 81 deletions
|
@ -34,10 +34,15 @@ public abstract class BookModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
final BookModel model;
|
final BookModel model;
|
||||||
if (plugin.type() == FormatPlugin.Type.NATIVE) {
|
switch (plugin.type()) {
|
||||||
model = new NativeBookModel(book);
|
case NATIVE:
|
||||||
} else {
|
model = new NativeBookModel(book);
|
||||||
model = new JavaBookModel(book);
|
break;
|
||||||
|
case JAVA:
|
||||||
|
model = new JavaBookModel(book);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.readModel(model)) {
|
if (plugin.readModel(model)) {
|
||||||
|
|
|
@ -31,10 +31,11 @@ public class FileTypeCollection {
|
||||||
private FileTypeCollection() {
|
private FileTypeCollection() {
|
||||||
addType(new FileTypeByExtension("fb2", "fb2", MimeType.TEXT_FB2));
|
addType(new FileTypeByExtension("fb2", "fb2", MimeType.TEXT_FB2));
|
||||||
addType(new FileTypeEpub());
|
addType(new FileTypeEpub());
|
||||||
|
addType(new FileTypeMobipocket());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addType(FileType type) {
|
private void addType(FileType type) {
|
||||||
myTypes.put(type.Id, type);
|
myTypes.put(type.Id.toLowerCase(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<FileType> types() {
|
public Collection<FileType> types() {
|
||||||
|
@ -42,6 +43,6 @@ public class FileTypeCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileType typeById(String id) {
|
public FileType typeById(String id) {
|
||||||
return myTypes.get(id);
|
return myTypes.get(id.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.geometerplus.zlibrary.core.util.MimeType;
|
||||||
|
|
||||||
class FileTypeMobipocket extends FileTypePalm {
|
class FileTypeMobipocket extends FileTypePalm {
|
||||||
FileTypeMobipocket() {
|
FileTypeMobipocket() {
|
||||||
super("mobipocket", "BOOKMOBI");
|
super("Mobipocket", "BOOKMOBI");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,13 +19,20 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.formats;
|
package org.geometerplus.fbreader.formats;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
|
||||||
import org.geometerplus.fbreader.library.Book;
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
import org.geometerplus.fbreader.filetype.*;
|
||||||
|
|
||||||
public abstract class FormatPlugin {
|
public abstract class FormatPlugin {
|
||||||
public abstract boolean acceptsFile(ZLFile file);
|
public final boolean acceptsFile(ZLFile file) {
|
||||||
|
final FileType fileType = FileTypeCollection.Instance.typeById(supportedFileType());
|
||||||
|
return fileType != null && fileType.acceptsFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String supportedFileType();
|
||||||
public abstract boolean readMetaInfo(Book book);
|
public abstract boolean readMetaInfo(Book book);
|
||||||
public abstract boolean readLanguageAndEncoding(Book book);
|
public abstract boolean readLanguageAndEncoding(Book book);
|
||||||
public abstract boolean readModel(BookModel model);
|
public abstract boolean readModel(BookModel model);
|
||||||
|
@ -33,9 +40,11 @@ public abstract class FormatPlugin {
|
||||||
public abstract String readAnnotation(ZLFile file);
|
public abstract String readAnnotation(ZLFile file);
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
|
ANY,
|
||||||
JAVA,
|
JAVA,
|
||||||
NATIVE,
|
NATIVE,
|
||||||
EXTERNAL
|
EXTERNAL,
|
||||||
|
NONE
|
||||||
};
|
};
|
||||||
public abstract Type type();
|
public abstract Type type();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class NativeFormatPlugin extends FormatPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public native boolean acceptsFile(ZLFile file);
|
public native String supportedFileType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public native boolean readMetaInfo(Book book);
|
public native boolean readMetaInfo(Book book);
|
||||||
|
|
|
@ -27,8 +27,8 @@ import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
|
|
||||||
public class FB2Plugin extends JavaFormatPlugin {
|
public class FB2Plugin extends JavaFormatPlugin {
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsFile(ZLFile file) {
|
public String supportedFileType() {
|
||||||
return "fb2".equals(file.getExtension());
|
return "fb2";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,12 +26,9 @@ import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
|
|
||||||
public class OEBPlugin extends JavaFormatPlugin {
|
public class OEBPlugin extends JavaFormatPlugin {
|
||||||
public boolean acceptsFile(ZLFile file) {
|
@Override
|
||||||
final String extension = file.getExtension();
|
public String supportedFileType() {
|
||||||
return
|
return "ePub";
|
||||||
"oebzip".equals(extension) ||
|
|
||||||
"epub".equals(extension) ||
|
|
||||||
"opf".equals(extension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLFile getOpfFile(ZLFile oebFile) {
|
private ZLFile getOpfFile(ZLFile oebFile) {
|
||||||
|
|
|
@ -30,11 +30,12 @@ import org.geometerplus.zlibrary.core.util.MimeType;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.library.Book;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
||||||
|
|
||||||
public class MobipocketPlugin extends PdbPlugin {
|
public class MobipocketPlugin extends JavaFormatPlugin {
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsFile(ZLFile file) {
|
public String supportedFileType() {
|
||||||
return super.acceptsFile(file) && (fileType(file) == "BOOKMOBI");
|
return "Mobipocket";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.pdb;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
|
||||||
|
|
||||||
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
|
||||||
|
|
||||||
public abstract class PdbPlugin extends JavaFormatPlugin {
|
|
||||||
@Override
|
|
||||||
public boolean acceptsFile(ZLFile file) {
|
|
||||||
final String extension = file.getExtension();
|
|
||||||
return (extension == "prc") || (extension == "pdb") || (extension == "mobi");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static String fileType(final ZLFile file) {
|
|
||||||
// TODO: use database instead of option (?)
|
|
||||||
ZLStringOption palmTypeOption = new ZLStringOption(file.getPath(), "PalmType", "");
|
|
||||||
String palmType = palmTypeOption.getValue();
|
|
||||||
if (palmType.length() != 8) {
|
|
||||||
byte[] id = new byte[8];
|
|
||||||
try {
|
|
||||||
final InputStream stream = file.getInputStream();
|
|
||||||
if (stream == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
stream.skip(60);
|
|
||||||
stream.read(id);
|
|
||||||
stream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
palmType = new String(id).intern();
|
|
||||||
palmTypeOption.setValue(palmType);
|
|
||||||
}
|
|
||||||
return palmType.intern();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue