* Do <b>NOT</b> 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}
*
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.
* <p>
return custom;
}
- List<MetaData> metas = getListBySource(source);
+ List<MetaData> metas = getList().filter(source, null, null);
if (metas.size() > 0) {
return getCover(metas.get(0).getLuid());
}
return custom;
}
- List<MetaData> metas = getListByAuthor(author);
+ List<MetaData> metas = getList().filter(null, author, null);
if (metas.size() > 0) {
return getCover(metas.get(0).getLuid());
}
}
}
+ /**
+ * Check if the {@link Story} denoted by this Library UID is present in the
+ * cache (if we have no cache, we default to </tt>true</tt>).
+ *
+ * @param luid
+ * the Library UID
+ *
+ * @return TRUE if it is
+ */
+ public boolean isCached(@SuppressWarnings("unused") String luid) {
+ // By default, everything is cached
+ return true;
+ }
+
+ /**
+ * Clear the {@link Story} from the cache, if needed.
+ * <p>
+ * The next time we try to retrieve the {@link Story}, it may be required to
+ * cache it again.
+ *
+ * @param luid
+ * the story to clear
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ @SuppressWarnings("unused")
+ public void clearFromCache(String luid) throws IOException {
+ // By default, this is a noop.
+ }
+
/**
* List all the known types (sources) of stories.
*
* @throws IOException
* in case of IOException
*/
- public synchronized List<String> getSources() throws IOException {
+ public List<String> getSources() throws IOException {
List<String> list = new ArrayList<String>();
for (MetaData meta : getMetas(null)) {
String storySource = meta.getSource();
* @throws IOException
* in case of IOException
*/
- public synchronized Map<String, List<String>> getSourcesGrouped()
- throws IOException {
+ public Map<String, List<String>> getSourcesGrouped() throws IOException {
Map<String, List<String>> map = new TreeMap<String, List<String>>();
for (String source : getSources()) {
String name;
* @throws IOException
* in case of IOException
*/
- public synchronized List<String> getAuthors() throws IOException {
+ public List<String> getAuthors() throws IOException {
List<String> list = new ArrayList<String>();
for (MetaData meta : getMetas(null)) {
String storyAuthor = meta.getAuthor();
* @throws IOException
* in case of IOException
*/
- public synchronized List<MetaData> getList() throws IOException {
- return getMetas(null);
- }
-
- /**
- * List all the stories of the given source type in the {@link BasicLibrary} ,
- * or all the stories if NULL is passed as a type.
- * <p>
- * Cover images not included.
- *
- * @param source the type of story to retrieve, or NULL for all
- *
- * @return the stories
- *
- * @throws IOException in case of IOException
- *
- * @deprecated use {@link BasicLibrary#getList(Progress)} and
- * {@link MetaResultList#filter(List, List, List)}
- */
- @Deprecated
- public synchronized List<MetaData> getListBySource(String source) throws IOException {
- List<String> sources = null;
- if (source != null) {
- sources = new ArrayList<String>();
- sources.add(source);
- }
-
- return getList(null).filter(sources, null, null);
- }
-
- /**
- * List all the stories of the given author in the {@link BasicLibrary}, or
- * all the stories if NULL is passed as an author.
- * <p>
- * Cover images not included.
- *
- * @param author
- * the author of the stories to retrieve, or NULL for all
- *
- * @return the stories
- *
- * @throws IOException
- * in case of IOException
- *
- * @deprecated use {@link BasicLibrary#getList(Progress)} and
- * {@link MetaResultList#filter(List, List, List)}
- */
- public synchronized List<MetaData> getListByAuthor(String author) throws IOException {
- List<String> authors = null;
- if (author != null) {
- authors = new ArrayList<String>();
- authors.add(author);
- }
-
- return getList(null).filter(null, authors, null);
+ public MetaResultList getList() throws IOException {
+ return getList(null);
}
/**
* cover image <b>MAY</b> 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())) {
* @throws IOException
* in case of IOException
*/
- public synchronized Story getStory(String luid, Progress pg)
+ public Story getStory(String luid, Progress pg)
throws IOException {
Progress pgMetas = new Progress();
Progress pgStory = new Progress();
* 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
* @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) {
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);
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();
}
Story story = save(support.process(pgProcess), pgSave);
+ pg.setName(story.getMeta().getTitle());
pg.done();
return story.getMeta();
*/
public synchronized Story save(Story story, String luid, Progress pg)
throws IOException {
+ 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 {
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();
return story;
}
* 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 + ")");
}
/**
meta.setTitle(newTitle);
meta.setAuthor(newAuthor);
saveMeta(meta, pg);
-
- invalidateInfo(luid);
}
/**