mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
implemented OEBEncryptionReader; fixed container.xml search
This commit is contained in:
parent
60032f42ef
commit
480d3d1398
10 changed files with 139 additions and 16 deletions
|
@ -109,6 +109,7 @@ LOCAL_SRC_FILES := \
|
|||
NativeFormats/fbreader/src/formats/oeb/NCXReader.cpp \
|
||||
NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp \
|
||||
NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.cpp \
|
||||
NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp \
|
||||
NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.cpp \
|
||||
NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp \
|
||||
NativeFormats/fbreader/src/formats/oeb/OEBTextStream.cpp \
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2014 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.
|
||||
*/
|
||||
|
||||
#include <ZLDir.h>
|
||||
#include <ZLLogger.h>
|
||||
#include <ZLXMLNamespace.h>
|
||||
|
||||
#include "OEBEncryptionReader.h"
|
||||
|
||||
OEBEncryptionReader::OEBEncryptionReader() : myType("unknown") {
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
return myType;
|
||||
}
|
||||
|
||||
void OEBEncryptionReader::startElementHandler(const char *tag, const char **attributes) {
|
||||
if (testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag)) {
|
||||
myType = "marlin";
|
||||
}
|
||||
interrupt();
|
||||
}
|
||||
|
||||
bool OEBEncryptionReader::processNamespaces() const {
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2014 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.
|
||||
*/
|
||||
|
||||
#ifndef __OEBENCRYPTIONREADER_H__
|
||||
#define __OEBENCRYPTIONREADER_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <ZLFile.h>
|
||||
#include <ZLXMLReader.h>
|
||||
|
||||
class OEBEncryptionReader : public ZLXMLReader {
|
||||
|
||||
public:
|
||||
OEBEncryptionReader();
|
||||
std::string readEncryptionInfo(const ZLFile &file);
|
||||
|
||||
private:
|
||||
void startElementHandler(const char *tag, const char **attributes);
|
||||
bool processNamespaces() const;
|
||||
|
||||
private:
|
||||
std::string myType;
|
||||
};
|
||||
|
||||
#endif /* __OEBENCRYPTIONREADER_H__ */
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "OEBPlugin.h"
|
||||
#include "OEBMetaInfoReader.h"
|
||||
#include "OEBEncryptionReader.h"
|
||||
#include "OEBUidReader.h"
|
||||
#include "OEBBookReader.h"
|
||||
#include "OEBCoverReader.h"
|
||||
|
@ -77,6 +78,12 @@ const std::string OEBPlugin::supportedFileType() const {
|
|||
return "ePub";
|
||||
}
|
||||
|
||||
ZLFile OEBPlugin::epubFile(const ZLFile &oebFile) {
|
||||
const ZLFile epub = oebFile.extension() == OPF ? oebFile.getContainerArchive() : oebFile;
|
||||
epub.forceArchiveType(ZLFile::ZIP);
|
||||
return epub;
|
||||
}
|
||||
|
||||
ZLFile OEBPlugin::opfFile(const ZLFile &oebFile) {
|
||||
//ZLLogger::Instance().registerClass("epub");
|
||||
|
||||
|
@ -86,9 +93,14 @@ ZLFile OEBPlugin::opfFile(const ZLFile &oebFile) {
|
|||
|
||||
ZLLogger::Instance().println("epub", "Looking for opf file in " + oebFile.path());
|
||||
|
||||
shared_ptr<ZLDir> oebDir = oebFile.directory();
|
||||
if (!oebDir.isNull()) {
|
||||
const ZLFile containerInfoFile(oebDir->itemPath("META-INF/container.xml"));
|
||||
oebFile.forceArchiveType(ZLFile::ZIP);
|
||||
shared_ptr<ZLDir> zipDir = oebFile.directory(false);
|
||||
if (zipDir.isNull()) {
|
||||
ZLLogger::Instance().println("epub", "Couldn't open zip archive");
|
||||
return ZLFile::NO_FILE;
|
||||
}
|
||||
|
||||
const ZLFile containerInfoFile(zipDir->itemPath("META-INF/container.xml"));
|
||||
if (containerInfoFile.exists()) {
|
||||
ZLLogger::Instance().println("epub", "Found container file " + containerInfoFile.path());
|
||||
ContainerFileReader reader;
|
||||
|
@ -96,17 +108,10 @@ ZLFile OEBPlugin::opfFile(const ZLFile &oebFile) {
|
|||
const std::string &opfPath = reader.rootPath();
|
||||
ZLLogger::Instance().println("epub", "opf path = " + opfPath);
|
||||
if (!opfPath.empty()) {
|
||||
return ZLFile(oebDir->itemPath(opfPath));
|
||||
}
|
||||
return ZLFile(zipDir->itemPath(opfPath));
|
||||
}
|
||||
}
|
||||
|
||||
oebFile.forceArchiveType(ZLFile::ZIP);
|
||||
shared_ptr<ZLDir> zipDir = oebFile.directory(false);
|
||||
if (zipDir.isNull()) {
|
||||
ZLLogger::Instance().println("epub", "Couldn't open zip archive");
|
||||
return ZLFile::NO_FILE;
|
||||
}
|
||||
std::vector<std::string> fileNames;
|
||||
zipDir->collectFiles(fileNames, false);
|
||||
for (std::vector<std::string>::const_iterator it = fileNames.begin(); it != fileNames.end(); ++it) {
|
||||
|
@ -124,12 +129,18 @@ bool OEBPlugin::readMetaInfo(Book &book) const {
|
|||
return OEBMetaInfoReader(book).readMetaInfo(opfFile(file));
|
||||
}
|
||||
|
||||
std::string OEBPlugin::readEncryptionType(Book &book) const {
|
||||
return OEBEncryptionReader().readEncryptionInfo(epubFile(book.file()));
|
||||
}
|
||||
|
||||
bool OEBPlugin::readUids(Book &book) const {
|
||||
const ZLFile &file = book.file();
|
||||
return OEBUidReader(book).readUids(opfFile(file));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -26,12 +26,14 @@ class OEBPlugin : public FormatPlugin {
|
|||
|
||||
public:
|
||||
static ZLFile opfFile(const ZLFile &oebFile);
|
||||
static ZLFile epubFile(const ZLFile &oebFile);
|
||||
|
||||
public:
|
||||
~OEBPlugin();
|
||||
bool providesMetaInfo() const;
|
||||
const std::string supportedFileType() const;
|
||||
bool readMetaInfo(Book &book) const;
|
||||
std::string readEncryptionType(Book &book) const;
|
||||
bool readUids(Book &book) const;
|
||||
bool readLanguageAndEncoding(Book &book) const;
|
||||
bool readModel(BookModel &model) const;
|
||||
|
|
|
@ -31,3 +31,4 @@ const std::string ZLXMLNamespace::CalibreMetadata = "http://calibre.kovidgoyal.n
|
|||
const std::string ZLXMLNamespace::Opds = "http://opds-spec.org/2010/catalog";
|
||||
const std::string ZLXMLNamespace::DaisyNCX = "http://www.daisy.org/z3986/2005/ncx/";
|
||||
const std::string ZLXMLNamespace::Svg = "http://www.w3.org/2000/svg";
|
||||
const std::string ZLXMLNamespace::MarlinEpub = "http://marlin-drm.com/epub";
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
static const std::string Opds;
|
||||
static const std::string DaisyNCX;
|
||||
static const std::string Svg;
|
||||
static const std::string MarlinEpub;
|
||||
};
|
||||
|
||||
#endif /* __ZLXMLNAMESPACE_H__ */
|
||||
|
|
|
@ -238,6 +238,14 @@ bool ZLFile::isDirectory() const {
|
|||
return myInfo.IsDirectory;
|
||||
}
|
||||
|
||||
ZLFile ZLFile::getContainerArchive() const {
|
||||
const int index = ZLFSManager::Instance().findArchiveFileNameDelimiter(myPath);
|
||||
if (index == -1) {
|
||||
return NO_FILE;
|
||||
}
|
||||
return ZLFile(myPath.substr(index));
|
||||
}
|
||||
|
||||
const std::string &ZLFile::mimeType() const {
|
||||
if (!myMimeTypeIsUpToDate) {
|
||||
myMimeType = ZLFSManager::Instance().mimeType(myPath);
|
||||
|
|
|
@ -65,6 +65,8 @@ public:
|
|||
bool isDirectory() const;
|
||||
bool isArchive() const;
|
||||
|
||||
ZLFile getContainerArchive() const;
|
||||
|
||||
bool remove() const;
|
||||
bool canRemove() const;
|
||||
|
||||
|
|
|
@ -100,7 +100,11 @@ bool ZLXMLReader::readDocument(shared_ptr<ZLInputStream> stream) {
|
|||
stream->seek(0, true);
|
||||
int index = stringBuffer.find('>');
|
||||
if (index > 0) {
|
||||
stringBuffer = ZLUnicodeUtil::toLower(stringBuffer.substr(0, index));
|
||||
stringBuffer = stringBuffer.substr(0, index);
|
||||
if (!ZLUnicodeUtil::isUtf8String(stringBuffer)) {
|
||||
return false;
|
||||
}
|
||||
stringBuffer = ZLUnicodeUtil::toLower(stringBuffer);
|
||||
int index = stringBuffer.find("\"iso-8859-1\"");
|
||||
if (index > 0) {
|
||||
useWindows1252 = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue