*/
@Override
public String toString() {
- return String.format("%s: [%s]", "" + type, "" + content);
+ return String.format("%s: [%s]", "" + type, content == null ? "N/A"
+ : content);
}
@Override
public synchronized Story save(Story story, String luid, Progress pg)
throws IOException {
+ Instance.getTraceHandler().trace(
+ this.getClass().getSimpleName() + ": saving story " + luid);
+
// Do not change the original metadata, but change the original story
MetaData meta = story.getMeta().clone();
story.setMeta(meta);
updateInfo(story.getMeta());
+ Instance.getTraceHandler().trace(
+ this.getClass().getSimpleName() + ": story saved (" + luid
+ + ")");
+
return story;
}
* in case of I/O error
*/
public synchronized void delete(String luid) throws IOException {
+ Instance.getTraceHandler().trace(
+ this.getClass().getSimpleName() + ": deleting story " + luid);
+
doDelete(luid);
deleteInfo(luid);
+
+ Instance.getTraceHandler().trace(
+ this.getClass().getSimpleName() + ": story deleted (" + luid
+ + ")");
}
/**
public void clearFromCache(String luid) throws IOException {
if (isCached(luid)) {
cacheLib.delete(luid);
- deleteInfo(luid);
}
}
@Override
public File getFile(String luid, Progress pg) {
- File[] files = getStories(pg).get(getInfo(luid));
+ Instance.getTraceHandler().trace(
+ this.getClass().getSimpleName() + ": get file for " + luid);
+
+ File file = null;
+ String mess = "no file found for ";
+
+ MetaData meta = getInfo(luid);
+ Instance.getTraceHandler().trace("(info is: " + meta + ")");
+
+ File[] files = getStories(pg).get(meta);
if (files != null) {
- return files[1];
+ mess = "file retrieved for ";
+ file = files[1];
}
- return null;
+ Instance.getTraceHandler().trace(
+ this.getClass().getSimpleName() + ": " + mess + luid);
+
+ return file;
}
@Override
* @param pg
* the optional {@link Progress}
*
- * @return the list of stories
+ * @return the list of stories (for each item, the first {@link File} is the info file, the
+ * second file is the target {@link File})
*/
private synchronized Map<MetaData, File[]> getStories(Progress pg) {
if (pg == null) {
for (String starter : new String[] { "xdg-open", "open", "see",
"start", "run" }) {
try {
+ Instance.getTraceHandler().trace(
+ "starting external program");
Runtime.getRuntime().exec(
new String[] { starter, target.getAbsolutePath() });
ok = true;
throw new IOException("Cannot find a program to start the file");
}
} else {
+ Instance.getTraceHandler().trace("starting external program");
Runtime.getRuntime().exec(
new String[] { program, target.getAbsolutePath() });
}
meta.setCover(images.get(imagesList.get(0)));
meta.setFakeCover(true);
}
-
-System.out.println("Meta from Cbz support at end: "+meta);
} finally {
IOUtils.deltree(tmpDir);
if (zipIn != null) {
protected List<Entry<String, URL>> getChapters(Progress pg) {
List<Entry<String, URL>> urls = new ArrayList<Entry<String, URL>>();
- int i = 1;
+ int i = 0;
Element doc = getSourceNode();
- Element chapEls = doc.getElementsByClass("chapters").first();
- for (Element chapEl : chapEls.getElementsByTag("li")) {
+ Elements chapEls = doc.getElementsByClass("chapters").first()
+ .getElementsByTag("li");
+ for (Element chapEl : chapEls) {
Element titleEl = chapEl.getElementsByTag("h5").first();
String title = StringUtils.unhtml(titleEl.text()).trim();
- title = Integer.toString(i++); // because Atril does not support
- // strange file names
+
+ // because Atril does not support strange file names
+ title = Integer.toString(chapEls.size() - i);
Element linkEl = chapEl.getElementsByTag("h5").first()
.getElementsByTag("a").first();
} catch (MalformedURLException e) {
Instance.getTraceHandler().error(e);
}
+
+ i++;
}
Collections.reverse(urls);