cached lib can now getStory()
authorNiki Roo <niki@nikiroo.be>
Thu, 21 Mar 2019 15:56:52 +0000 (16:56 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 21 Mar 2019 15:56:52 +0000 (16:56 +0100)
src/be/nikiroo/fanfix/library/BasicLibrary.java
src/be/nikiroo/fanfix/library/CacheLibrary.java
src/be/nikiroo/fanfix/supported/Html.java

index 78d20d654afee85ec8e1f0826abd156576fe821e..b8b8185cd50f75b915d732901ce8a79814bb9727 100644 (file)
@@ -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) {
         * @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();
                }
                if (pg == null) {
                        pg = new Progress();
                }
@@ -577,39 +613,32 @@ abstract public class BasicLibrary {
                pg.addProgress(pgProcess, 1);
 
                Story story = null;
                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 story;
index 9432b33f5a0fb0b46fa360e3ca882fe3386bb87e..ea1fd707913ba0b6696e732a64f38cc3d9cfcdbc 100644 (file)
@@ -65,6 +65,20 @@ public class CacheLibrary extends BasicLibrary {
                return metas;
        }
 
                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) {
        @Override
        public synchronized File getFile(final String luid, Progress pg) {
                if (pg == null) {
index c7db5d83ce3c0f16d1525dbb591f9453571cd420..5fe28397e66936698a73dec7c64787bc08a43730 100644 (file)
@@ -32,6 +32,23 @@ class Html extends InfoText {
                return false;
        }
 
                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);
        @Override
        public URL getCanonicalUrl(URL source) {
                File txt = getTxt(source);