mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-08 06:38:41 -04:00
Introduce EntryNotFoundException.
This commit is contained in:
parent
827ab31c38
commit
9d6ef87b57
@ -342,7 +342,8 @@ String getLibzimFiles() {
|
||||
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionIterator.java " +
|
||||
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionSearcher.java " +
|
||||
"${projectDir}/src/main/java/org/kiwix/libzim/SuggestionSearch.java " +
|
||||
"${projectDir}/src/main/java/org/kiwix/libzim/ZimFileFormatException.java"
|
||||
"${projectDir}/src/main/java/org/kiwix/libzim/ZimFileFormatException.java " +
|
||||
"${projectDir}/src/main/java/org/kiwix/libzim/EntryNotFoundException.java"
|
||||
}
|
||||
|
||||
task buildLinuxBinding(type: Exec) {
|
||||
|
@ -51,7 +51,7 @@ catch(const zim::ZimFileFormatError& e) { \
|
||||
throwException(env, "java/lang/Exception", e.what()); \
|
||||
return RET; \
|
||||
} catch(const zim::EntryNotFound& e) { \
|
||||
throwException(env, "java/lang/Exception", e.what()); \
|
||||
throwException(env, "org/kiwix/libzim/EntryNotFoundException", e.what()); \
|
||||
return RET; \
|
||||
} catch (const std::ios_base::failure& e) { \
|
||||
throwException(env, "java/io/IOException", e.what()); \
|
||||
|
@ -60,25 +60,25 @@ public class Archive
|
||||
public native int getArticleCount();
|
||||
public native int getMediaCount();
|
||||
public native String getUuid();
|
||||
public native String getMetadata(String name);
|
||||
public native Item getMetadataItem(String name);
|
||||
public native String getMetadata(String name) throws EntryNotFoundException;
|
||||
public native Item getMetadataItem(String name) throws EntryNotFoundException;
|
||||
public native String[] getMetadataKeys();
|
||||
|
||||
public native Item getIllustrationItem(int size);
|
||||
public native boolean hasIllustration(int size);
|
||||
public native long[] getIllustrationSizes();
|
||||
|
||||
public native Entry getEntryByPath(String path);
|
||||
public native Entry getEntryByPath(int index);
|
||||
public native Entry getEntryByPath(String path) throws EntryNotFoundException;
|
||||
public native Entry getEntryByPath(int index) throws EntryNotFoundException;
|
||||
public native boolean hasEntryByPath(String path);
|
||||
|
||||
public native Entry getEntryByTitle(String title);
|
||||
public native Entry getEntryByTitle(int index);
|
||||
public native Entry getEntryByTitle(String title) throws EntryNotFoundException;
|
||||
public native Entry getEntryByTitle(int index) throws EntryNotFoundException;
|
||||
public native boolean hasEntryByTitle(String title);
|
||||
|
||||
public native Entry getEntryByClusterOrder(int index);
|
||||
public native Entry getEntryByClusterOrder(int index) throws EntryNotFoundException;
|
||||
|
||||
public native Entry getMainEntry();
|
||||
public native Entry getMainEntry() throws EntryNotFoundException;
|
||||
public native boolean hasMainEntry();
|
||||
|
||||
public native Entry getRandomEntry();
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Matthieu Gautier <mgautier@kymeria.org>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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.kiwix.libzim;
|
||||
|
||||
public class EntryNotFoundException extends Exception
|
||||
{
|
||||
public EntryNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -54,25 +54,25 @@ public class TestArchive
|
||||
public int getArticleCount() { return inner.getArticleCount(); }
|
||||
public int getMediaCount() { return inner.getMediaCount(); }
|
||||
public String getUuid() { return inner.getUuid(); }
|
||||
public String getMetadata(String name) { return inner.getMetadata(name); }
|
||||
public TestItem getMetadataItem(String name) { return new TestItem(inner.getMetadataItem(name)); }
|
||||
public String getMetadata(String name) throws EntryNotFoundException { return inner.getMetadata(name); }
|
||||
public TestItem getMetadataItem(String name) throws EntryNotFoundException { return new TestItem(inner.getMetadataItem(name)); }
|
||||
public String[] getMetadataKeys() { return inner.getMetadataKeys(); }
|
||||
|
||||
public TestItem getIllustrationItem(int size) { return new TestItem(inner.getIllustrationItem(size)); }
|
||||
public boolean hasIllustration(int size) { return inner.hasIllustration(size); }
|
||||
public long[] getIllustrationSizes() { return inner.getIllustrationSizes(); }
|
||||
|
||||
public TestEntry getEntryByPath(String path) { return new TestEntry(inner.getEntryByPath(path)); }
|
||||
public TestEntry getEntryByPath(int index) { return new TestEntry(inner.getEntryByPath(index)); }
|
||||
public TestEntry getEntryByPath(String path) throws EntryNotFoundException { return new TestEntry(inner.getEntryByPath(path)); }
|
||||
public TestEntry getEntryByPath(int index) throws EntryNotFoundException { return new TestEntry(inner.getEntryByPath(index)); }
|
||||
public boolean hasEntryByPath(String path) { return inner.hasEntryByPath(path); }
|
||||
|
||||
public TestEntry getEntryByTitle(String title) { return new TestEntry(inner.getEntryByTitle(title)); }
|
||||
public TestEntry getEntryByTitle(int index) { return new TestEntry(inner.getEntryByTitle(index)); }
|
||||
public TestEntry getEntryByTitle(String title) throws EntryNotFoundException { return new TestEntry(inner.getEntryByTitle(title)); }
|
||||
public TestEntry getEntryByTitle(int index) throws EntryNotFoundException { return new TestEntry(inner.getEntryByTitle(index)); }
|
||||
public boolean hasEntryByTitle(String title) { return inner.hasEntryByTitle(title); }
|
||||
|
||||
public TestEntry getEntryByClusterOrder(int index) { return new TestEntry(inner.getEntryByClusterOrder(index)); }
|
||||
public TestEntry getEntryByClusterOrder(int index) throws EntryNotFoundException { return new TestEntry(inner.getEntryByClusterOrder(index)); }
|
||||
|
||||
public TestEntry getMainEntry() { return new TestEntry(inner.getMainEntry()); }
|
||||
public TestEntry getMainEntry() throws EntryNotFoundException { return new TestEntry(inner.getMainEntry()); }
|
||||
public boolean hasMainEntry() { return inner.hasMainEntry(); }
|
||||
|
||||
public TestEntry getRandomEntry() { return new TestEntry(inner.getRandomEntry()); }
|
||||
|
@ -47,7 +47,7 @@ public class test {
|
||||
}
|
||||
|
||||
private void testArchive(TestArchive archive)
|
||||
throws IOException {
|
||||
throws IOException, EntryNotFoundException {
|
||||
// test the zim file main page title
|
||||
TestEntry mainPage = archive.getMainEntry();
|
||||
assertTrue(mainPage.isRedirect());
|
||||
@ -158,20 +158,24 @@ public class test {
|
||||
// Test invalid path
|
||||
try {
|
||||
archive.getEntryByTitle("Wrong title");
|
||||
} catch(Exception e) {
|
||||
} catch(EntryNotFoundException e) {
|
||||
assertEquals("Cannot find entry", e.getMessage());
|
||||
} catch(Exception e) {
|
||||
fail("ERROR: Must be a EntryNotFoundException.");
|
||||
}
|
||||
|
||||
try {
|
||||
archive.getEntryByPath("wrong_path.html");
|
||||
} catch(Exception e) {
|
||||
} catch(EntryNotFoundException e) {
|
||||
assertEquals("Cannot find entry", e.getMessage());
|
||||
} catch(Exception e) {
|
||||
fail("ERROR: Must be a EntryNotFoundException.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArchiveDirect()
|
||||
throws JNIKiwixException, IOException, ZimFileFormatException {
|
||||
throws JNIKiwixException, IOException, ZimFileFormatException, EntryNotFoundException {
|
||||
TestArchive archive = new TestArchive("small.zim");
|
||||
testArchive(archive);
|
||||
assertTrue(archive.check());
|
||||
@ -200,12 +204,14 @@ public class test {
|
||||
fail("ERROR: Archive created with invalid Zim file!");
|
||||
} catch (ZimFileFormatException e) {
|
||||
assertEquals("Invalid magic number", e.getMessage());
|
||||
} catch(Exception e) {
|
||||
fail("ERROR: Must be a ZimFileFormatException.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArchiveByFd()
|
||||
throws JNIKiwixException, IOException, ZimFileFormatException {
|
||||
throws JNIKiwixException, IOException, ZimFileFormatException, EntryNotFoundException {
|
||||
FileInputStream fis = new FileInputStream("small.zim");
|
||||
TestArchive archive = new TestArchive(fis.getFD());
|
||||
testArchive(archive);
|
||||
@ -216,7 +222,7 @@ public class test {
|
||||
|
||||
@Test
|
||||
public void testArchiveWithAnEmbeddedArchive()
|
||||
throws JNIKiwixException, IOException, ZimFileFormatException {
|
||||
throws JNIKiwixException, IOException, ZimFileFormatException, EntryNotFoundException {
|
||||
File plainArchive = new File("small.zim");
|
||||
FileInputStream fis = new FileInputStream("small.zim.embedded");
|
||||
TestArchive archive = new TestArchive(fis.getFD(), 8, plainArchive.length());
|
||||
|
Loading…
x
Reference in New Issue
Block a user