mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
encryption type is visible from java code
This commit is contained in:
parent
480d3d1398
commit
2f75bb15d6
12 changed files with 76 additions and 19 deletions
|
@ -130,6 +130,17 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readEncryptionType(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||
if (plugin.isNull()) {
|
||||
return AndroidUtil::createJavaString(env, FormatPlugin::EncryptionType::UNKNOWN);
|
||||
}
|
||||
|
||||
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
||||
return AndroidUtil::createJavaString(env, plugin->readEncryptionType(*book));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readUidsNative(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
|
||||
#include "../library/Book.h"
|
||||
|
||||
const std::string FormatPlugin::EncryptionType::NONE = "none";
|
||||
const std::string FormatPlugin::EncryptionType::UNKNOWN = "unknown";
|
||||
const std::string FormatPlugin::EncryptionType::MARLIN = "marlin";
|
||||
|
||||
bool FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream, bool force) {
|
||||
std::string language = book.language();
|
||||
std::string encoding = book.encoding();
|
||||
|
@ -99,6 +103,10 @@ const std::string &FormatPlugin::tryOpen(const ZLFile&) const {
|
|||
return EMPTY;
|
||||
}
|
||||
|
||||
const std::string &FormatPlugin::readEncryptionType(Book &book) const {
|
||||
return EncryptionType::NONE;
|
||||
}
|
||||
|
||||
shared_ptr<const ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,15 @@ public:
|
|||
|
||||
class FormatPlugin {
|
||||
|
||||
public:
|
||||
class EncryptionType {
|
||||
|
||||
public:
|
||||
static const std::string NONE;
|
||||
static const std::string UNKNOWN;
|
||||
static const std::string MARLIN;
|
||||
};
|
||||
|
||||
protected:
|
||||
FormatPlugin();
|
||||
|
||||
|
@ -58,6 +67,7 @@ public:
|
|||
|
||||
virtual const std::string &tryOpen(const ZLFile &file) const;
|
||||
virtual bool readMetaInfo(Book &book) const = 0;
|
||||
virtual const std::string &readEncryptionType(Book &book) const;
|
||||
virtual bool readUids(Book &book) const = 0;
|
||||
virtual bool readLanguageAndEncoding(Book &book) const = 0;
|
||||
virtual bool readModel(BookModel &model) const = 0;
|
||||
|
|
|
@ -21,28 +21,31 @@
|
|||
#include <ZLLogger.h>
|
||||
#include <ZLXMLNamespace.h>
|
||||
|
||||
#include "../FormatPlugin.h"
|
||||
#include "OEBEncryptionReader.h"
|
||||
|
||||
OEBEncryptionReader::OEBEncryptionReader() : myType("unknown") {
|
||||
OEBEncryptionReader::OEBEncryptionReader() : myIsMarlin(false) {
|
||||
}
|
||||
|
||||
std::string OEBEncryptionReader::readEncryptionInfo(const ZLFile &epubFile) {
|
||||
const std::string &OEBEncryptionReader::readEncryptionInfo(const ZLFile &epubFile) {
|
||||
shared_ptr<ZLDir> epubDir = epubFile.directory();
|
||||
if (!epubDir.isNull()) {
|
||||
const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml"));
|
||||
if (rightsFile.exists()) {
|
||||
readDocument(rightsFile);
|
||||
} else {
|
||||
myType = "none";
|
||||
}
|
||||
if (epubDir.isNull()) {
|
||||
return FormatPlugin::EncryptionType::UNKNOWN;
|
||||
}
|
||||
|
||||
const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml"));
|
||||
if (rightsFile.exists()) {
|
||||
readDocument(rightsFile);
|
||||
return myIsMarlin
|
||||
? FormatPlugin::EncryptionType::MARLIN
|
||||
: FormatPlugin::EncryptionType::UNKNOWN;
|
||||
} else {
|
||||
return FormatPlugin::EncryptionType::NONE;
|
||||
}
|
||||
return myType;
|
||||
}
|
||||
|
||||
void OEBEncryptionReader::startElementHandler(const char *tag, const char **attributes) {
|
||||
if (testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag)) {
|
||||
myType = "marlin";
|
||||
}
|
||||
myIsMarlin = testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag);
|
||||
interrupt();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,14 +29,14 @@ class OEBEncryptionReader : public ZLXMLReader {
|
|||
|
||||
public:
|
||||
OEBEncryptionReader();
|
||||
std::string readEncryptionInfo(const ZLFile &file);
|
||||
const std::string &readEncryptionInfo(const ZLFile &file);
|
||||
|
||||
private:
|
||||
void startElementHandler(const char *tag, const char **attributes);
|
||||
bool processNamespaces() const;
|
||||
|
||||
private:
|
||||
std::string myType;
|
||||
bool myIsMarlin;
|
||||
};
|
||||
|
||||
#endif /* __OEBENCRYPTIONREADER_H__ */
|
||||
|
|
|
@ -129,7 +129,7 @@ bool OEBPlugin::readMetaInfo(Book &book) const {
|
|||
return OEBMetaInfoReader(book).readMetaInfo(opfFile(file));
|
||||
}
|
||||
|
||||
std::string OEBPlugin::readEncryptionType(Book &book) const {
|
||||
const std::string &OEBPlugin::readEncryptionType(Book &book) const {
|
||||
return OEBEncryptionReader().readEncryptionInfo(epubFile(book.file()));
|
||||
}
|
||||
|
||||
|
@ -139,8 +139,6 @@ bool OEBPlugin::readUids(Book &book) const {
|
|||
}
|
||||
|
||||
bool OEBPlugin::readModel(BookModel &model) const {
|
||||
ZLLogger::Instance().registerClass("encryption");
|
||||
ZLLogger::Instance().println("encryption", "ENCRYPTION TYPE = " + readEncryptionType(*model.book()));
|
||||
const ZLFile &file = model.book()->file();
|
||||
return OEBBookReader(model).readBook(opfFile(file));
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
bool providesMetaInfo() const;
|
||||
const std::string supportedFileType() const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
std::string readEncryptionType(Book &book) const;
|
||||
const std::string &readEncryptionType(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
|
|
|
@ -28,6 +28,12 @@ import org.geometerplus.fbreader.bookmodel.BookModel;
|
|||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
|
||||
public abstract class FormatPlugin {
|
||||
public interface EncryptionType {
|
||||
String NONE = "none";
|
||||
String UNKNOWN = "unknown";
|
||||
String MARLIN = "marlin";
|
||||
}
|
||||
|
||||
private final String myFileType;
|
||||
|
||||
protected FormatPlugin(String fileType) {
|
||||
|
@ -42,6 +48,7 @@ public abstract class FormatPlugin {
|
|||
return file;
|
||||
}
|
||||
public abstract void readMetaInfo(Book book) throws BookReadingException;
|
||||
public abstract String readEncryptionType(Book book);
|
||||
public abstract void readUids(Book book) throws BookReadingException;
|
||||
public abstract void readModel(BookModel model) throws BookReadingException;
|
||||
public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException;
|
||||
|
|
|
@ -60,6 +60,10 @@ public class NativeFormatPlugin extends FormatPlugin {
|
|||
|
||||
private native int readMetaInfoNative(Book book);
|
||||
|
||||
@Override
|
||||
public native String readEncryptionType(Book book);
|
||||
|
||||
@Override
|
||||
synchronized public void readUids(Book book) throws BookReadingException {
|
||||
readUidsNative(book);
|
||||
if (book.uids().isEmpty()) {
|
||||
|
@ -79,6 +83,7 @@ public class NativeFormatPlugin extends FormatPlugin {
|
|||
@Override
|
||||
synchronized public void readModel(BookModel model) throws BookReadingException {
|
||||
final int code = readModelNative(model);
|
||||
System.err.println("ENCRYPTION TYPE = " + readEncryptionType(model.Book));
|
||||
if (code != 0) {
|
||||
throw new BookReadingException(
|
||||
"nativeCodeFailure",
|
||||
|
|
|
@ -47,6 +47,11 @@ public class FB2Plugin extends JavaFormatPlugin {
|
|||
new FB2MetaInfoReader(book).readMetaInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readEncryptionType(Book book) {
|
||||
return EncryptionType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUids(Book book) throws BookReadingException {
|
||||
// this method does nothing, we expect it will be never called
|
||||
|
|
|
@ -61,6 +61,11 @@ public class OEBPlugin extends JavaFormatPlugin {
|
|||
new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readEncryptionType(Book book) {
|
||||
return EncryptionType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUids(Book book) throws BookReadingException {
|
||||
// this method does nothing, we expect it will be never called
|
||||
|
|
|
@ -123,6 +123,11 @@ public class MobipocketPlugin extends JavaFormatPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readEncryptionType(Book book) {
|
||||
return EncryptionType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUids(Book book) throws BookReadingException {
|
||||
if (book.uids().isEmpty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue