mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
BookReadingException: handle reading error more accurately
This commit is contained in:
parent
2976b4c8fa
commit
be37623fcf
33 changed files with 239 additions and 134 deletions
|
@ -82,7 +82,7 @@ static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readMetaInfo(JNIEnv* env, jobject thiz, jobject javaBook) {
|
JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readMetaInfoNative(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(env, thiz);
|
shared_ptr<FormatPlugin> plugin = findCppPlugin(env, thiz);
|
||||||
if (plugin.isNull()) {
|
if (plugin.isNull()) {
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
|
@ -228,7 +228,7 @@ static bool initTOC(JNIEnv *env, jobject javaModel, BookModel &model) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModel(JNIEnv* env, jobject thiz, jobject javaModel) {
|
JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel) {
|
||||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(env, thiz);
|
shared_ptr<FormatPlugin> plugin = findCppPlugin(env, thiz);
|
||||||
if (plugin.isNull()) {
|
if (plugin.isNull()) {
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
|
|
|
@ -136,8 +136,8 @@ public abstract class DictionaryUtil {
|
||||||
if (ourInfos.isEmpty()) {
|
if (ourInfos.isEmpty()) {
|
||||||
final Thread initThread = new Thread(new Runnable() {
|
final Thread initThread = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
new InfoReader().read(ZLFile.createFileByPath("dictionaries/main.xml"));
|
new InfoReader().readQuietly(ZLFile.createFileByPath("dictionaries/main.xml"));
|
||||||
new ParagonInfoReader(context).read(ZLFile.createFileByPath("dictionaries/paragon.xml"));
|
new ParagonInfoReader(context).readQuietly(ZLFile.createFileByPath("dictionaries/paragon.xml"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
initThread.setPriority(Thread.MIN_PRIORITY);
|
initThread.setPriority(Thread.MIN_PRIORITY);
|
||||||
|
|
|
@ -27,10 +27,10 @@ import org.geometerplus.fbreader.library.Book;
|
||||||
import org.geometerplus.fbreader.formats.*;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
|
|
||||||
public abstract class BookModel {
|
public abstract class BookModel {
|
||||||
public static BookModel createModel(Book book) {
|
public static BookModel createModel(Book book) throws BookReadingException {
|
||||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File);
|
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
return null;
|
throw new BookReadingException("pluginNotFound");
|
||||||
}
|
}
|
||||||
|
|
||||||
final BookModel model;
|
final BookModel model;
|
||||||
|
@ -42,13 +42,11 @@ public abstract class BookModel {
|
||||||
model = new JavaBookModel(book);
|
model = new JavaBookModel(book);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
throw new BookReadingException("unknownPluginType", plugin.type().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.readModel(model)) {
|
plugin.readModel(model);
|
||||||
return model;
|
return model;
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Book Book;
|
public final Book Book;
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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.bookmodel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
|
public final class BookReadingException extends Exception {
|
||||||
|
private static String getResourceText(String resourceId) {
|
||||||
|
return ZLResource.resource("bookReadingException").getResource(resourceId).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookReadingException(String resourceId) {
|
||||||
|
super(getResourceText(resourceId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookReadingException(String resourceId, String param) {
|
||||||
|
super(getResourceText(resourceId).replace("%s", param));
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookReadingException(IOException e, ZLFile file) {
|
||||||
|
super(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,6 +32,7 @@ import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||||
import org.geometerplus.zlibrary.text.view.*;
|
import org.geometerplus.zlibrary.text.view.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
import org.geometerplus.fbreader.bookmodel.TOCTree;
|
import org.geometerplus.fbreader.bookmodel.TOCTree;
|
||||||
import org.geometerplus.fbreader.library.*;
|
import org.geometerplus.fbreader.library.*;
|
||||||
|
|
||||||
|
@ -243,8 +244,8 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
Model = null;
|
Model = null;
|
||||||
System.gc();
|
System.gc();
|
||||||
System.gc();
|
System.gc();
|
||||||
Model = BookModel.createModel(book);
|
try {
|
||||||
if (Model != null) {
|
Model = BookModel.createModel(book);
|
||||||
ZLTextHyphenator.Instance().load(book.getLanguage());
|
ZLTextHyphenator.Instance().load(book.getLanguage());
|
||||||
BookTextView.setModel(Model.getTextModel());
|
BookTextView.setModel(Model.getTextModel());
|
||||||
BookTextView.gotoPosition(book.getStoredPosition());
|
BookTextView.gotoPosition(book.getStoredPosition());
|
||||||
|
@ -265,6 +266,8 @@ public final class FBReaderApp extends ZLApplication {
|
||||||
title.append(")");
|
title.append(")");
|
||||||
}
|
}
|
||||||
setTitle(title.toString());
|
setTitle(title.toString());
|
||||||
|
} catch (BookReadingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getViewWidget().repaint();
|
getViewWidget().repaint();
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class TapZoneMap {
|
||||||
final ZLFile mapFile = ZLFile.createFileByPath(
|
final ZLFile mapFile = ZLFile.createFileByPath(
|
||||||
"default/tapzones/" + name.toLowerCase() + ".xml"
|
"default/tapzones/" + name.toLowerCase() + ".xml"
|
||||||
);
|
);
|
||||||
new Reader().read(mapFile);
|
new Reader().readQuietly(mapFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActionByCoordinates(int x, int y, int width, int height, Tap tap) {
|
public String getActionByCoordinates(int x, int y, int width, int height, Tap tap) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ 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.bookmodel.BookModel;
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
import org.geometerplus.fbreader.library.Book;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
|
||||||
public abstract class FormatPlugin {
|
public abstract class FormatPlugin {
|
||||||
|
@ -36,9 +37,9 @@ public abstract class FormatPlugin {
|
||||||
return myFileType;
|
return myFileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean readMetaInfo(Book book);
|
public abstract void readMetaInfo(Book book) throws BookReadingException;
|
||||||
|
public abstract void readModel(BookModel model) throws BookReadingException;
|
||||||
public abstract boolean readLanguageAndEncoding(Book book);
|
public abstract boolean readLanguageAndEncoding(Book book);
|
||||||
public abstract boolean readModel(BookModel model);
|
|
||||||
public abstract ZLImage readCover(ZLFile file);
|
public abstract ZLImage readCover(ZLFile file);
|
||||||
public abstract String readAnnotation(ZLFile file);
|
public abstract String readAnnotation(ZLFile file);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.geometerplus.zlibrary.core.image.*;
|
||||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
import org.geometerplus.fbreader.library.Book;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
|
||||||
public class NativeFormatPlugin extends FormatPlugin {
|
public class NativeFormatPlugin extends FormatPlugin {
|
||||||
|
@ -37,13 +38,25 @@ public class NativeFormatPlugin extends FormatPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public native boolean readMetaInfo(Book book);
|
public void readMetaInfo(Book book) throws BookReadingException {
|
||||||
|
if (!readMetaInfoNative(book)) {
|
||||||
|
throw new BookReadingException("errorReadingFile", book.File.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private native boolean readMetaInfoNative(Book book);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public native boolean readLanguageAndEncoding(Book book);
|
public native boolean readLanguageAndEncoding(Book book);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public native boolean readModel(BookModel model);
|
public void readModel(BookModel model) throws BookReadingException {
|
||||||
|
if (!readModelNative(model)) {
|
||||||
|
throw new BookReadingException("errorReadingFile", model.Book.File.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private native boolean readModelNative(BookModel model);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLImage readCover(final ZLFile file) {
|
public ZLImage readCover(final ZLFile file) {
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.formats.fb2;
|
package org.geometerplus.fbreader.formats.fb2;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
|
||||||
|
@ -92,7 +94,12 @@ public class FB2AnnotationReader extends ZLXMLReaderAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDocument(ZLFile file) {
|
private boolean readDocument(ZLFile file) {
|
||||||
return ZLXMLProcessor.read(this, file, 512);
|
try {
|
||||||
|
ZLXMLProcessor.read(this, file, 512);
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class FB2CoverImage extends ZLImageProxy {
|
||||||
Base64EncodedImage readCover(ZLFile file) {
|
Base64EncodedImage readCover(ZLFile file) {
|
||||||
myReadCoverPage = false;
|
myReadCoverPage = false;
|
||||||
myImageReference = null;
|
myImageReference = null;
|
||||||
read(file);
|
readQuietly(file);
|
||||||
return myImage;
|
return myImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,12 @@
|
||||||
package org.geometerplus.fbreader.formats.fb2;
|
package org.geometerplus.fbreader.formats.fb2;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
import org.geometerplus.fbreader.library.Book;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
import org.geometerplus.fbreader.library.Tag;
|
import org.geometerplus.fbreader.library.Tag;
|
||||||
|
|
||||||
|
@ -54,13 +56,17 @@ public class FB2MetaInfoReader extends ZLXMLReaderAdapter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readMetaInfo() {
|
public void readMetaInfo() throws BookReadingException {
|
||||||
myReadState = READ_NOTHING;
|
myReadState = READ_NOTHING;
|
||||||
myAuthorNames[0] = "";
|
myAuthorNames[0] = "";
|
||||||
myAuthorNames[1] = "";
|
myAuthorNames[1] = "";
|
||||||
myAuthorNames[2] = "";
|
myAuthorNames[2] = "";
|
||||||
myBuffer.delete(0, myBuffer.length());
|
myBuffer.delete(0, myBuffer.length());
|
||||||
return readDocument(myBook.File);
|
try {
|
||||||
|
ZLXMLProcessor.read(this, myBook.File, 512);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BookReadingException(e, myBook.File);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
||||||
|
@ -222,8 +228,4 @@ public class FB2MetaInfoReader extends ZLXMLReaderAdapter {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDocument(ZLFile file) {
|
|
||||||
return ZLXMLProcessor.read(this, file, 512);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.geometerplus.fbreader.formats.fb2;
|
package org.geometerplus.fbreader.formats.fb2;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
import org.geometerplus.fbreader.library.Book;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
@ -31,13 +32,13 @@ public class FB2Plugin extends JavaFormatPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readMetaInfo(Book book) {
|
public void readMetaInfo(Book book) throws BookReadingException {
|
||||||
return new FB2MetaInfoReader(book).readMetaInfo();
|
new FB2MetaInfoReader(book).readMetaInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readModel(BookModel model) {
|
public void readModel(BookModel model) throws BookReadingException {
|
||||||
return new FB2Reader(model).readBook();
|
new FB2Reader(model).readBook();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,8 +20,10 @@
|
||||||
package org.geometerplus.fbreader.formats.fb2;
|
package org.geometerplus.fbreader.formats.fb2;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
||||||
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||||
import org.geometerplus.zlibrary.core.util.*;
|
import org.geometerplus.zlibrary.core.util.*;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
@ -58,9 +60,14 @@ public final class FB2Reader extends ZLXMLReaderAdapter {
|
||||||
myBookReader = new BookReader(model);
|
myBookReader = new BookReader(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean readBook() {
|
void readBook() throws BookReadingException {
|
||||||
Base64EncodedImage.resetCounter();
|
Base64EncodedImage.resetCounter();
|
||||||
return ZLXMLProcessor.read(this, myBookReader.Model.Book.File);
|
final ZLFile file = myBookReader.Model.Book.File;
|
||||||
|
try {
|
||||||
|
ZLXMLProcessor.read(this, file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BookReadingException(e, file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDocumentHandler() {
|
public void startDocumentHandler() {
|
||||||
|
|
|
@ -31,7 +31,7 @@ abstract class FB2TagManager {
|
||||||
|
|
||||||
static ArrayList<Tag> humanReadableTags(String id) {
|
static ArrayList<Tag> humanReadableTags(String id) {
|
||||||
if (ourMap.isEmpty()) {
|
if (ourMap.isEmpty()) {
|
||||||
new FB2TagInfoReader().read(
|
new FB2TagInfoReader().readQuietly(
|
||||||
ZLResourceFile.createResourceFile("formats/fb2/fb2genres.xml")
|
ZLResourceFile.createResourceFile("formats/fb2/fb2genres.xml")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.geometerplus.fbreader.formats.oeb;
|
package org.geometerplus.fbreader.formats.oeb;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLArchiveEntryFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLArchiveEntryFile;
|
||||||
|
@ -57,10 +58,14 @@ class NCXReader extends ZLXMLReaderAdapter {
|
||||||
NCXReader(BookReader modelReader) {
|
NCXReader(BookReader modelReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean readFile(String filePath) {
|
void readFile(String filePath) throws BookReadingException {
|
||||||
final ZLFile file = ZLFile.createFileByPath(filePath);
|
final ZLFile file = ZLFile.createFileByPath(filePath);
|
||||||
myLocalPathPrefix = MiscUtil.archiveEntryName(MiscUtil.htmlDirectoryPrefix(file));
|
myLocalPathPrefix = MiscUtil.archiveEntryName(MiscUtil.htmlDirectoryPrefix(file));
|
||||||
return read(file);
|
try {
|
||||||
|
read(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BookReadingException(e, file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer,NavPoint> navigationMap() {
|
Map<Integer,NavPoint> navigationMap() {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.geometerplus.fbreader.formats.oeb;
|
package org.geometerplus.fbreader.formats.oeb;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
@ -38,7 +39,8 @@ class OEBAnnotationReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
myReadState = READ_NONE;
|
myReadState = READ_NONE;
|
||||||
myBuffer.delete(0, myBuffer.length());
|
myBuffer.delete(0, myBuffer.length());
|
||||||
|
|
||||||
if (ZLXMLProcessor.read(this, file, 512)) {
|
try {
|
||||||
|
ZLXMLProcessor.read(this, file, 512);
|
||||||
final int len = myBuffer.length();
|
final int len = myBuffer.length();
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
if (myBuffer.charAt(len - 1) == '\n') {
|
if (myBuffer.charAt(len - 1) == '\n') {
|
||||||
|
@ -46,8 +48,10 @@ class OEBAnnotationReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
}
|
}
|
||||||
return myBuffer.toString();
|
return myBuffer.toString();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.geometerplus.fbreader.formats.oeb;
|
package org.geometerplus.fbreader.formats.oeb;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
@ -70,7 +71,7 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
private HashMap<String,String> myFileNumbers = new HashMap<String,String>();
|
private HashMap<String,String> myFileNumbers = new HashMap<String,String>();
|
||||||
private HashMap<String,Integer> myTOCLabels = new HashMap<String,Integer>();
|
private HashMap<String,Integer> myTOCLabels = new HashMap<String,Integer>();
|
||||||
|
|
||||||
boolean readBook(ZLFile file) {
|
void readBook(ZLFile file) throws BookReadingException {
|
||||||
myFilePrefix = MiscUtil.htmlDirectoryPrefix(file);
|
myFilePrefix = MiscUtil.htmlDirectoryPrefix(file);
|
||||||
|
|
||||||
myIdToHref.clear();
|
myIdToHref.clear();
|
||||||
|
@ -80,8 +81,10 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
myGuideTOC.clear();
|
myGuideTOC.clear();
|
||||||
myState = READ_NONE;
|
myState = READ_NONE;
|
||||||
|
|
||||||
if (!read(file)) {
|
try {
|
||||||
return false;
|
read(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BookReadingException(e, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
myModelReader.setMainTextModel();
|
myModelReader.setMainTextModel();
|
||||||
|
@ -92,7 +95,7 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
final ZLFile xhtmlFile = ZLFile.createFileByPath(myFilePrefix + name);
|
final ZLFile xhtmlFile = ZLFile.createFileByPath(myFilePrefix + name);
|
||||||
if (xhtmlFile == null) {
|
if (xhtmlFile == null) {
|
||||||
// NPE fix: null for bad attributes in .opf XML file
|
// NPE fix: null for bad attributes in .opf XML file
|
||||||
return false;
|
throw new BookReadingException("fileNotFound", myFilePrefix + name);
|
||||||
}
|
}
|
||||||
if (count++ == 0 && xhtmlFile.getPath().equals(myCoverFileName)) {
|
if (count++ == 0 && xhtmlFile.getPath().equals(myCoverFileName)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -102,13 +105,16 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
|
|
||||||
myModelReader.addHyperlinkLabel(referenceName);
|
myModelReader.addHyperlinkLabel(referenceName);
|
||||||
myTOCLabels.put(referenceName, myModelReader.Model.BookTextModel.getParagraphsNumber());
|
myTOCLabels.put(referenceName, myModelReader.Model.BookTextModel.getParagraphsNumber());
|
||||||
reader.readFile(xhtmlFile, referenceName + '#');
|
try {
|
||||||
|
reader.readFile(xhtmlFile, referenceName + '#');
|
||||||
|
} catch (IOException e) {
|
||||||
|
// skip
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
myModelReader.insertEndOfSectionParagraph();
|
myModelReader.insertEndOfSectionParagraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
generateTOC();
|
generateTOC();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BookModel.Label getTOCLabel(String id) {
|
private BookModel.Label getTOCLabel(String id) {
|
||||||
|
@ -128,33 +134,32 @@ class OEBBookReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
return myModelReader.Model.getLabel(num + id.substring(index));
|
return myModelReader.Model.getLabel(num + id.substring(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateTOC() {
|
private void generateTOC() throws BookReadingException {
|
||||||
if (myNCXTOCFileName != null) {
|
if (myNCXTOCFileName != null) {
|
||||||
final NCXReader ncxReader = new NCXReader(myModelReader);
|
final NCXReader ncxReader = new NCXReader(myModelReader);
|
||||||
if (ncxReader.readFile(myFilePrefix + myNCXTOCFileName)) {
|
ncxReader.readFile(myFilePrefix + myNCXTOCFileName);
|
||||||
final Map<Integer,NCXReader.NavPoint> navigationMap = ncxReader.navigationMap();
|
final Map<Integer,NCXReader.NavPoint> navigationMap = ncxReader.navigationMap();
|
||||||
if (!navigationMap.isEmpty()) {
|
if (!navigationMap.isEmpty()) {
|
||||||
int level = 0;
|
int level = 0;
|
||||||
for (NCXReader.NavPoint point : navigationMap.values()) {
|
for (NCXReader.NavPoint point : navigationMap.values()) {
|
||||||
final BookModel.Label label = getTOCLabel(point.ContentHRef);
|
final BookModel.Label label = getTOCLabel(point.ContentHRef);
|
||||||
int index = (label != null) ? label.ParagraphIndex : -1;
|
int index = (label != null) ? label.ParagraphIndex : -1;
|
||||||
while (level > point.Level) {
|
while (level > point.Level) {
|
||||||
myModelReader.endContentsParagraph();
|
|
||||||
--level;
|
|
||||||
}
|
|
||||||
while (++level <= point.Level) {
|
|
||||||
myModelReader.beginContentsParagraph(-2);
|
|
||||||
myModelReader.addContentsData(Dots);
|
|
||||||
}
|
|
||||||
myModelReader.beginContentsParagraph(index);
|
|
||||||
myModelReader.addContentsData(point.Text.toCharArray());
|
|
||||||
}
|
|
||||||
while (level > 0) {
|
|
||||||
myModelReader.endContentsParagraph();
|
myModelReader.endContentsParagraph();
|
||||||
--level;
|
--level;
|
||||||
}
|
}
|
||||||
return;
|
while (++level <= point.Level) {
|
||||||
|
myModelReader.beginContentsParagraph(-2);
|
||||||
|
myModelReader.addContentsData(Dots);
|
||||||
|
}
|
||||||
|
myModelReader.beginContentsParagraph(index);
|
||||||
|
myModelReader.addContentsData(point.Text.toCharArray());
|
||||||
}
|
}
|
||||||
|
while (level > 0) {
|
||||||
|
myModelReader.endContentsParagraph();
|
||||||
|
--level;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class OEBCoverBackgroundReader extends ZLXMLReaderAdapter implements XMLNamespac
|
||||||
myPathPrefix = MiscUtil.htmlDirectoryPrefix(file);
|
myPathPrefix = MiscUtil.htmlDirectoryPrefix(file);
|
||||||
myReadGuide = false;
|
myReadGuide = false;
|
||||||
myImage = null;
|
myImage = null;
|
||||||
read(file);
|
readQuietly(file);
|
||||||
return myImage;
|
return myImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,14 @@
|
||||||
package org.geometerplus.fbreader.formats.oeb;
|
package org.geometerplus.fbreader.formats.oeb;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
import org.geometerplus.zlibrary.core.constants.XMLNamespaces;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.library.Book;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
|
|
||||||
class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
private final Book myBook;
|
private final Book myBook;
|
||||||
|
@ -52,12 +54,14 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
myBook.setLanguage(null);
|
myBook.setLanguage(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean readMetaInfo(ZLFile file) {
|
void readMetaInfo(ZLFile file) throws BookReadingException {
|
||||||
myReadMetaData = false;
|
myReadMetaData = false;
|
||||||
myReadState = READ_NONE;
|
myReadState = READ_NONE;
|
||||||
|
|
||||||
if (!ZLXMLProcessor.read(this, file, 512)) {
|
try {
|
||||||
return false;
|
ZLXMLProcessor.read(this, file, 512);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BookReadingException(e, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<String> authors = myAuthorList.isEmpty() ? myAuthorList2 : myAuthorList;
|
final ArrayList<String> authors = myAuthorList.isEmpty() ? myAuthorList2 : myAuthorList;
|
||||||
|
@ -70,8 +74,6 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
}
|
}
|
||||||
myBook.addAuthor(a);
|
myBook.addAuthor(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int READ_NONE = 0;
|
private static final int READ_NONE = 0;
|
||||||
|
|
|
@ -19,18 +19,20 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.formats.oeb;
|
package org.geometerplus.fbreader.formats.oeb;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
|
||||||
import org.geometerplus.fbreader.library.Book;
|
|
||||||
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
||||||
|
|
||||||
public class OEBPlugin extends JavaFormatPlugin {
|
public class OEBPlugin extends JavaFormatPlugin {
|
||||||
public OEBPlugin() {
|
public OEBPlugin() {
|
||||||
super("ePub");
|
super("ePub");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLFile getOpfFile(ZLFile oebFile) {
|
private ZLFile getOpfFile(ZLFile oebFile) throws BookReadingException {
|
||||||
if ("opf".equals(oebFile.getExtension())) {
|
if ("opf".equals(oebFile.getExtension())) {
|
||||||
return oebFile;
|
return oebFile;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +40,7 @@ public class OEBPlugin extends JavaFormatPlugin {
|
||||||
final ZLFile containerInfoFile = ZLFile.createFile(oebFile, "META-INF/container.xml");
|
final ZLFile containerInfoFile = ZLFile.createFile(oebFile, "META-INF/container.xml");
|
||||||
if (containerInfoFile.exists()) {
|
if (containerInfoFile.exists()) {
|
||||||
final ContainerFileReader reader = new ContainerFileReader();
|
final ContainerFileReader reader = new ContainerFileReader();
|
||||||
reader.read(containerInfoFile);
|
reader.readQuietly(containerInfoFile);
|
||||||
final String opfPath = reader.getRootPath();
|
final String opfPath = reader.getRootPath();
|
||||||
if (opfPath != null) {
|
if (opfPath != null) {
|
||||||
return ZLFile.createFile(oebFile, opfPath);
|
return ZLFile.createFile(oebFile, opfPath);
|
||||||
|
@ -50,31 +52,35 @@ public class OEBPlugin extends JavaFormatPlugin {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new BookReadingException("opfFileNotFound");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readMetaInfo(Book book) {
|
public void readMetaInfo(Book book) throws BookReadingException {
|
||||||
final ZLFile opfFile = getOpfFile(book.File);
|
new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File));
|
||||||
return (opfFile != null) ? new OEBMetaInfoReader(book).readMetaInfo(opfFile) : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readModel(BookModel model) {
|
public void readModel(BookModel model) throws BookReadingException {
|
||||||
model.Book.File.setCached(true);
|
model.Book.File.setCached(true);
|
||||||
final ZLFile opfFile = getOpfFile(model.Book.File);
|
new OEBBookReader(model).readBook(getOpfFile(model.Book.File));
|
||||||
return (opfFile != null) ? new OEBBookReader(model).readBook(opfFile) : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLImage readCover(ZLFile file) {
|
public ZLImage readCover(ZLFile file) {
|
||||||
final ZLFile opfFile = getOpfFile(file);
|
try {
|
||||||
return (opfFile != null) ? new OEBCoverReader().readCover(opfFile) : null;
|
return new OEBCoverReader().readCover(getOpfFile(file));
|
||||||
|
} catch (BookReadingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String readAnnotation(ZLFile file) {
|
public String readAnnotation(ZLFile file) {
|
||||||
final ZLFile opfFile = getOpfFile(file);
|
try {
|
||||||
return (opfFile != null) ? new OEBAnnotationReader().readAnnotation(opfFile) : null;
|
return new OEBAnnotationReader().readAnnotation(getOpfFile(file));
|
||||||
|
} catch (BookReadingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class XHTMLImageFinder extends ZLXMLReaderAdapter {
|
||||||
ZLFileImage readImage(ZLFile file) {
|
ZLFileImage readImage(ZLFile file) {
|
||||||
myXHTMLPathPrefix = MiscUtil.htmlDirectoryPrefix(file);
|
myXHTMLPathPrefix = MiscUtil.htmlDirectoryPrefix(file);
|
||||||
myImage = null;
|
myImage = null;
|
||||||
read(file);
|
readQuietly(file);
|
||||||
return myImage;
|
return myImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ 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.bookmodel.BookReadingException;
|
||||||
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
import org.geometerplus.fbreader.formats.JavaFormatPlugin;
|
||||||
|
|
||||||
public class MobipocketPlugin extends JavaFormatPlugin {
|
public class MobipocketPlugin extends JavaFormatPlugin {
|
||||||
|
@ -38,14 +39,14 @@ public class MobipocketPlugin extends JavaFormatPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readMetaInfo(Book book) {
|
public void readMetaInfo(Book book) throws BookReadingException {
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
try {
|
try {
|
||||||
stream = book.File.getInputStream();
|
stream = book.File.getInputStream();
|
||||||
final PdbHeader header = new PdbHeader(stream);
|
final PdbHeader header = new PdbHeader(stream);
|
||||||
PdbUtil.skip(stream, header.Offsets[0] + 16 - header.length());
|
PdbUtil.skip(stream, header.Offsets[0] + 16 - header.length());
|
||||||
if (PdbUtil.readInt(stream) != 0x4D4F4249) /* "MOBI" */ {
|
if (PdbUtil.readInt(stream) != 0x4D4F4249) /* "MOBI" */ {
|
||||||
return false;
|
throw new BookReadingException("unsupportedFileFormat");
|
||||||
}
|
}
|
||||||
final int length = (int)PdbUtil.readInt(stream);
|
final int length = (int)PdbUtil.readInt(stream);
|
||||||
PdbUtil.skip(stream, 4);
|
PdbUtil.skip(stream, 4);
|
||||||
|
@ -111,9 +112,8 @@ public class MobipocketPlugin extends JavaFormatPlugin {
|
||||||
final byte[] titleBuffer = new byte[fullNameLength];
|
final byte[] titleBuffer = new byte[fullNameLength];
|
||||||
stream.read(titleBuffer);
|
stream.read(titleBuffer);
|
||||||
book.setTitle(new String(titleBuffer, encodingName));
|
book.setTitle(new String(titleBuffer, encodingName));
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
throw new BookReadingException(e, book.File);
|
||||||
} finally {
|
} finally {
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -125,12 +125,11 @@ public class MobipocketPlugin extends JavaFormatPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readModel(BookModel model) {
|
public void readModel(BookModel model) throws BookReadingException {
|
||||||
try {
|
try {
|
||||||
return new MobipocketHtmlBookReader(model).readBook();
|
new MobipocketHtmlBookReader(model).readBook();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//e.printStackTrace();
|
throw new BookReadingException(e, model.Book.File);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.geometerplus.fbreader.formats.xhtml;
|
package org.geometerplus.fbreader.formats.xhtml;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
@ -162,7 +163,7 @@ public class XHTMLReader extends ZLXMLReaderAdapter {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readFile(ZLFile file, String referencePrefix) {
|
public void readFile(ZLFile file, String referencePrefix) throws IOException {
|
||||||
fillTagTable();
|
fillTagTable();
|
||||||
|
|
||||||
myReferencePrefix = referencePrefix;
|
myReferencePrefix = referencePrefix;
|
||||||
|
@ -177,7 +178,7 @@ public class XHTMLReader extends ZLXMLReaderAdapter {
|
||||||
myPreformatted = false;
|
myPreformatted = false;
|
||||||
myInsideBody = false;
|
myInsideBody = false;
|
||||||
|
|
||||||
return read(file);
|
read(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final HashMap<String,XHTMLTagAction> myActions = new HashMap<String,XHTMLTagAction>();
|
private final HashMap<String,XHTMLTagAction> myActions = new HashMap<String,XHTMLTagAction>();
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.formats.*;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.Paths;
|
import org.geometerplus.fbreader.Paths;
|
||||||
|
|
||||||
|
@ -150,7 +151,12 @@ public class Book {
|
||||||
myIsSaved = false;
|
myIsSaved = false;
|
||||||
|
|
||||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
|
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
|
||||||
if (plugin == null || !plugin.readMetaInfo(this)) {
|
if (plugin == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
plugin.readMetaInfo(this);
|
||||||
|
} catch (BookReadingException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (myTitle == null || myTitle.length() == 0) {
|
if (myTitle == null || myTitle.length() == 0) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.geometerplus.fbreader.network.opds;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkManager;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkRequest;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkRequest;
|
||||||
|
@ -101,9 +102,9 @@ public class OPDSLinkReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
xmlReader.read(new FileInputStream(catalogsFile));
|
xmlReader.read(new ZLPhysicalFile(catalogsFile));
|
||||||
return xmlReader.links();
|
return xmlReader.links();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException e) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class TipsManager {
|
||||||
final ZLFile file = ZLFile.createFileByPath(getLocalFilePath());
|
final ZLFile file = ZLFile.createFileByPath(getLocalFilePath());
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
final TipsFeedHandler handler = new TipsFeedHandler();
|
final TipsFeedHandler handler = new TipsFeedHandler();
|
||||||
new ATOMXMLReader(handler, false).read(file);
|
new ATOMXMLReader(handler, false).readQuietly(file);
|
||||||
final List<Tip> tips = Collections.unmodifiableList(handler.Tips);
|
final List<Tip> tips = Collections.unmodifiableList(handler.Tips);
|
||||||
if (tips.size() > 0) {
|
if (tips.size() > 0) {
|
||||||
myTips = tips;
|
myTips = tips;
|
||||||
|
|
|
@ -44,14 +44,14 @@ public final class ZLKeyBindings {
|
||||||
public ZLKeyBindings(String name) {
|
public ZLKeyBindings(String name) {
|
||||||
myName = name;
|
myName = name;
|
||||||
final Set<String> keys = new TreeSet<String>();
|
final Set<String> keys = new TreeSet<String>();
|
||||||
new Reader(keys).read(ZLFile.createFileByPath("default/keymap.xml"));
|
new Reader(keys).readQuietly(ZLFile.createFileByPath("default/keymap.xml"));
|
||||||
try {
|
try {
|
||||||
new Reader(keys).read(ZLFile.createFileByPath(Paths.systemShareDirectory() + "/keymap.xml"));
|
new Reader(keys).readQuietly(ZLFile.createFileByPath(Paths.systemShareDirectory() + "/keymap.xml"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
new Reader(keys).read(ZLFile.createFileByPath(Paths.BooksDirectoryOption().getValue() + "/keymap.xml"));
|
new Reader(keys).readQuietly(ZLFile.createFileByPath(Paths.BooksDirectoryOption().getValue() + "/keymap.xml"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public final class ZLEncodingCollection {
|
||||||
private final HashMap<String,String> myEncodingByAlias = new HashMap<String,String>();
|
private final HashMap<String,String> myEncodingByAlias = new HashMap<String,String>();
|
||||||
|
|
||||||
private ZLEncodingCollection() {
|
private ZLEncodingCollection() {
|
||||||
new ZLEncodingCollectionReader().read(
|
new ZLEncodingCollectionReader().readQuietly(
|
||||||
ZLResourceFile.createResourceFile("encodings/Encodings.xml")
|
ZLResourceFile.createResourceFile("encodings/Encodings.xml")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ final class ZLTreeResource extends ZLResource {
|
||||||
public void readDocument(ZLTreeResource root, ZLFile file) {
|
public void readDocument(ZLTreeResource root, ZLFile file) {
|
||||||
myStack.clear();
|
myStack.clear();
|
||||||
myStack.add(root);
|
myStack.add(root);
|
||||||
read(file);
|
readQuietly(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,42 +33,33 @@ public abstract class ZLXMLProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean read(ZLXMLReader reader, InputStream stream, int bufferSize) {
|
public static void read(ZLXMLReader reader, InputStream stream, int bufferSize) throws IOException {
|
||||||
ZLXMLParser parser = null;
|
ZLXMLParser parser = null;
|
||||||
try {
|
try {
|
||||||
parser = new ZLXMLParser(reader, stream, bufferSize);
|
parser = new ZLXMLParser(reader, stream, bufferSize);
|
||||||
reader.startDocumentHandler();
|
reader.startDocumentHandler();
|
||||||
parser.doIt();
|
parser.doIt();
|
||||||
reader.endDocumentHandler();
|
reader.endDocumentHandler();
|
||||||
} catch (IOException e) {
|
|
||||||
//System.out.println(e);
|
|
||||||
return false;
|
|
||||||
} finally {
|
} finally {
|
||||||
if (parser != null) {
|
if (parser != null) {
|
||||||
parser.finish();
|
parser.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean read(ZLXMLReader xmlReader, ZLFile file) {
|
public static void read(ZLXMLReader xmlReader, ZLFile file) throws IOException {
|
||||||
return read(xmlReader, file, 65536);
|
read(xmlReader, file, 65536);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean read(ZLXMLReader xmlReader, ZLFile file, int bufferSize) {
|
public static void read(ZLXMLReader xmlReader, ZLFile file, int bufferSize) throws IOException {
|
||||||
InputStream stream = null;
|
InputStream stream = file.getInputStream();
|
||||||
try {
|
try {
|
||||||
stream = file.getInputStream();
|
read(xmlReader, stream, bufferSize);
|
||||||
} catch (IOException e) {
|
} finally {
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (stream == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean code = read(xmlReader, stream, bufferSize);
|
|
||||||
try {
|
|
||||||
stream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,18 +21,28 @@ package org.geometerplus.zlibrary.core.xml;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
|
||||||
public abstract class ZLXMLReaderAdapter implements ZLXMLReader {
|
public abstract class ZLXMLReaderAdapter implements ZLXMLReader {
|
||||||
private Map<String,String> myNamespaceMap = Collections.emptyMap();
|
private Map<String,String> myNamespaceMap = Collections.emptyMap();
|
||||||
|
|
||||||
public boolean read(ZLFile file) {
|
public boolean readQuietly(ZLFile file) {
|
||||||
return ZLXMLProcessor.read(this, file);
|
try {
|
||||||
|
ZLXMLProcessor.read(this, file);
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean read(InputStream stream) {
|
public void read(ZLFile file) throws IOException {
|
||||||
return ZLXMLProcessor.read(this, stream, 65536);
|
ZLXMLProcessor.read(this, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(InputStream stream) throws IOException {
|
||||||
|
ZLXMLProcessor.read(this, stream, 65536);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dontCacheAttributeValues() {
|
public boolean dontCacheAttributeValues() {
|
||||||
|
|
|
@ -61,7 +61,7 @@ final class ZLTextTeXHyphenator extends ZLTextHyphenator {
|
||||||
unload();
|
unload();
|
||||||
|
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
new ZLTextHyphenationReader(this).read(ZLResourceFile.createResourceFile(
|
new ZLTextHyphenationReader(this).readQuietly(ZLResourceFile.createResourceFile(
|
||||||
"hyphenationPatterns/" + language + ".pattern"
|
"hyphenationPatterns/" + language + ".pattern"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ZLTextStyleCollection {
|
||||||
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
|
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
|
||||||
|
|
||||||
private ZLTextStyleCollection() {
|
private ZLTextStyleCollection() {
|
||||||
new TextStyleReader(this).read(ZLResourceFile.createResourceFile("default/styles.xml"));
|
new TextStyleReader(this).readQuietly(ZLResourceFile.createResourceFile("default/styles.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZLTextStyleCollection Instance() {
|
public static ZLTextStyleCollection Instance() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue