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;
|
||||
if (plugin.type() == FormatPlugin.Type.NATIVE) {
|
||||
switch (plugin.type()) {
|
||||
case NATIVE:
|
||||
model = new NativeBookModel(book);
|
||||
} else {
|
||||
break;
|
||||
case JAVA:
|
||||
model = new JavaBookModel(book);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
if (plugin.readModel(model)) {
|
||||
|
|
|
@ -31,10 +31,11 @@ public class FileTypeCollection {
|
|||
private FileTypeCollection() {
|
||||
addType(new FileTypeByExtension("fb2", "fb2", MimeType.TEXT_FB2));
|
||||
addType(new FileTypeEpub());
|
||||
addType(new FileTypeMobipocket());
|
||||
}
|
||||
|
||||
private void addType(FileType type) {
|
||||
myTypes.put(type.Id, type);
|
||||
myTypes.put(type.Id.toLowerCase(), type);
|
||||
}
|
||||
|
||||
public Collection<FileType> types() {
|
||||
|
@ -42,6 +43,6 @@ public class FileTypeCollection {
|
|||
}
|
||||
|
||||
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 {
|
||||
FileTypeMobipocket() {
|
||||
super("mobipocket", "BOOKMOBI");
|
||||
super("Mobipocket", "BOOKMOBI");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,13 +19,20 @@
|
|||
|
||||
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.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 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 readLanguageAndEncoding(Book book);
|
||||
public abstract boolean readModel(BookModel model);
|
||||
|
@ -33,9 +40,11 @@ public abstract class FormatPlugin {
|
|||
public abstract String readAnnotation(ZLFile file);
|
||||
|
||||
public enum Type {
|
||||
ANY,
|
||||
JAVA,
|
||||
NATIVE,
|
||||
EXTERNAL
|
||||
EXTERNAL,
|
||||
NONE
|
||||
};
|
||||
public abstract Type type();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class NativeFormatPlugin extends FormatPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public native boolean acceptsFile(ZLFile file);
|
||||
public native String supportedFileType();
|
||||
|
||||
@Override
|
||||
public native boolean readMetaInfo(Book book);
|
||||
|
|
|
@ -27,8 +27,8 @@ import org.geometerplus.zlibrary.core.image.ZLImage;
|
|||
|
||||
public class FB2Plugin extends JavaFormatPlugin {
|
||||
@Override
|
||||
public boolean acceptsFile(ZLFile file) {
|
||||
return "fb2".equals(file.getExtension());
|
||||
public String supportedFileType() {
|
||||
return "fb2";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,12 +26,9 @@ import org.geometerplus.zlibrary.core.filesystem.*;
|
|||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
||||
public class OEBPlugin extends JavaFormatPlugin {
|
||||
public boolean acceptsFile(ZLFile file) {
|
||||
final String extension = file.getExtension();
|
||||
return
|
||||
"oebzip".equals(extension) ||
|
||||
"epub".equals(extension) ||
|
||||
"opf".equals(extension);
|
||||
@Override
|
||||
public String supportedFileType() {
|
||||
return "ePub";
|
||||
}
|
||||
|
||||
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.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
||||
|
||||
public class MobipocketPlugin extends PdbPlugin {
|
||||
public class MobipocketPlugin extends JavaFormatPlugin {
|
||||
@Override
|
||||
public boolean acceptsFile(ZLFile file) {
|
||||
return super.acceptsFile(file) && (fileType(file) == "BOOKMOBI");
|
||||
public String supportedFileType() {
|
||||
return "Mobipocket";
|
||||
}
|
||||
|
||||
@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