kiwix / java-libkiwix

Libkiwix binding for Java & Kotlin
https://central.sonatype.com/artifact/org.kiwix/libkiwix
GNU General Public License v3.0
3 stars 4 forks source link

`Manager` is unable to read the bookmarks from file. #69

Closed MohitMaliFtechiz closed 1 year ago

MohitMaliFtechiz commented 1 year ago

Manager is unable to read the bookmarks from the file if we have not added the book to the library for which book we have saved the bookmarks in that file.

e.g. First I added two books to the library and saved some bookmarks to a file and after that, I closed the application, now I reopened the application and tried to load the bookmarks from that file but it did not read any bookmarks from this file, and return nothing, but if I again add same book to the library then it starts reading the bookmarks from that file for this added book but still not reading the other bookmarks which we had saved for other books. But here it should read all the bookmarks from the file without adding the book to the library as bookmarks are independent.

Steps to reproduce the behavior

you can add these test cases in the test.java class for testing, create a bookmark.txt file inside test package add these bookmarks to that file, and run the test cases.

<bookmarks>
  <bookmark>
    <book>
      <id>8a3066ca-b324-b8ef-3e70-ef944b1a22a3</id>
      <title>Alpine Linux Wiki</title>
      <language>eng</language>
      <date>2022-10-17</date>
    </book>
    <title>Alpine Linux Wiki</title>
    <url>https://bookmarkurl.com/</url>
  </bookmark>
</bookmarks>
 @Test
    public void testSavedBookMarks() throws Exception, ZimFileFormatException, JNIKiwixException {
        TestLibrary lib = new TestLibrary();
        TestManager manager = new TestManager(lib);
        boolean isReaded = manager.readBookmarkFile("bookmark.txt");
        assertEquals(true, isReaded);
        TestBookmark[] bookmarkArray = lib.getBookmarks(true);
        assertEquals(1, bookmarkArray.length);
    }
MohitMaliFtechiz commented 1 year ago

My bad! This is the libkiwix feature for only getting the current zim file bookmarks lib.getBookmarks(true); if we pass false then it starts reading the full bookmark file.

mgautierfr commented 1 year ago

for only getting the current zim file bookmarks

This is not exactly true. true means that it only return "valid" bookmarks. In this context, a bookmark is considered valid if it is about a book actually stored in the library. As you create a new library without books, there is no valid bookmark.