change config names
[fanfix.git] / src / be / nikiroo / fanfix / library / LocalLibrary.java
index 1752dc7f3e253e57586fdc0e675d380700bc31ee..ffcd8af99d0a482b27e939435fbbd6548f32550d 100644 (file)
@@ -47,8 +47,8 @@ public class LocalLibrary extends BasicLibrary {
         */
        public LocalLibrary(File baseDir) {
                this(baseDir, Instance.getConfig().getString(
-                               Config.NON_IMAGES_DOCUMENT_TYPE), Instance.getConfig()
-                               .getString(Config.IMAGES_DOCUMENT_TYPE), false);
+                               Config.FILE_FORMAT_NON_IMAGES_DOCUMENT_TYPE), Instance.getConfig()
+                               .getString(Config.FILE_FORMAT_IMAGES_DOCUMENT_TYPE), false);
        }
 
        /**
@@ -100,7 +100,7 @@ public class LocalLibrary extends BasicLibrary {
        }
 
        @Override
-       public File getFile(String luid, Progress pg) {
+       public File getFile(String luid, Progress pg) throws IOException {
                Instance.getTraceHandler().trace(
                                this.getClass().getSimpleName() + ": get file for " + luid);
 
@@ -122,7 +122,7 @@ public class LocalLibrary extends BasicLibrary {
        }
 
        @Override
-       public Image getCover(String luid) {
+       public Image getCover(String luid) throws IOException {
                MetaData meta = getInfo(luid);
                if (meta != null) {
                        if (meta.getCover() != null) {
@@ -255,6 +255,15 @@ public class LocalLibrary extends BasicLibrary {
 
        @Override
        public synchronized Image getCustomAuthorCover(String author) {
+               if (authorCovers == null) {
+                       authorCovers = new HashMap<String, Image>();
+               }
+
+               Image img = authorCovers.get(author);
+               if (img != null) {
+                       return img;
+               }
+
                File cover = getAuthorCoverFile(author);
                if (cover.exists()) {
                        InputStream in;
@@ -279,12 +288,12 @@ public class LocalLibrary extends BasicLibrary {
        }
 
        @Override
-       public void setSourceCover(String source, String luid) {
+       public void setSourceCover(String source, String luid) throws IOException {
                setSourceCover(source, getCover(luid));
        }
 
        @Override
-       public void setAuthorCover(String author, String luid) {
+       public void setAuthorCover(String author, String luid) throws IOException {
                setAuthorCover(author, getCover(luid));
        }
 
@@ -405,6 +414,22 @@ public class LocalLibrary extends BasicLibrary {
                return text;
        }
 
+       /**
+        * Return the default {@link OutputType} for this kind of {@link Story}.
+        * 
+        * @param imageDocument
+        *            TRUE for images document, FALSE for text documents
+        * 
+        * @return the type
+        */
+       public String getOutputType(boolean imageDocument) {
+               if (imageDocument) {
+                       return image.toString();
+               }
+
+               return text.toString();
+       }
+
        /**
         * Get the target {@link File} related to the given <tt>.info</tt>
         * {@link File} and {@link MetaData}.
@@ -491,7 +516,7 @@ public class LocalLibrary extends BasicLibrary {
        private File getAuthorCoverFile(String author) {
                File aDir = new File(baseDir, "_AUTHORS");
                String hash = StringUtils.getMd5Hash(author);
-               String ext = Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER);
+               String ext = Instance.getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER);
                return new File(aDir, hash + "." + ext.toLowerCase());
        }
 
@@ -537,7 +562,7 @@ public class LocalLibrary extends BasicLibrary {
                }
 
                String coverExt = "."
-                               + Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER)
+                               + Instance.getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER)
                                                .toLowerCase();
                File coverFile = new File(path + coverExt);
                if (!coverFile.exists()) {
@@ -614,7 +639,8 @@ public class LocalLibrary extends BasicLibrary {
                                boolean info = file != null && file.isFile()
                                                && file.getPath().toLowerCase().endsWith(".info");
                                boolean dir = file != null && file.isDirectory();
-                               return info || dir;
+                               boolean isExpandedHtml = new File(file, "index.html").isFile();
+                               return info || (dir && !isExpandedHtml);
                        }
                });