* @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();
}
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;
return metas;
}
+ @Override
+ public synchronized Story getStory(String luid, MetaData meta, Progress pg) {
+ String normal = Instance.getUiConfig().getString(
+ UiConfig.GUI_NON_IMAGES_DOCUMENT_TYPE);
+ String images = Instance.getUiConfig().getString(
+ UiConfig.GUI_IMAGES_DOCUMENT_TYPE);
+ String type = meta.isImageDocument() ? images : normal;
+
+ MetaData cachedMeta = meta.clone();
+ cachedMeta.setType(type);
+
+ return super.getStory(luid, cachedMeta, pg);
+ }
+
@Override
public synchronized File getFile(final String luid, Progress pg) {
if (pg == null) {
return false;
}
+ @Override
+ protected File getInfoFile() {
+ File source = getSourceFile();
+ if ("index.html".equals(source.getName())) {
+ source = source.getParentFile();
+ }
+
+ String src = source.getPath();
+ File infoFile = new File(src + ".info");
+ if (!infoFile.exists() && src.endsWith(".txt")) {
+ infoFile = new File(
+ src.substring(0, src.length() - ".txt".length()) + ".info");
+ }
+
+ return infoFile;
+ }
+
@Override
public URL getCanonicalUrl(URL source) {
File txt = getTxt(source);