X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=library%2FBasicLibrary.java;h=586c4ef17e11ff4d8c7eefa1cf6c689dac71ce59;hb=8e7a5d0e13cb1fbbf3a2d71de99b119ef56a999c;hp=7f286079ed1fe87c88f2ec798a85c26774950089;hpb=3b039231be91c50e3d1bd59492205d61a0928494;p=nikiroo-utils.git diff --git a/library/BasicLibrary.java b/library/BasicLibrary.java index 7f28607..586c4ef 100644 --- a/library/BasicLibrary.java +++ b/library/BasicLibrary.java @@ -98,7 +98,7 @@ abstract public class BasicLibrary { * Do NOT alter this file. * * @param luid - * the Library UID of the story + * the Library UID of the story, can be NULL * @param pg * the optional {@link Progress} * @@ -123,12 +123,12 @@ abstract public class BasicLibrary { public abstract Image getCover(String luid) throws IOException; // TODO: ensure it is the main used interface - public synchronized MetaResultList getList(Progress pg) throws IOException { + public MetaResultList getList(Progress pg) throws IOException { return new MetaResultList(getMetas(pg)); } - - //TODO: make something for (normal and custom) not-story covers - + + // TODO: make something for (normal and custom) not-story covers + /** * Return the cover image associated to this source. *

@@ -338,14 +338,14 @@ abstract public class BasicLibrary { * @param pg * the optional progress reporter */ - public synchronized void refresh(Progress pg) { + public void refresh(Progress pg) { try { getMetas(pg); } catch (IOException e) { // We will let it fail later } } - + /** * Check if the {@link Story} denoted by this Library UID is present in the * cache (if we have no cache, we default to true). @@ -359,7 +359,7 @@ abstract public class BasicLibrary { // By default, everything is cached return true; } - + /** * Clear the {@link Story} from the cache, if needed. *

@@ -384,7 +384,7 @@ abstract public class BasicLibrary { * @throws IOException * in case of IOException */ - public synchronized List getSources() throws IOException { + public List getSources() throws IOException { List list = new ArrayList(); for (MetaData meta : getMetas(null)) { String storySource = meta.getSource(); @@ -414,8 +414,7 @@ abstract public class BasicLibrary { * @throws IOException * in case of IOException */ - public synchronized Map> getSourcesGrouped() - throws IOException { + public Map> getSourcesGrouped() throws IOException { Map> map = new TreeMap>(); for (String source : getSources()) { String name; @@ -450,7 +449,7 @@ abstract public class BasicLibrary { * @throws IOException * in case of IOException */ - public synchronized List getAuthors() throws IOException { + public List getAuthors() throws IOException { List list = new ArrayList(); for (MetaData meta : getMetas(null)) { String storyAuthor = meta.getAuthor(); @@ -606,14 +605,14 @@ abstract public class BasicLibrary { * cover image MAY not be included. * * @param luid - * the Library UID of the story + * the Library UID of the story, can be NULL * - * @return the corresponding {@link Story} + * @return the corresponding {@link Story} or NULL if not found * * @throws IOException * in case of IOException */ - public synchronized MetaData getInfo(String luid) throws IOException { + public MetaData getInfo(String luid) throws IOException { if (luid != null) { for (MetaData meta : getMetas(null)) { if (luid.equals(meta.getLuid())) { @@ -668,6 +667,8 @@ abstract public class BasicLibrary { * Retrieve a specific {@link Story}. * * @param luid + * the LUID of the story + * @param meta * the meta of the story * @param pg * the optional progress reporter @@ -677,8 +678,7 @@ abstract public class BasicLibrary { * @throws IOException * in case of IOException */ - public synchronized Story getStory(String luid, - @SuppressWarnings("javadoc") MetaData meta, Progress pg) + public synchronized Story getStory(String luid, MetaData meta, Progress pg) throws IOException { if (pg == null) { @@ -693,12 +693,21 @@ abstract public class BasicLibrary { pg.addProgress(pgProcess, 1); Story story = null; - File file = getFile(luid, pgGet); + File file = null; + + if (luid != null && meta != null) { + file = getFile(luid, pgGet); + } + pgGet.done(); try { - SupportType type = SupportType.valueOfAllOkUC(meta.getType()); - URL url = file.toURI().toURL(); - if (type != null) { + if (file != null) { + SupportType type = SupportType.valueOfAllOkUC(meta.getType()); + if (type == null) { + throw new IOException("Unknown type: " + meta.getType()); + } + + URL url = file.toURI().toURL(); story = BasicSupport.getSupport(type, url) // .process(pgProcess); @@ -706,15 +715,13 @@ abstract public class BasicLibrary { 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.getInstance().getTraceHandler().error(new IOException( - String.format("Cannot load file of type '%s' from library: %s", meta.getType(), file), e)); + // We should not have not-supported files in the library + Instance.getInstance().getTraceHandler() + .error(new IOException(String.format( + "Cannot load file of type '%s' from library: %s", + meta.getType(), file), e)); } finally { pgProcess.done(); pg.done(); @@ -876,15 +883,16 @@ abstract public class BasicLibrary { if (pg == null) { pg = new Progress(); } - - Instance.getInstance().getTraceHandler().trace(this.getClass().getSimpleName() + ": saving story " + luid); + + Instance.getInstance().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); pg.setName("Saving story"); - + if (luid == null || luid.isEmpty()) { meta.setLuid(String.format("%03d", getNextId())); } else { @@ -900,7 +908,8 @@ abstract public class BasicLibrary { updateInfo(story.getMeta()); Instance.getInstance().getTraceHandler() - .trace(this.getClass().getSimpleName() + ": story saved (" + luid + ")"); + .trace(this.getClass().getSimpleName() + ": story saved (" + + luid + ")"); pg.setName(meta.getTitle()); pg.done(); @@ -917,14 +926,15 @@ abstract public class BasicLibrary { * in case of I/O error */ public synchronized void delete(String luid) throws IOException { - Instance.getInstance().getTraceHandler().trace(this.getClass().getSimpleName() + ": deleting story " + luid); + Instance.getInstance().getTraceHandler().trace( + this.getClass().getSimpleName() + ": deleting story " + luid); doDelete(luid); invalidateInfo(luid); Instance.getInstance().getTraceHandler() - .trace(this.getClass().getSimpleName() + ": story deleted (" + luid - + ")"); + .trace(this.getClass().getSimpleName() + ": story deleted (" + + luid + ")"); } /**