X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FBasicLibrary.java;h=b8b8185cd50f75b915d732901ce8a79814bb9727;hp=78d20d654afee85ec8e1f0826abd156576fe821e;hb=60f723111f3f7f5bd60760afa7d0b645406b48d7;hpb=efdbabcde03fdcdac05c917e1fbc671d621a93a3 diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index 78d20d6..b8b8185 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -565,6 +565,42 @@ abstract public class BasicLibrary { * @return the corresponding {@link Story} or NULL if not found */ public synchronized Story getStory(String luid, Progress pg) { + Progress pgMetas = new Progress(); + Progress pgStory = new Progress(); + if (pg != null) { + pg.setMinMax(0, 100); + pg.addProgress(pgMetas, 10); + pg.addProgress(pgStory, 90); + } + + MetaData meta = null; + for (MetaData oneMeta : getMetas(pgMetas)) { + if (oneMeta.getLuid().equals(luid)) { + meta = oneMeta; + break; + } + } + + pgMetas.done(); + + Story story = getStory(luid, meta, pgStory); + pgStory.done(); + + return story; + } + + /** + * Retrieve a specific {@link Story}. + * + * @param luid + * the meta of the story + * @param pg + * the optional progress reporter + * + * @return the corresponding {@link Story} or NULL if not found + */ + public synchronized Story getStory(String luid, MetaData meta, Progress pg) { + if (pg == null) { pg = new Progress(); } @@ -577,39 +613,32 @@ abstract public class BasicLibrary { pg.addProgress(pgProcess, 1); Story story = null; - for (MetaData meta : getMetas(null)) { - if (meta.getLuid().equals(luid)) { - File file = getFile(luid, pgGet); - pgGet.done(); - try { - SupportType type = SupportType.valueOfAllOkUC(meta - .getType()); - URL url = file.toURI().toURL(); - if (type != null) { - story = BasicSupport.getSupport(type, url) // - .process(pgProcess); - - // Because we do not want to clear the meta cache: - meta.setCover(story.getMeta().getCover()); - meta.setResume(story.getMeta().getResume()); - story.setMeta(meta); - // - } else { - throw new IOException("Unknown type: " + meta.getType()); - } - } catch (IOException e) { - // We should not have not-supported files in the - // library - Instance.getTraceHandler().error( - new IOException("Cannot load file from library: " - + file, e)); - } finally { - pgProcess.done(); - pg.done(); - } - - break; + File file = getFile(luid, pgGet); + pgGet.done(); + try { + SupportType type = SupportType.valueOfAllOkUC(meta.getType()); + URL url = file.toURI().toURL(); + if (type != null) { + story = BasicSupport.getSupport(type, url) // + .process(pgProcess); + + // Because we do not want to clear the meta cache: + meta.setCover(story.getMeta().getCover()); + meta.setResume(story.getMeta().getResume()); + story.setMeta(meta); + // + } else { + throw new IOException("Unknown type: " + meta.getType()); } + } catch (IOException e) { + // We should not have not-supported files in the + // library + Instance.getTraceHandler() + .error(new IOException("Cannot load file from library: " + + file, e)); + } finally { + pgProcess.done(); + pg.done(); } return story;