Instance: use getInstance()
authorNiki Roo <niki@nikiroo.be>
Mon, 6 Apr 2020 11:14:01 +0000 (13:14 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 6 Apr 2020 11:14:01 +0000 (13:14 +0200)
58 files changed:
src/be/nikiroo/fanfix/DataLoader.java
src/be/nikiroo/fanfix/Instance.java
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/VersionCheck.java
src/be/nikiroo/fanfix/library/BasicLibrary.java
src/be/nikiroo/fanfix/library/CacheLibrary.java
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
src/be/nikiroo/fanfix/output/BasicOutput.java
src/be/nikiroo/fanfix/output/Cbz.java
src/be/nikiroo/fanfix/output/Epub.java
src/be/nikiroo/fanfix/output/Html.java
src/be/nikiroo/fanfix/output/InfoCover.java
src/be/nikiroo/fanfix/output/InfoText.java
src/be/nikiroo/fanfix/output/LaTeX.java
src/be/nikiroo/fanfix/output/Text.java
src/be/nikiroo/fanfix/reader/BasicReader.java
src/be/nikiroo/fanfix/reader/cli/CliReader.java
src/be/nikiroo/fanfix/reader/tui/TuiReader.java
src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java
src/be/nikiroo/fanfix/reader/tui/TuiReaderMainWindow.java
src/be/nikiroo/fanfix/reader/tui/TuiReaderOptionWindow.java
src/be/nikiroo/fanfix/reader/ui/GuiReader.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderCoverImager.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderNavBar.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderSearchAction.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderSearchFrame.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderViewerPanel.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderViewerTextOutput.java
src/be/nikiroo/fanfix/searchable/BasicSearchable.java
src/be/nikiroo/fanfix/searchable/Fanfiction.java
src/be/nikiroo/fanfix/searchable/MangaLel.java
src/be/nikiroo/fanfix/supported/BasicSupport.java
src/be/nikiroo/fanfix/supported/BasicSupportHelper.java
src/be/nikiroo/fanfix/supported/BasicSupportImages.java
src/be/nikiroo/fanfix/supported/BasicSupportPara.java
src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java
src/be/nikiroo/fanfix/supported/Cbz.java
src/be/nikiroo/fanfix/supported/E621.java
src/be/nikiroo/fanfix/supported/EHentai.java
src/be/nikiroo/fanfix/supported/Epub.java
src/be/nikiroo/fanfix/supported/Fanfiction.java
src/be/nikiroo/fanfix/supported/Fimfiction.java
src/be/nikiroo/fanfix/supported/FimfictionApi.java
src/be/nikiroo/fanfix/supported/Html.java
src/be/nikiroo/fanfix/supported/InfoReader.java
src/be/nikiroo/fanfix/supported/MangaHub.java
src/be/nikiroo/fanfix/supported/MangaLel.java
src/be/nikiroo/fanfix/supported/SupportType.java
src/be/nikiroo/fanfix/supported/Text.java
src/be/nikiroo/fanfix/supported/YiffStar.java
src/be/nikiroo/fanfix/test/BasicSupportDeprecatedTest.java
src/be/nikiroo/fanfix/test/BasicSupportUtilitiesTest.java
src/be/nikiroo/fanfix/test/ConversionTest.java
src/be/nikiroo/fanfix/test/Test.java

index 3e0e7704e8e93068d93b7454a25e7f5fffb311f1..901e8da4c13d8a338cccf2945be17a52adef5abd 100644 (file)
@@ -314,11 +314,10 @@ public class DataLoader {
                        throws IOException {
                String format;
                if (cover) {
-                       format = Instance.getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER)
-                                       .toLowerCase();
+                       format = Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase();
                } else {
-                       format = Instance.getConfig()
-                                       .getString(Config.FILE_FORMAT_IMAGE_FORMAT_CONTENT).toLowerCase();
+                       format = Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_CONTENT)
+                                       .toLowerCase();
                }
                saveAsImage(img, new File(target.toString() + "." + format), format);
        }
index 561e2f685218442c05f98187df6738afc779ced2..f48d05b7d4cd84994eeb7e5e238018e99317afbd 100644 (file)
@@ -29,55 +29,83 @@ import be.nikiroo.utils.resources.Bundles;
  * @author niki
  */
 public class Instance {
-       private static ConfigBundle config;
-       private static UiConfigBundle uiconfig;
-       private static StringIdBundle trans;
-       private static DataLoader cache;
-       private static StringIdGuiBundle transGui;
-       private static BasicLibrary lib;
-       private static File coverDir;
-       private static File readerTmp;
-       private static File remoteDir;
-       private static String configDir;
-       private static TraceHandler tracer;
-       private static TempFiles tempFiles;
-
-       private static boolean init;
+       static private Instance instance;
+       static private Object instancelock = new Object();
+
+       private ConfigBundle config;
+       private UiConfigBundle uiconfig;
+       private StringIdBundle trans;
+       private DataLoader cache;
+       private StringIdGuiBundle transGui;
+       private BasicLibrary lib;
+       private File coverDir;
+       private File readerTmp;
+       private File remoteDir;
+       private String configDir;
+       private TraceHandler tracer;
+       private TempFiles tempFiles;
 
        /**
         * Initialise the instance -- if already initialised, nothing will happen.
         * <p>
-        * Before calling this method, you may call
-        * {@link Bundles#setDirectory(String)} if wanted.
+        * Before calling this method, you may call {@link Bundles#setDirectory(String)}
+        * if wanted.
         */
        static public void init() {
                init(false);
        }
 
        /**
-        * Initialise the instance -- if already initialised, nothing will happen
-        * unless you pass TRUE to <tt>force</tt>.
+        * Initialise the instance -- if already initialised, nothing will happen unless
+        * you pass TRUE to <tt>force</tt>.
         * <p>
-        * Before calling this method, you may call
-        * {@link Bundles#setDirectory(String)} if wanted.
+        * Before calling this method, you may call {@link Bundles#setDirectory(String)}
+        * if wanted.
         * <p>
-        * Note: forcing the initialisation can be dangerous, so make sure to only
-        * make it under controlled circumstances -- for instance, at the start of
-        * the program, you could call {@link Instance#init()}, change some settings
-        * because you want to force those settings (it will also forbid users to
-        * change them!) and then call {@link Instance#init(boolean)} with
-        * <tt>force</tt> set to TRUE.
+        * Note: forcing the initialisation can be dangerous, so make sure to only make
+        * it under controlled circumstances -- for instance, at the start of the
+        * program, you could call {@link Instance#init()}, change some settings because
+        * you want to force those settings (it will also forbid users to change them!)
+        * and then call {@link Instance#init(boolean)} with <tt>force</tt> set to TRUE.
         * 
-        * @param force
-        *            force the initialisation even if already initialised
+        * @param force force the initialisation even if already initialised
         */
        static public void init(boolean force) {
-               if (init && !force) {
-                       return;
+               synchronized (instancelock) {
+                       if (instance == null || force) {
+                               instance = new Instance();
+                       }
                }
 
-               init = true;
+       }
+
+       /**
+        * Force-initialise the {@link Instance} to a known value.
+        * <p>
+        * Usually for DEBUG/Test purposes.
+        * 
+        * @param instance the actual Instance to use
+        */
+       static public void init(Instance instance) {
+               Instance.instance = instance;
+       }
+
+       /**
+        * The (mostly unique) instance of this {@link Instance}.
+        * 
+        * @return the (mostly unique) instance
+        */
+       public static Instance getInstance() {
+               return instance;
+       }
 
+       /**
+        * Actually initialise the instance.
+        * <p>
+        * Before calling this method, you may call {@link Bundles#setDirectory(String)}
+        * if wanted.
+        */
+       protected Instance() {
                // Before we can configure it:
                Boolean debug = checkEnv("DEBUG");
                boolean trace = debug != null && debug;
@@ -93,12 +121,12 @@ public class Instance {
                createConfigs(configDir, false);
 
                // Proxy support
-               Proxy.use(Instance.getConfig().getString(Config.NETWORK_PROXY));
+               Proxy.use(config.getString(Config.NETWORK_PROXY));
 
                // update tracer:
                if (debug == null) {
-                       debug = Instance.getConfig().getBoolean(Config.DEBUG_ERR, false);
-                       trace = Instance.getConfig().getBoolean(Config.DEBUG_TRACE, false);
+                       debug = config.getBoolean(Config.DEBUG_ERR, false);
+                       trace = config.getBoolean(Config.DEBUG_TRACE, false);
                }
 
                tracer = new TraceHandler(true, debug, trace);
@@ -120,19 +148,16 @@ public class Instance {
                        int hoursLarge = config.getInteger(Config.CACHE_MAX_TIME_STABLE, 0);
                        cache = new DataLoader(tmp, ua, hours, hoursLarge);
                } catch (IOException e) {
-                       tracer.error(new IOException(
-                                       "Cannot create cache (will continue without cache)", e));
+                       tracer.error(new IOException("Cannot create cache (will continue without cache)", e));
                        cache = new DataLoader(ua);
                }
 
                cache.setTraceHandler(tracer);
 
                // readerTmp / coverDir
-               readerTmp = getFile(UiConfig.CACHE_DIR_LOCAL_READER, new File(
-                               configDir, "tmp-reader"));
+               readerTmp = getFile(UiConfig.CACHE_DIR_LOCAL_READER, new File(configDir, "tmp-reader"));
 
-               coverDir = getFile(Config.DEFAULT_COVERS_DIR, new File(configDir,
-                               "covers"));
+               coverDir = getFile(Config.DEFAULT_COVERS_DIR, new File(configDir, "covers"));
                coverDir.mkdirs();
 
                try {
@@ -149,22 +174,21 @@ public class Instance {
         * 
         * @return the traces handler (never NULL)
         */
-       public static TraceHandler getTraceHandler() {
+       public TraceHandler getTraceHandler() {
                return tracer;
        }
 
        /**
         * The traces handler for this {@link Cache}.
         * 
-        * @param tracer
-        *            the new traces handler or NULL
+        * @param tracer the new traces handler or NULL
         */
-       public static void setTraceHandler(TraceHandler tracer) {
+       public void setTraceHandler(TraceHandler tracer) {
                if (tracer == null) {
                        tracer = new TraceHandler(false, false, false);
                }
 
-               Instance.tracer = tracer;
+               this.tracer = tracer;
                cache.setTraceHandler(tracer);
        }
 
@@ -173,7 +197,7 @@ public class Instance {
         * 
         * @return the configuration service
         */
-       public static ConfigBundle getConfig() {
+       public ConfigBundle getConfig() {
                return config;
        }
 
@@ -182,17 +206,16 @@ public class Instance {
         * 
         * @return the configuration service
         */
-       public static UiConfigBundle getUiConfig() {
+       public UiConfigBundle getUiConfig() {
                return uiconfig;
        }
 
        /**
         * Reset the configuration.
         * 
-        * @param resetTrans
-        *            also reset the translation files
+        * @param resetTrans also reset the translation files
         */
-       public static void resetConfig(boolean resetTrans) {
+       public void resetConfig(boolean resetTrans) {
                String dir = Bundles.getDirectory();
                Bundles.setDirectory(null);
                try {
@@ -227,7 +250,7 @@ public class Instance {
         * 
         * @return the {@link DataLoader}
         */
-       public static DataLoader getCache() {
+       public DataLoader getCache() {
                return cache;
        }
 
@@ -238,7 +261,7 @@ public class Instance {
         * 
         * @return the {link StringIdBundle}
         */
-       public static StringIdBundle getTrans() {
+       public StringIdBundle getTrans() {
                return trans;
        }
 
@@ -249,7 +272,7 @@ public class Instance {
         * 
         * @return the {link StringIdGuiBundle}
         */
-       public static StringIdGuiBundle getTransGui() {
+       public StringIdGuiBundle getTransGui() {
                return transGui;
        }
 
@@ -258,7 +281,7 @@ public class Instance {
         * 
         * @return the {@link LocalLibrary}
         */
-       public static BasicLibrary getLibrary() {
+       public BasicLibrary getLibrary() {
                if (lib == null) {
                        throw new NullPointerException("We don't have a library to return");
                }
@@ -271,7 +294,7 @@ public class Instance {
         * 
         * @return the default covers directory
         */
-       public static File getCoverDir() {
+       public File getCoverDir() {
                return coverDir;
        }
 
@@ -280,7 +303,7 @@ public class Instance {
         * 
         * @return the directory
         */
-       public static File getReaderDir() {
+       public File getReaderDir() {
                return readerTmp;
        }
 
@@ -288,12 +311,11 @@ public class Instance {
         * Return the directory where to store temporary files for the remote
         * {@link LocalLibrary}.
         * 
-        * @param host
-        *            the remote for this host
+        * @param host the remote for this host
         * 
         * @return the directory
         */
-       public static File getRemoteDir(String host) {
+       public File getRemoteDir(String host) {
                return getRemoteDir(remoteDir, host);
        }
 
@@ -301,14 +323,12 @@ public class Instance {
         * Return the directory where to store temporary files for the remote
         * {@link LocalLibrary}.
         * 
-        * @param remoteDir
-        *            the base remote directory
-        * @param host
-        *            the remote for this host
+        * @param remoteDir the base remote directory
+        * @param host      the remote for this host
         * 
         * @return the directory
         */
-       private static File getRemoteDir(File remoteDir, String host) {
+       private File getRemoteDir(File remoteDir, String host) {
                remoteDir.mkdirs();
 
                if (host != null) {
@@ -323,15 +343,12 @@ public class Instance {
         * 
         * @return TRUE if we need to
         */
-       public static boolean isVersionCheckNeeded() {
+       public boolean isVersionCheckNeeded() {
                try {
-                       long wait = config.getInteger(Config.NETWORK_UPDATE_INTERVAL, 0)
-                                       * 24 * 60 * 60 * 1000;
+                       long wait = config.getInteger(Config.NETWORK_UPDATE_INTERVAL, 0) * 24 * 60 * 60 * 1000;
                        if (wait >= 0) {
-                               String lastUpString = IOUtils.readSmallFile(new File(configDir,
-                                               "LAST_UPDATE"));
-                               long delay = new Date().getTime()
-                                               - Long.parseLong(lastUpString);
+                               String lastUpString = IOUtils.readSmallFile(new File(configDir, "LAST_UPDATE"));
+                               long delay = new Date().getTime() - Long.parseLong(lastUpString);
                                if (delay > wait) {
                                        return true;
                                }
@@ -349,10 +366,9 @@ public class Instance {
        /**
         * Notify that we checked for a new version of Fanfix.
         */
-       public static void setVersionChecked() {
+       public void setVersionChecked() {
                try {
-                       IOUtils.writeSmallFile(new File(configDir), "LAST_UPDATE",
-                                       Long.toString(new Date().getTime()));
+                       IOUtils.writeSmallFile(new File(configDir), "LAST_UPDATE", Long.toString(new Date().getTime()));
                } catch (IOException e) {
                        tracer.error(e);
                }
@@ -365,18 +381,18 @@ public class Instance {
         * 
         * @return the facility
         */
-       public static TempFiles getTempFiles() {
+       public TempFiles getTempFiles() {
                return tempFiles;
        }
 
        /**
-        * The configuration directory (will check, in order of preference, the
-        * system properties, the environment and then defaults to
+        * The configuration directory (will check, in order of preference, the system
+        * properties, the environment and then defaults to
         * {@link Instance#getHome()}/.fanfix).
         * 
         * @return the config directory
         */
-       private static String getConfigDir() {
+       private String getConfigDir() {
                String configDir = System.getProperty("CONFIG_DIR");
 
                if (configDir == null) {
@@ -395,13 +411,11 @@ public class Instance {
         * {@link Instance#uiconfig}, {@link Instance#trans} and
         * {@link Instance#transGui}).
         * 
-        * @param configDir
-        *            the directory where to find the configuration files
-        * @param refresh
-        *            TRUE to reset the configuration files from the default
-        *            included ones
+        * @param configDir the directory where to find the configuration files
+        * @param refresh   TRUE to reset the configuration files from the default
+        *                  included ones
         */
-       private static void createConfigs(String configDir, boolean refresh) {
+       private void createConfigs(String configDir, boolean refresh) {
                if (!refresh) {
                        Bundles.setDirectory(configDir);
                }
@@ -443,16 +457,14 @@ public class Instance {
        /**
         * Create the default library as specified by the config.
         * 
-        * @param remoteDir
-        *            the base remote directory if needed
+        * @param remoteDir the base remote directory if needed
         * 
         * @return the default {@link BasicLibrary}
         */
-       private static BasicLibrary createDefaultLibrary(File remoteDir) {
+       private BasicLibrary createDefaultLibrary(File remoteDir) {
                BasicLibrary lib = null;
 
-               boolean useRemote = config.getBoolean(Config.REMOTE_LIBRARY_ENABLED,
-                               false);
+               boolean useRemote = config.getBoolean(Config.REMOTE_LIBRARY_ENABLED, false);
 
                if (useRemote) {
                        String host = null;
@@ -464,11 +476,9 @@ public class Instance {
 
                                tracer.trace("Selecting remote library " + host + ":" + port);
                                lib = new RemoteLibrary(key, host, port);
-                               lib = new CacheLibrary(getRemoteDir(remoteDir, host), lib);
+                               lib = new CacheLibrary(getRemoteDir(remoteDir, host), lib, uiconfig);
                        } catch (Exception e) {
-                               tracer.error(new IOException(
-                                               "Cannot create remote library for: " + host + ":"
-                                                               + port, e));
+                               tracer.error(new IOException("Cannot create remote library for: " + host + ":" + port, e));
                        }
                } else {
                        String libDir = System.getenv("BOOKS_DIR");
@@ -479,11 +489,9 @@ public class Instance {
                                }
                        }
                        try {
-                               lib = new LocalLibrary(getFile(libDir));
+                               lib = new LocalLibrary(getFile(libDir), config);
                        } catch (Exception e) {
-                               tracer.error(new IOException(
-                                               "Cannot create library for directory: "
-                                                               + getFile(libDir), e));
+                               tracer.error(new IOException("Cannot create library for directory: " + getFile(libDir), e));
                        }
                }
 
@@ -493,9 +501,11 @@ public class Instance {
        /**
         * Return a path, but support the special $HOME variable.
         * 
-        * @return the path
+        * @param id  the key for the path, which may contain "$HOME"
+        * @param def the default value if none
+        * @return the path, with expanded "$HOME" if needed
         */
-       private static File getFile(Config id, File def) {
+       protected File getFile(Config id, File def) {
                String path = config.getString(id, def.getPath());
                return getFile(path);
        }
@@ -503,9 +513,11 @@ public class Instance {
        /**
         * Return a path, but support the special $HOME variable.
         * 
-        * @return the path
+        * @param id  the key for the path, which may contain "$HOME"
+        * @param def the default value if none
+        * @return the path, with expanded "$HOME" if needed
         */
-       private static File getFile(UiConfig id, File def) {
+       protected File getFile(UiConfig id, File def) {
                String path = uiconfig.getString(id, def.getPath());
                return getFile(path);
        }
@@ -513,9 +525,10 @@ public class Instance {
        /**
         * Return a path, but support the special $HOME variable.
         * 
-        * @return the path
+        * @param path the path, which may contain "$HOME"
+        * @return the path, with expanded "$HOME" if needed
         */
-       private static File getFile(String path) {
+       protected File getFile(String path) {
                File file = null;
                if (path != null && !path.isEmpty()) {
                        path = path.replace('/', File.separatorChar);
@@ -534,12 +547,12 @@ public class Instance {
         * properties.
         * <p>
         * The environment variable is tested first. Then, the custom property
-        * "fanfix.home" is tried, followed by the usual "user.home" then
-        * "java.io.tmp" if nothing else is found.
+        * "fanfix.home" is tried, followed by the usual "user.home" then "java.io.tmp"
+        * if nothing else is found.
         * 
         * @return the home
         */
-       private static String getHome() {
+       protected String getHome() {
                String home = System.getenv("FANFIX_DIR");
                if (home != null && new File(home).isFile()) {
                        home = null;
@@ -578,12 +591,11 @@ public class Instance {
         * 
         * @return the language
         */
-       private static String getLang() {
+       protected String getLang() {
                String lang = config.getString(Config.LANG);
 
                if (lang == null || lang.isEmpty()) {
-                       if (System.getenv("LANG") != null
-                                       && !System.getenv("LANG").isEmpty()) {
+                       if (System.getenv("LANG") != null && !System.getenv("LANG").isEmpty()) {
                                lang = System.getenv("LANG");
                        }
                }
@@ -598,17 +610,15 @@ public class Instance {
        /**
         * Check that the given environment variable is "enabled".
         * 
-        * @param key
-        *            the variable to check
+        * @param key the variable to check
         * 
         * @return TRUE if it is
         */
-       private static Boolean checkEnv(String key) {
+       protected Boolean checkEnv(String key) {
                String value = System.getenv(key);
                if (value != null) {
                        value = value.trim().toLowerCase();
-                       if ("yes".equals(value) || "true".equals(value)
-                                       || "on".equals(value) || "1".equals(value)
+                       if ("yes".equals(value) || "true".equals(value) || "on".equals(value) || "1".equals(value)
                                        || "y".equals(value)) {
                                return true;
                        }
index 6f77e443bebdab359bbf2589f2e89cb35c925f4d..961816a3f63e96afc4611489e5d83d85c9e2898a 100644 (file)
@@ -10,9 +10,7 @@ import java.util.List;
 import javax.net.ssl.SSLException;
 
 import be.nikiroo.fanfix.bundles.Config;
-import be.nikiroo.fanfix.bundles.ConfigBundle;
 import be.nikiroo.fanfix.bundles.StringId;
-import be.nikiroo.fanfix.bundles.StringIdBundle;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
@@ -31,8 +29,6 @@ import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
-import be.nikiroo.utils.resources.Bundles;
-import be.nikiroo.utils.resources.TransBundle;
 import be.nikiroo.utils.serial.server.ServerObject;
 
 /**
@@ -126,9 +122,8 @@ public class Main {
                                                action = MainAction.valueOf(args[i].substring(2)
                                                                .toUpperCase().replace("-", "_"));
                                        } catch (Exception e) {
-                                               Instance.getTraceHandler().error(
-                                                               new IllegalArgumentException("Unknown action: "
-                                                                               + args[i], e));
+                                               Instance.getInstance().getTraceHandler()
+                                                               .error(new IllegalArgumentException("Unknown action: " + args[i], e));
                                                exitCode = 255;
                                        }
                                }
@@ -229,15 +224,13 @@ public class Main {
                                        searchOn = SupportType.valueOfAllOkUC(args[i]);
 
                                        if (searchOn == null) {
-                                               Instance.getTraceHandler().error(
-                                                               "Website not known: <" + args[i] + ">");
+                                               Instance.getInstance().getTraceHandler().error("Website not known: <" + args[i] + ">");
                                                exitCode = 41;
                                                break;
                                        }
 
                                        if (BasicSearchable.getSearchable(searchOn) == null) {
-                                               Instance.getTraceHandler().error(
-                                                               "Website not supported: " + searchOn);
+                                               Instance.getInstance().getTraceHandler().error("Website not supported: " + searchOn);
                                                exitCode = 42;
                                                break;
                                        }
@@ -272,14 +265,12 @@ public class Main {
                                        searchOn = SupportType.valueOfAllOkUC(args[i]);
 
                                        if (searchOn == null) {
-                                               Instance.getTraceHandler().error(
-                                                               "Website not known: <" + args[i] + ">");
+                                               Instance.getInstance().getTraceHandler().error("Website not known: <" + args[i] + ">");
                                                exitCode = 255;
                                        }
 
                                        if (BasicSearchable.getSearchable(searchOn) == null) {
-                                               Instance.getTraceHandler().error(
-                                                               "Website not supported: " + searchOn);
+                                               Instance.getInstance().getTraceHandler().error("Website not supported: " + searchOn);
                                                exitCode = 255;
                                        }
                                } else if (page == null && item == null) {
@@ -292,8 +283,7 @@ public class Main {
                                                        int index = Integer.parseInt(args[i]);
                                                        tags.add(index);
                                                } catch (NumberFormatException e) {
-                                                       Instance.getTraceHandler().error(
-                                                                       "Invalid tag index: " + args[i]);
+                                                       Instance.getInstance().getTraceHandler().error("Invalid tag index: " + args[i]);
                                                        exitCode = 255;
                                                }
                                        }
@@ -349,7 +339,8 @@ public class Main {
                                        port = Integer.parseInt(args[i]);
 
                                        BasicLibrary lib = new RemoteLibrary(key, host, port);
-                                       lib = new CacheLibrary(Instance.getRemoteDir(host), lib);
+                                       lib = new CacheLibrary(Instance.getInstance().getRemoteDir(host), lib,
+                                                       Instance.getInstance().getUiConfig());
 
                                        BasicReader.setDefaultLibrary(lib);
 
@@ -423,9 +414,7 @@ public class Main {
                                break;
                        case LIST:
                                if (BasicReader.getReader() == null) {
-                                       Instance.getTraceHandler()
-                                                       .error(new Exception(
-                                                                       "No reader type has been configured"));
+                                       Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured"));
                                        exitCode = 10;
                                        break;
                                }
@@ -433,33 +422,31 @@ public class Main {
                                break;
                        case SET_SOURCE:
                                try {
-                                       Instance.getLibrary().changeSource(luid, sourceString, pg);
+                                       Instance.getInstance().getLibrary().changeSource(luid, sourceString, pg);
                                } catch (IOException e1) {
-                                       Instance.getTraceHandler().error(e1);
+                                       Instance.getInstance().getTraceHandler().error(e1);
                                        exitCode = 21;
                                }
                                break;
                        case SET_TITLE:
                                try {
-                                       Instance.getLibrary().changeTitle(luid, titleString, pg);
+                                       Instance.getInstance().getLibrary().changeTitle(luid, titleString, pg);
                                } catch (IOException e1) {
-                                       Instance.getTraceHandler().error(e1);
+                                       Instance.getInstance().getTraceHandler().error(e1);
                                        exitCode = 22;
                                }
                                break;
                        case SET_AUTHOR:
                                try {
-                                       Instance.getLibrary().changeAuthor(luid, authorString, pg);
+                                       Instance.getInstance().getLibrary().changeAuthor(luid, authorString, pg);
                                } catch (IOException e1) {
-                                       Instance.getTraceHandler().error(e1);
+                                       Instance.getInstance().getTraceHandler().error(e1);
                                        exitCode = 23;
                                }
                                break;
                        case READ:
                                if (BasicReader.getReader() == null) {
-                                       Instance.getTraceHandler()
-                                                       .error(new Exception(
-                                                                       "No reader type has been configured"));
+                                       Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured"));
                                        exitCode = 10;
                                        break;
                                }
@@ -467,9 +454,7 @@ public class Main {
                                break;
                        case READ_URL:
                                if (BasicReader.getReader() == null) {
-                                       Instance.getTraceHandler()
-                                                       .error(new Exception(
-                                                                       "No reader type has been configured"));
+                                       Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured"));
                                        exitCode = 10;
                                        break;
                                }
@@ -478,22 +463,20 @@ public class Main {
                        case SEARCH:
                                page = page == null ? 1 : page;
                                if (page < 0) {
-                                       Instance.getTraceHandler().error("Incorrect page number");
+                                       Instance.getInstance().getTraceHandler().error("Incorrect page number");
                                        exitCode = 255;
                                        break;
                                }
 
                                item = item == null ? 0 : item;
                                if (item < 0) {
-                                       Instance.getTraceHandler().error("Incorrect item number");
+                                       Instance.getInstance().getTraceHandler().error("Incorrect item number");
                                        exitCode = 255;
                                        break;
                                }
 
                                if (BasicReader.getReader() == null) {
-                                       Instance.getTraceHandler()
-                                                       .error(new Exception(
-                                                                       "No reader type has been configured"));
+                                       Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured"));
                                        exitCode = 10;
                                        break;
                                }
@@ -509,7 +492,7 @@ public class Main {
                                                exitCode = 255;
                                        }
                                } catch (IOException e1) {
-                                       Instance.getTraceHandler().error(e1);
+                                       Instance.getInstance().getTraceHandler().error(e1);
                                        exitCode = 20;
                                }
 
@@ -522,22 +505,20 @@ public class Main {
 
                                page = page == null ? 1 : page;
                                if (page < 0) {
-                                       Instance.getTraceHandler().error("Incorrect page number");
+                                       Instance.getInstance().getTraceHandler().error("Incorrect page number");
                                        exitCode = 255;
                                        break;
                                }
 
                                item = item == null ? 0 : item;
                                if (item < 0) {
-                                       Instance.getTraceHandler().error("Incorrect item number");
+                                       Instance.getInstance().getTraceHandler().error("Incorrect item number");
                                        exitCode = 255;
                                        break;
                                }
 
                                if (BasicReader.getReader() == null) {
-                                       Instance.getTraceHandler()
-                                                       .error(new Exception(
-                                                                       "No reader type has been configured"));
+                                       Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured"));
                                        exitCode = 10;
                                        break;
                                }
@@ -546,7 +527,7 @@ public class Main {
                                        BasicReader.getReader().searchTag(searchOn, page, item,
                                                        true, tags.toArray(new Integer[] {}));
                                } catch (IOException e1) {
-                                       Instance.getTraceHandler().error(e1);
+                                       Instance.getInstance().getTraceHandler().error(e1);
                                }
 
                                break;
@@ -567,22 +548,20 @@ public class Main {
                                break;
                        case START:
                                if (BasicReader.getReader() == null) {
-                                       Instance.getTraceHandler()
-                                                       .error(new Exception(
-                                                                       "No reader type has been configured"));
+                                       Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured"));
                                        exitCode = 10;
                                        break;
                                }
                                try {
                                        BasicReader.getReader().browse(null);
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                        exitCode = 66;
                                }
                                break;
                        case SERVER:
-                               key = Instance.getConfig().getString(Config.SERVER_KEY);
-                               port = Instance.getConfig().getInteger(Config.SERVER_PORT);
+                               key = Instance.getInstance().getConfig().getString(Config.SERVER_KEY);
+                               port = Instance.getInstance().getConfig().getInteger(Config.SERVER_PORT);
                                if (port == null) {
                                        System.err.println("No port configured in the config file");
                                        exitCode = 15;
@@ -590,18 +569,18 @@ public class Main {
                                }
                                try {
                                        ServerObject server = new RemoteLibraryServer(key, port);
-                                       server.setTraceHandler(Instance.getTraceHandler());
+                                       server.setTraceHandler(Instance.getInstance().getTraceHandler());
                                        server.run();
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                }
                                return;
                        case STOP_SERVER:
                                // Can be given via "--remote XX XX XX"
                                if (key == null)
-                                       key = Instance.getConfig().getString(Config.SERVER_KEY);
+                                       key = Instance.getInstance().getConfig().getString(Config.SERVER_KEY);
                                if (port == null)
-                                       port = Instance.getConfig().getInteger(Config.SERVER_PORT);
+                                       port = Instance.getInstance().getConfig().getInteger(Config.SERVER_PORT);
 
                                if (port == null) {
                                        System.err.println("No port given nor configured in the config file");
@@ -611,11 +590,11 @@ public class Main {
                                try {
                                        new RemoteLibrary(key, host, port).exit();
                                } catch (SSLException e) {
-                                       Instance.getTraceHandler().error(
+                                       Instance.getInstance().getTraceHandler().error(
                                                        "Bad access key for remote library");
                                        exitCode = 43;
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                        exitCode = 44;
                                }
 
@@ -627,11 +606,9 @@ public class Main {
                }
 
                try {
-                       Instance.getTempFiles().close();
+                       Instance.getInstance().getTempFiles().close();
                } catch (IOException e) {
-                       Instance.getTraceHandler()
-                                       .error(new IOException(
-                                                       "Cannot dispose of the temporary files", e));
+                       Instance.getInstance().getTraceHandler().error(new IOException("Cannot dispose of the temporary files", e));
                }
 
                if (exitCode == 255) {
@@ -653,12 +630,10 @@ public class Main {
         */
        public static int imprt(String urlString, Progress pg) {
                try {
-                       MetaData meta = Instance.getLibrary().imprt(
-                                       BasicReader.getUrl(urlString), pg);
-                       System.out.println(meta.getLuid() + ": \"" + meta.getTitle()
-                                       + "\" imported.");
+                       MetaData meta = Instance.getInstance().getLibrary().imprt(BasicReader.getUrl(urlString), pg);
+                       System.out.println(meta.getLuid() + ": \"" + meta.getTitle() + "\" imported.");
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                        return 1;
                }
 
@@ -684,15 +659,14 @@ public class Main {
                        Progress pg) {
                OutputType type = OutputType.valueOfNullOkUC(typeString, null);
                if (type == null) {
-                       Instance.getTraceHandler().error(
-                                       new Exception(trans(StringId.OUTPUT_DESC, typeString)));
+                       Instance.getInstance().getTraceHandler().error(new Exception(trans(StringId.OUTPUT_DESC, typeString)));
                        return 1;
                }
 
                try {
-                       Instance.getLibrary().export(luid, type, target, pg);
+                       Instance.getInstance().getLibrary().export(luid, type, target, pg);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                        return 4;
                }
 
@@ -714,7 +688,7 @@ public class Main {
                try {
                        BasicReader.getReader().browse(source);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                        return 66;
                }
 
@@ -750,16 +724,15 @@ public class Main {
                                        reader.setChapter(Integer.parseInt(chapString));
                                        reader.read(true);
                                } catch (NumberFormatException e) {
-                                       Instance.getTraceHandler().error(
-                                                       new IOException("Chapter number cannot be parsed: "
-                                                                       + chapString, e));
+                                       Instance.getInstance().getTraceHandler()
+                                                       .error(new IOException("Chapter number cannot be parsed: " + chapString, e));
                                        return 2;
                                }
                        } else {
                                reader.read(true);
                        }
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                        return 1;
                }
 
@@ -787,7 +760,7 @@ public class Main {
                        String target, boolean infoCover, Progress pg) {
                int exitCode = 0;
 
-               Instance.getTraceHandler().trace("Convert: " + urlString);
+               Instance.getInstance().getTraceHandler().trace("Convert: " + urlString);
                String sourceName = urlString;
                try {
                        URL source = BasicReader.getUrl(urlString);
@@ -798,9 +771,8 @@ public class Main {
 
                        OutputType type = OutputType.valueOfAllOkUC(typeString, null);
                        if (type == null) {
-                               Instance.getTraceHandler().error(
-                                               new IOException(trans(StringId.ERR_BAD_OUTPUT_TYPE,
-                                                               typeString)));
+                               Instance.getInstance().getTraceHandler()
+                                               .error(new IOException(trans(StringId.ERR_BAD_OUTPUT_TYPE, typeString)));
 
                                exitCode = 2;
                        } else {
@@ -808,8 +780,7 @@ public class Main {
                                        BasicSupport support = BasicSupport.getSupport(source);
 
                                        if (support != null) {
-                                               Instance.getTraceHandler().trace(
-                                                               "Support found: " + support.getClass());
+                                               Instance.getInstance().getTraceHandler().trace("Support found: " + support.getClass());
                                                Progress pgIn = new Progress();
                                                Progress pgOut = new Progress();
                                                if (pg != null) {
@@ -821,32 +792,26 @@ public class Main {
                                                Story story = support.process(pgIn);
                                                try {
                                                        target = new File(target).getAbsolutePath();
-                                                       BasicOutput.getOutput(type, infoCover, infoCover)
-                                                                       .process(story, target, pgOut);
+                                                       BasicOutput.getOutput(type, infoCover, infoCover).process(story, target, pgOut);
                                                } catch (IOException e) {
-                                                       Instance.getTraceHandler().error(
-                                                                       new IOException(trans(StringId.ERR_SAVING,
-                                                                                       target), e));
+                                                       Instance.getInstance().getTraceHandler()
+                                                                       .error(new IOException(trans(StringId.ERR_SAVING, target), e));
                                                        exitCode = 5;
                                                }
                                        } else {
-                                               Instance.getTraceHandler().error(
-                                                               new IOException(trans(
-                                                                               StringId.ERR_NOT_SUPPORTED, source)));
+                                               Instance.getInstance().getTraceHandler()
+                                                               .error(new IOException(trans(   StringId.ERR_NOT_SUPPORTED, source)));
 
                                                exitCode = 4;
                                        }
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(
-                                                       new IOException(trans(StringId.ERR_LOADING,
-                                                                       sourceName), e));
+                                       Instance.getInstance().getTraceHandler()
+                                                       .error(new IOException(trans(StringId.ERR_LOADING, sourceName), e));
                                        exitCode = 3;
                                }
                        }
                } catch (MalformedURLException e) {
-                       Instance.getTraceHandler()
-                                       .error(new IOException(trans(StringId.ERR_BAD_URL,
-                                                       sourceName), e));
+                       Instance.getInstance().getTraceHandler().error(new IOException(trans(StringId.ERR_BAD_URL, sourceName), e));
                        exitCode = 1;
                }
 
@@ -862,7 +827,7 @@ public class Main {
         * @return the translated result
         */
        private static String trans(StringId id, Object... params) {
-               return Instance.getTrans().getString(id, params);
+               return Instance.getInstance().getTrans().getString(id, params);
        }
 
        /**
@@ -912,9 +877,8 @@ public class Main {
                        BasicReader.setDefaultReaderType(readerType);
                        return 0;
                } catch (IllegalArgumentException e) {
-                       Instance.getTraceHandler().error(
-                                       new IOException("Unknown reader type: " + readerTypeString,
-                                                       e));
+                       Instance.getInstance().getTraceHandler()
+                                       .error(new IOException("Unknown reader type: " + readerTypeString,      e));
                        return 1;
                }
        }
index 2c9a0328aca615aa982f58f68262b636e9758086..f64159abb97c3fe3236bc272710402a1e32631f7 100644 (file)
@@ -93,7 +93,7 @@ public class VersionCheck {
         * time has elapsed.
         */
        public void ok() {
-               Instance.setVersionChecked();
+               Instance.getInstance().setVersionChecked();
        }
 
        /**
@@ -107,10 +107,10 @@ public class VersionCheck {
                List<Version> newer = new ArrayList<Version>();
                Map<Version, List<String>> changes = new HashMap<Version, List<String>>();
 
-               if (Instance.isVersionCheckNeeded()) {
+               if (Instance.getInstance().isVersionCheckNeeded()) {
                        try {
                                // Prepare the URLs according to the user's language
-                               Locale lang = Instance.getTrans().getLocale();
+                               Locale lang = Instance.getInstance().getTrans().getLocale();
                                String fr = lang.getLanguage();
                                String BE = lang.getCountry().replace(".UTF8", "");
                                String urlFrBE = base.replace("${LANG}", "-" + fr + "_" + BE);
@@ -120,8 +120,7 @@ public class VersionCheck {
                                InputStream in = null;
                                for (String url : new String[] { urlFrBE, urlFr, urlDefault }) {
                                        try {
-                                               in = Instance.getCache()
-                                                               .open(new URL(url), null, false);
+                                               in = Instance.getInstance().getCache().open(new URL(url), null, false);
                                                break;
                                        } catch (IOException e) {
                                        }
@@ -162,10 +161,8 @@ public class VersionCheck {
                                        reader.close();
                                }
                        } catch (IOException e) {
-                               Instance.getTraceHandler()
-                                               .error(new IOException(
-                                                               "Cannot download latest changelist on github.com",
-                                                               e));
+                               Instance.getInstance().getTraceHandler()
+                                               .error(new IOException("Cannot download latest changelist on github.com", e));
                        }
                }
 
index 099859dcfaffed075f30b3d716b790f644a43a09..c558384d380526819f36a8dac9553b89d33517ca 100644 (file)
@@ -730,10 +730,8 @@ abstract public class BasicLibrary {
                } catch (IOException e) {
                        // We should not have not-supported files in the
                        // library
-                       Instance.getTraceHandler().error(
-                                       new IOException(String.format(
-                                                       "Cannot load file of type '%s' from library: %s",
-                                                       meta.getType(), file), e));
+                       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();
@@ -892,8 +890,7 @@ abstract public class BasicLibrary {
        public synchronized Story save(Story story, String luid, Progress pg)
                        throws IOException {
 
-               Instance.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();
@@ -913,9 +910,8 @@ abstract public class BasicLibrary {
 
                updateInfo(story.getMeta());
 
-               Instance.getTraceHandler().trace(
-                               this.getClass().getSimpleName() + ": story saved (" + luid
-                                               + ")");
+               Instance.getInstance().getTraceHandler()
+                               .trace(this.getClass().getSimpleName() + ": story saved (" + luid + ")");
 
                return story;
        }
@@ -930,14 +926,13 @@ abstract public class BasicLibrary {
         *             in case of I/O error
         */
        public synchronized void delete(String luid) throws IOException {
-               Instance.getTraceHandler().trace(
-                               this.getClass().getSimpleName() + ": deleting story " + luid);
+               Instance.getInstance().getTraceHandler().trace(this.getClass().getSimpleName() + ": deleting story " + luid);
 
                doDelete(luid);
                invalidateInfo(luid);
 
-               Instance.getTraceHandler().trace(
-                               this.getClass().getSimpleName() + ": story deleted (" + luid
+               Instance.getInstance().getTraceHandler()
+                               .trace(this.getClass().getSimpleName() + ": story deleted (" + luid
                                                + ")");
        }
 
index e8743b63cd9d18ca0ef0ba3316aa204433b4bf34..cccfedba0cfd29ec755034b9197f7a7495dd0b38 100644 (file)
@@ -7,8 +7,10 @@ import java.util.List;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.UiConfig;
+import be.nikiroo.fanfix.bundles.UiConfigBundle;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 
@@ -25,19 +27,18 @@ public class CacheLibrary extends BasicLibrary {
        /**
         * Create a cache library around the given one.
         * <p>
-        * It will return the same result, but those will be saved to disk at the
-        * same time to be fetched quicker the next time.
+        * It will return the same result, but those will be saved to disk at the same
+        * time to be fetched quicker the next time.
         * 
-        * @param cacheDir
-        *            the cache directory where to save the files to disk
-        * @param lib
-        *            the original library to wrap
+        * @param cacheDir the cache directory where to save the files to disk
+        * @param lib      the original library to wrap
+        * @param config   the configuration used to know which kind of default
+        *                 {@link OutputType} to use for images and non-images stories
         */
-       public CacheLibrary(File cacheDir, BasicLibrary lib) {
-               this.cacheLib = new LocalLibrary(cacheDir, Instance.getUiConfig()
-                               .getString(UiConfig.GUI_NON_IMAGES_DOCUMENT_TYPE), Instance
-                               .getUiConfig().getString(UiConfig.GUI_IMAGES_DOCUMENT_TYPE),
-                               true);
+       public CacheLibrary(File cacheDir, BasicLibrary lib, UiConfigBundle config) {
+               this.cacheLib = new LocalLibrary(cacheDir, //
+                               config.getString(UiConfig.GUI_NON_IMAGES_DOCUMENT_TYPE),
+                               config.getString(UiConfig.GUI_IMAGES_DOCUMENT_TYPE), true);
                this.lib = lib;
        }
 
@@ -95,7 +96,7 @@ public class CacheLibrary extends BasicLibrary {
                                updateInfo(cacheLib.getInfo(luid));
                                pgImport.done();
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
 
                        pgImport.done();
index ffcd8af99d0a482b27e939435fbbd6548f32550d..c99a0fbebefc1a2fef30d6f83d8c0d080303b5ef 100644 (file)
@@ -13,6 +13,8 @@ import java.util.Map;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
+import be.nikiroo.fanfix.bundles.ConfigBundle;
+import be.nikiroo.fanfix.bundles.UiConfigBundle;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.output.BasicOutput;
@@ -42,13 +44,14 @@ public class LocalLibrary extends BasicLibrary {
        /**
         * Create a new {@link LocalLibrary} with the given back-end directory.
         * 
-        * @param baseDir
-        *            the directory where to find the {@link Story} objects
+        * @param baseDir the directory where to find the {@link Story} objects
+        * @param config  the configuration used to know which kind of default
+        *                {@link OutputType} to use for images and non-images stories
         */
-       public LocalLibrary(File baseDir) {
-               this(baseDir, Instance.getConfig().getString(
-                               Config.FILE_FORMAT_NON_IMAGES_DOCUMENT_TYPE), Instance.getConfig()
-                               .getString(Config.FILE_FORMAT_IMAGES_DOCUMENT_TYPE), false);
+       public LocalLibrary(File baseDir, ConfigBundle config) {
+               this(baseDir, //
+                               config.getString(Config.FILE_FORMAT_NON_IMAGES_DOCUMENT_TYPE),
+                               config.getString(Config.FILE_FORMAT_IMAGES_DOCUMENT_TYPE), false);
        }
 
        /**
@@ -101,8 +104,7 @@ public class LocalLibrary extends BasicLibrary {
 
        @Override
        public File getFile(String luid, Progress pg) throws IOException {
-               Instance.getTraceHandler().trace(
-                               this.getClass().getSimpleName() + ": get file for " + luid);
+               Instance.getInstance().getTraceHandler().trace(this.getClass().getSimpleName() + ": get file for " + luid);
 
                File file = null;
                String mess = "no file found for ";
@@ -114,9 +116,8 @@ public class LocalLibrary extends BasicLibrary {
                        file = files[1];
                }
 
-               Instance.getTraceHandler().trace(
-                               this.getClass().getSimpleName() + ": " + mess + luid + " ("
-                                               + meta.getTitle() + ")");
+               Instance.getInstance().getTraceHandler()
+                               .trace(this.getClass().getSimpleName() + ": " + mess + luid + " (" + meta.getTitle() + ")");
 
                return file;
        }
@@ -137,7 +138,7 @@ public class LocalLibrary extends BasicLibrary {
                                        meta = InfoReader.readMeta(infoFile, true);
                                        return meta.getCover();
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                }
                        }
                }
@@ -205,7 +206,7 @@ public class LocalLibrary extends BasicLibrary {
                                        InfoCover.writeInfo(newDir, name, meta);
                                        relatedFile.getParentFile().delete();
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                }
                        } else {
                                relatedFile.renameTo(new File(newDir, relatedFile.getName()));
@@ -242,10 +243,8 @@ public class LocalLibrary extends BasicLibrary {
                                } catch (FileNotFoundException e) {
                                        e.printStackTrace();
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(
-                                                       new IOException(
-                                                                       "Cannot load the existing custom source cover: "
-                                                                                       + cover, e));
+                                       Instance.getInstance().getTraceHandler()
+                                                       .error(new IOException("Cannot load the existing custom source cover: " + cover, e));
                                }
                        }
                }
@@ -277,10 +276,8 @@ public class LocalLibrary extends BasicLibrary {
                        } catch (FileNotFoundException e) {
                                e.printStackTrace();
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(
-                                               new IOException(
-                                                               "Cannot load the existing custom author cover: "
-                                                                               + cover, e));
+                               Instance.getInstance().getTraceHandler()
+                                               .error(new IOException("Cannot load the existing custom author cover: " + cover, e));
                        }
                }
 
@@ -310,12 +307,12 @@ public class LocalLibrary extends BasicLibrary {
                dir.mkdirs();
                File cover = new File(dir, ".cover");
                try {
-                       Instance.getCache().saveAsImage(coverImage, cover, true);
+                       Instance.getInstance().getCache().saveAsImage(coverImage, cover, true);
                        if (sourceCovers != null) {
                                sourceCovers.put(source, coverImage);
                        }
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -331,12 +328,12 @@ public class LocalLibrary extends BasicLibrary {
                File cover = getAuthorCoverFile(author);
                cover.getParentFile().mkdirs();
                try {
-                       Instance.getCache().saveAsImage(coverImage, cover, true);
+                       Instance.getInstance().getCache().saveAsImage(coverImage, cover, true);
                        if (authorCovers != null) {
                                authorCovers.put(author, coverImage);
                        }
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -516,7 +513,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.FILE_FORMAT_IMAGE_FORMAT_COVER);
+               String ext = Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER);
                return new File(aDir, hash + "." + ext.toLowerCase());
        }
 
@@ -562,8 +559,7 @@ public class LocalLibrary extends BasicLibrary {
                }
 
                String coverExt = "."
-                               + Instance.getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER)
-                                               .toLowerCase();
+                               + Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase();
                File coverFile = new File(path + coverExt);
                if (!coverFile.exists()) {
                        coverFile = new File(path.substring(0,
@@ -675,9 +671,8 @@ public class LocalLibrary extends BasicLibrary {
                                } catch (IOException e) {
                                        // We should not have not-supported files in the
                                        // library
-                                       Instance.getTraceHandler().error(
-                                                       new IOException("Cannot load file from library: "
-                                                                       + infoFileOrSubdir, e));
+                                       Instance.getInstance().getTraceHandler()
+                                                       .error(new IOException("Cannot load file from library: " + infoFileOrSubdir, e));
                                }
                        }
 
index 69dc377c7ef64e29e818d9c009ddfaa14d652125..c2774f936e8966cb7358c30e446bd86f4242b027 100644 (file)
@@ -124,9 +124,9 @@ public class RemoteLibrary extends BasicLibrary {
 
        @Override
        public Status getStatus() {
-               Instance.getTraceHandler().trace("Getting remote lib status...");
+               Instance.getInstance().getTraceHandler().trace("Getting remote lib status...");
                Status status = getStatusDo();
-               Instance.getTraceHandler().trace("Remote lib status: " + status);
+               Instance.getInstance().getTraceHandler().trace("Remote lib status: " + status);
                return status;
        }
 
@@ -560,7 +560,7 @@ public class RemoteLibrary extends BasicLibrary {
                                @Override
                                protected void onError(Exception e) {
                                        if (!(e instanceof IOException)) {
-                                               Instance.getTraceHandler().error(e);
+                                               Instance.getInstance().getTraceHandler().error(e);
                                                return;
                                        }
 
index 1f655457c96a6eb405caef125e5accd1b021f391..4f89a1fa19263c9d4bedf513274442660d3a023f 100644 (file)
@@ -80,7 +80,7 @@ public class RemoteLibraryServer extends ServerObject {
         */
        public RemoteLibraryServer(String key, int port) throws IOException {
                super("Fanfix remote library", port, key);
-               setTraceHandler(Instance.getTraceHandler());
+               setTraceHandler(Instance.getInstance().getTraceHandler());
        }
 
        @Override
@@ -110,8 +110,7 @@ public class RemoteLibraryServer extends ServerObject {
                        }
                }
 
-               List<String> whitelist = Instance.getConfig().getList(
-                               Config.SERVER_WHITELIST);
+               List<String> whitelist = Instance.getInstance().getConfig().getList(Config.SERVER_WHITELIST);
                if (whitelist == null) {
                        whitelist = new ArrayList<String>();
                }
@@ -120,10 +119,9 @@ public class RemoteLibraryServer extends ServerObject {
                        wl = false;
                }
 
-               rw = Instance.getConfig().getBoolean(Config.SERVER_RW, rw);
+               rw = Instance.getInstance().getConfig().getBoolean(Config.SERVER_RW, rw);
                if (!subkey.isEmpty()) {
-                       List<String> allowed = Instance.getConfig().getList(
-                                       Config.SERVER_ALLOWED_SUBKEYS);
+                       List<String> allowed = Instance.getInstance().getConfig().getList(Config.SERVER_ALLOWED_SUBKEYS);
                        if (allowed.contains(subkey)) {
                                if ((subkey + "|").contains("|rw|")) {
                                        rw = true;
@@ -203,7 +201,7 @@ public class RemoteLibraryServer extends ServerObject {
                        if ("*".equals(args[0])) {
                                Progress pg = createPgForwarder(action);
 
-                               for (MetaData meta : Instance.getLibrary().getMetas(pg)) {
+                               for (MetaData meta : Instance.getInstance().getLibrary().getMetas(pg)) {
                                        MetaData light;
                                        if (meta.getCover() == null) {
                                                light = meta;
@@ -217,7 +215,7 @@ public class RemoteLibraryServer extends ServerObject {
 
                                forcePgDoneSent(pg);
                        } else {
-                               MetaData meta = Instance.getLibrary().getInfo((String) args[0]);
+                               MetaData meta = Instance.getInstance().getLibrary().getInfo((String) args[0]);
                                MetaData light;
                                if (meta.getCover() == null) {
                                        light = meta;
@@ -240,7 +238,7 @@ public class RemoteLibraryServer extends ServerObject {
 
                        return metas.toArray(new MetaData[0]);
                } else if ("GET_STORY".equals(command)) {
-                       MetaData meta = Instance.getLibrary().getInfo((String) args[0]);
+                       MetaData meta = Instance.getInstance().getLibrary().getInfo((String) args[0]);
                        if (meta == null) {
                                return null;
                        }
@@ -257,8 +255,7 @@ public class RemoteLibraryServer extends ServerObject {
                        action.send(meta);
                        action.rec();
 
-                       Story story = Instance.getLibrary()
-                                       .getStory((String) args[0], null);
+                       Story story = Instance.getInstance().getLibrary().getStory((String) args[0], null);
                        for (Object obj : breakStory(story)) {
                                action.send(obj);
                                action.rec();
@@ -280,7 +277,7 @@ public class RemoteLibraryServer extends ServerObject {
                        }
 
                        Story story = rebuildStory(list);
-                       Instance.getLibrary().save(story, (String) args[0], null);
+                       Instance.getInstance().getLibrary().save(story, (String) args[0], null);
                        return story.getMeta().getLuid();
                } else if ("IMPORT".equals(command)) {
                        if (!rw) {
@@ -289,8 +286,7 @@ public class RemoteLibraryServer extends ServerObject {
                        }
 
                        Progress pg = createPgForwarder(action);
-                       MetaData meta = Instance.getLibrary().imprt(
-                                       new URL((String) args[0]), pg);
+                       MetaData meta = Instance.getInstance().getLibrary().imprt(new URL((String) args[0]), pg);
                        forcePgDoneSent(pg);
                        return meta.getLuid();
                } else if ("DELETE_STORY".equals(command)) {
@@ -299,16 +295,14 @@ public class RemoteLibraryServer extends ServerObject {
                                                + args[0], false);
                        }
 
-                       Instance.getLibrary().delete((String) args[0]);
+                       Instance.getInstance().getLibrary().delete((String) args[0]);
                } else if ("GET_COVER".equals(command)) {
-                       return Instance.getLibrary().getCover((String) args[0]);
+                       return Instance.getInstance().getLibrary().getCover((String) args[0]);
                } else if ("GET_CUSTOM_COVER".equals(command)) {
                        if ("SOURCE".equals(args[0])) {
-                               return Instance.getLibrary().getCustomSourceCover(
-                                               (String) args[1]);
+                               return Instance.getInstance().getLibrary().getCustomSourceCover((String) args[1]);
                        } else if ("AUTHOR".equals(args[0])) {
-                               return Instance.getLibrary().getCustomAuthorCover(
-                                               (String) args[1]);
+                               return Instance.getInstance().getLibrary().getCustomAuthorCover((String) args[1]);
                        } else {
                                return null;
                        }
@@ -319,21 +313,18 @@ public class RemoteLibraryServer extends ServerObject {
                        }
 
                        if ("SOURCE".equals(args[0])) {
-                               Instance.getLibrary().setSourceCover((String) args[1],
-                                               (String) args[2]);
+                               Instance.getInstance().getLibrary().setSourceCover((String) args[1], (String) args[2]);
                        } else if ("AUTHOR".equals(args[0])) {
-                               Instance.getLibrary().setAuthorCover((String) args[1],
-                                               (String) args[2]);
+                               Instance.getInstance().getLibrary().setAuthorCover((String) args[1], (String) args[2]);
                        }
                } else if ("CHANGE_STA".equals(command)) {
                        if (!rw) {
-                               throw new RemoteLibraryException("Read-Only remote library: "
-                                               + args[0] + ", " + args[1], false);
+                               throw new RemoteLibraryException("Read-Only remote library: " + args[0] + ", " + args[1], false);
                        }
 
                        Progress pg = createPgForwarder(action);
-                       Instance.getLibrary().changeSTA((String) args[0], (String) args[1],
-                                       (String) args[2], (String) args[3], pg);
+                       Instance.getInstance().getLibrary().changeSTA((String) args[0], (String) args[1], (String) args[2],
+                                       (String) args[3], pg);
                        forcePgDoneSent(pg);
                } else if ("EXIT".equals(command)) {
                        if (!rw) {
index 15d8cc1c7c88c4b454c90c97a51f77e1740dcb5f..41634faaddbceabc89b4ad1be016c88bbaedc0de 100644 (file)
@@ -63,10 +63,10 @@ public abstract class BasicOutput {
                        StringId id = longDesc ? StringId.OUTPUT_DESC
                                        : StringId.OUTPUT_DESC_SHORT;
 
-                       String desc = Instance.getTrans().getStringX(id, this.name());
+                       String desc = Instance.getInstance().getTrans().getStringX(id, this.name());
 
                        if (desc == null) {
-                               desc = Instance.getTrans().getString(id, this.toString());
+                               desc = Instance.getInstance().getTrans().getString(id, this.toString());
                        }
 
                        if (desc == null || desc.isEmpty()) {
index 3d9008299052451539d1e99db77c426d8e1bebd0..ee671e779668483bc0efd82038afa898905c3cee 100644 (file)
@@ -23,7 +23,7 @@ class Cbz extends BasicOutput {
 
                File target = new File(targetDir, targetName);
 
-               dir = Instance.getTempFiles().createTempDir("fanfic-reader-cbz-dir");
+               dir = Instance.getInstance().getTempFiles().createTempDir("fanfic-reader-cbz-dir");
                try {
                        // will also save the images! (except the cover -> false)
                        BasicOutput
index b7401d3922b2c182fd2ff1840ff1182986bd54cc..fc2dc8c982127210c308d6a9dc70a20b667162eb 100644 (file)
@@ -36,7 +36,7 @@ class Epub extends BasicOutput {
                String targetNameOrig = targetName;
                targetName += getDefaultExtension(false);
 
-               tmpDir = Instance.getTempFiles().createTempDir("fanfic-reader-epub");
+               tmpDir = Instance.getInstance().getTempFiles().createTempDir("fanfic-reader-epub");
                tmpDir.delete();
 
                if (!tmpDir.mkdir()) {
@@ -137,10 +137,9 @@ class Epub extends BasicOutput {
                if (story.getMeta() != null && story.getMeta().getCover() != null) {
                        File file = new File(images, "cover");
                        try {
-                               Instance.getCache().saveAsImage(story.getMeta().getCover(),
-                                               file, true);
+                               Instance.getInstance().getCache().saveAsImage(story.getMeta().getCover(), file, true);
                        } catch (Exception e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
 
@@ -246,8 +245,7 @@ class Epub extends BasicOutput {
                        break;
                case IMAGE:
                        File file = new File(images, getCurrentImageBestName(false));
-                       Instance.getCache().saveAsImage(para.getContentImage(), file,
-                                       nextParaIsCover);
+                       Instance.getInstance().getCache().saveAsImage(para.getContentImage(), file, nextParaIsCover);
                        writer.write("                  <img alt='page image' class='page-image' src='images/"
                                        + getCurrentImageBestName(false) + "'/>");
                        break;
@@ -358,11 +356,10 @@ class Epub extends BasicOutput {
        private void generateNcx(Chapter chap, StringBuilder builder, int navPoint) {
                String name;
                if (chap.getName() != null && !chap.getName().isEmpty()) {
-                       name = Instance.getTrans().getString(StringId.CHAPTER_NAMED,
-                                       chap.getNumber(), chap.getName());
+                       name = Instance.getInstance().getTrans().getString(StringId.CHAPTER_NAMED, chap.getNumber(),
+                                       chap.getName());
                } else {
-                       name = Instance.getTrans().getString(StringId.CHAPTER_UNNAMED,
-                                       chap.getNumber());
+                       name = Instance.getInstance().getTrans().getString(StringId.CHAPTER_UNNAMED, chap.getNumber());
                }
 
                String nnn = String.format("%03d", (navPoint - 2));
@@ -440,7 +437,7 @@ class Epub extends BasicOutput {
                builder.append("\n      <!-- Images -->");
 
                if (story.getMeta() != null && story.getMeta().getCover() != null) {
-                       String format = Instance.getConfig()
+                       String format = Instance.getInstance().getConfig()
                                        .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER)
                                        .toLowerCase();
                        builder.append("\n      <item id=\"cover\" href=\"images/cover."
@@ -487,7 +484,7 @@ class Epub extends BasicOutput {
                        author = meta.getAuthor();
                }
 
-               String format = Instance.getConfig()
+               String format = Instance.getInstance().getConfig()
                                .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase();
 
                builder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
index ca802a50b60770c73d1ceef3388037a2222c1482..da79466a40d9cc2fcf80872d77ef6e588398e732 100644 (file)
@@ -50,8 +50,7 @@ class Html extends BasicOutput {
                                .process(story, dir, targetNameOrig);
 
                if (story.getMeta().getCover() != null) {
-                       Instance.getCache().saveAsImage(story.getMeta().getCover(),
-                                       new File(dir, "cover"), true);
+                       Instance.getInstance().getCache().saveAsImage(story.getMeta().getCover(), new File(dir, "cover"), true);
                }
 
                return target;
@@ -91,7 +90,7 @@ class Html extends BasicOutput {
                        author = meta.getAuthor();
                }
 
-               String format = Instance.getConfig()
+               String format = Instance.getInstance().getConfig()
                                .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase();
 
                InputStream inStyle = getClass().getResourceAsStream("html.style.css");
index 6bfa4dd0ac504c8d74bcfb4a78b54ce5b75d5ae5..d8ca49a6876bcb1a759845d117b26cdd302bdfe6 100644 (file)
@@ -46,7 +46,7 @@ public class InfoCover {
                                                meta.isImageDocument() ? "true" : "false");
                                writeMeta(infoWriter, "TYPE", meta.getType());
                                if (meta.getCover() != null) {
-                                       String format = Instance.getConfig()
+                                       String format = Instance.getInstance().getConfig()
                                                        .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase();
                                        writeMeta(infoWriter, "COVER", targetName + "." + format);
                                } else {
@@ -71,12 +71,10 @@ public class InfoCover {
                        MetaData meta) {
                if (meta != null && meta.getCover() != null) {
                        try {
-                               Instance.getCache().saveAsImage(meta.getCover(),
-                                               new File(targetDir, targetName), true);
+                               Instance.getInstance().getCache().saveAsImage(meta.getCover(), new File(targetDir, targetName), true);
                        } catch (IOException e) {
                                // Allow to continue without cover
-                               Instance.getTraceHandler().error(
-                                               new IOException("Failed to save the cover image", e));
+                               Instance.getInstance().getTraceHandler().error(new IOException("Failed to save the cover image", e));
                        }
                }
        }
index cce715dcca8d228d36b51776a5d6cc4f44166e3f..935da8704d1a9ff5a02dd15dd6cef0c50705de5c 100644 (file)
@@ -9,14 +9,10 @@ import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
 
 class InfoText extends Text {
        // quote chars
-       private char openQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_SINGLE_QUOTE);
-       private char closeQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_SINGLE_QUOTE);
-       private char openDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_DOUBLE_QUOTE);
-       private char closeDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_DOUBLE_QUOTE);
+       private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
+       private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
+       private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+       private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
 
        @Override
        public String getDefaultExtension(boolean readerTarget) {
@@ -28,11 +24,10 @@ class InfoText extends Text {
                writer.write("\n");
 
                if (chap.getName() != null && !chap.getName().isEmpty()) {
-                       writer.write(Instance.getTrans().getString(StringId.CHAPTER_NAMED,
-                                       chap.getNumber(), chap.getName()));
+                       writer.write(Instance.getInstance().getTrans().getString(StringId.CHAPTER_NAMED, chap.getNumber(),
+                                       chap.getName()));
                } else {
-                       writer.write(Instance.getTrans().getString(
-                                       StringId.CHAPTER_UNNAMED, chap.getNumber()));
+                       writer.write(Instance.getInstance().getTrans().getString(StringId.CHAPTER_UNNAMED, chap.getNumber()));
                }
 
                writer.write("\n\n");
index 321556feed92054f0b134d19ad1a8bfcf5401340..a15e67c900c7fe59dbbde4aa901c7bc246255e61 100644 (file)
@@ -19,14 +19,10 @@ class LaTeX extends BasicOutput {
        private boolean lastWasQuote = false;
 
        // quote chars
-       private char openQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_SINGLE_QUOTE);
-       private char closeQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_SINGLE_QUOTE);
-       private char openDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_DOUBLE_QUOTE);
-       private char closeDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_DOUBLE_QUOTE);
+       private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
+       private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
+       private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+       private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
 
        @Override
        public File process(Story story, File targetDir, String targetName)
@@ -66,10 +62,9 @@ class LaTeX extends BasicOutput {
                        author = "\\author{" + latexEncode(meta.getAuthor()) + "}";
                        lang = meta.getLang().toLowerCase();
                        if (lang != null && !lang.isEmpty()) {
-                               lang = Instance.getConfig().getStringX(Config.CONF_LATEX_LANG, lang);
+                               lang = Instance.getInstance().getConfig().getStringX(Config.CONF_LATEX_LANG, lang);
                                if (lang == null) {
-                                       System.err.println(Instance.getTrans().getString(
-                                                       StringId.LATEX_LANG_UNKNOWN, lang));
+                                       System.err.println(Instance.getInstance().getTrans().getString(StringId.LATEX_LANG_UNKNOWN, lang));
                                }
                        }
                }
index 4a45e5430fba9465b1e92a590bcae9cc18b28360..f0516dc629ebca9bf65b7bf86fa559028004f622 100644 (file)
@@ -62,8 +62,7 @@ class Text extends BasicOutput {
                writer.write(title);
                writer.write("\n");
                if (author != null && !author.isEmpty()) {
-                       writer.write(Instance.getTrans().getString(StringId.BY) + " "
-                                       + author);
+                       writer.write(Instance.getInstance().getTrans().getString(StringId.BY) + " " + author);
                }
                if (date != null && !date.isEmpty()) {
                        writer.write(" (");
@@ -82,11 +81,9 @@ class Text extends BasicOutput {
        protected void writeChapterHeader(Chapter chap) throws IOException {
                String txt;
                if (chap.getName() != null && !chap.getName().isEmpty()) {
-                       txt = Instance.getTrans().getString(StringId.CHAPTER_NAMED,
-                                       chap.getNumber(), chap.getName());
+                       txt = Instance.getInstance().getTrans().getString(StringId.CHAPTER_NAMED, chap.getNumber(), chap.getName());
                } else {
-                       txt = Instance.getTrans().getString(StringId.CHAPTER_UNNAMED,
-                                       chap.getNumber());
+                       txt = Instance.getInstance().getTrans().getString(StringId.CHAPTER_UNNAMED, chap.getNumber());
                }
 
                writer.write("\n" + txt + "\n");
@@ -106,11 +103,9 @@ class Text extends BasicOutput {
                if (para.getType() == ParagraphType.IMAGE) {
                        File file = new File(targetDir, getCurrentImageBestName(true));
                        try {
-                               Instance.getCache().saveAsImage(para.getContentImage(), file,
-                                               nextParaIsCover);
+                               Instance.getInstance().getCache().saveAsImage(para.getContentImage(), file, nextParaIsCover);
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(
-                                               new IOException("Cannot save an image", e));
+                               Instance.getInstance().getTraceHandler().error(new IOException("Cannot save an image", e));
                        }
                }
 
index 61769c01f87951c5546ae59cc12948e88c1ebe9e..7f79da3a8ec62b854b7bcdba62838a23779fcaf4 100644 (file)
@@ -30,7 +30,7 @@ import be.nikiroo.utils.serial.SerialUtils;
  * @author niki
  */
 public abstract class BasicReader implements Reader {
-       private static BasicLibrary defaultLibrary = Instance.getLibrary();
+       private static BasicLibrary defaultLibrary = Instance.getInstance().getLibrary();
        private static ReaderType defaultType = ReaderType.GUI;
 
        private BasicLibrary lib;
@@ -42,7 +42,7 @@ public abstract class BasicReader implements Reader {
         * Take the default reader type configuration from the config file.
         */
        static {
-               String typeString = Instance.getConfig().getString(Config.READER_TYPE);
+               String typeString = Instance.getInstance().getConfig().getString(Config.READER_TYPE);
                if (typeString != null && !typeString.isEmpty()) {
                        try {
                                ReaderType type = ReaderType.valueOf(typeString.toUpperCase());
@@ -137,9 +137,8 @@ public abstract class BasicReader implements Reader {
                                                .getTypeName());
                        }
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(
-                                       new Exception("Cannot create a reader of type: "
-                                                       + defaultType + " (Not compiled in?)", e));
+                       Instance.getInstance().getTraceHandler()
+                                       .error(new Exception("Cannot create a reader of type: " + defaultType + " (Not compiled in?)", e));
                }
 
                return null;
@@ -292,11 +291,9 @@ public abstract class BasicReader implements Reader {
                        throws IOException {
                String program = null;
                if (meta.isImageDocument()) {
-                       program = Instance.getUiConfig().getString(
-                                       UiConfig.IMAGES_DOCUMENT_READER);
+                       program = Instance.getInstance().getUiConfig().getString(UiConfig.IMAGES_DOCUMENT_READER);
                } else {
-                       program = Instance.getUiConfig().getString(
-                                       UiConfig.NON_IMAGES_DOCUMENT_READER);
+                       program = Instance.getInstance().getUiConfig().getString(UiConfig.NON_IMAGES_DOCUMENT_READER);
                }
 
                if (program != null && program.trim().isEmpty()) {
@@ -330,10 +327,8 @@ public abstract class BasicReader implements Reader {
                        for (String starter : new String[] { "xdg-open", "open", "see",
                                        "start", "run" }) {
                                try {
-                                       Instance.getTraceHandler().trace(
-                                                       "starting external program");
-                                       proc = Runtime.getRuntime().exec(
-                                                       new String[] { starter, target.getAbsolutePath() });
+                                       Instance.getInstance().getTraceHandler().trace("starting external program");
+                                       proc = Runtime.getRuntime().exec(new String[] { starter, target.getAbsolutePath() });
                                        ok = true;
                                        break;
                                } catch (IOException e) {
@@ -343,7 +338,7 @@ public abstract class BasicReader implements Reader {
                                throw new IOException("Cannot find a program to start the file");
                        }
                } else {
-                       Instance.getTraceHandler().trace("starting external program");
+                       Instance.getInstance().getTraceHandler().trace("starting external program");
                        proc = Runtime.getRuntime().exec(
                                        new String[] { program, target.getAbsolutePath() });
                }
index 2a085a76e0b0829762c1b63794dc6a303d590143..556052149d7c120305df7ab206e10b80618af703 100644 (file)
@@ -52,12 +52,11 @@ class CliReader extends BasicReader {
                // TODO: progress?
                for (Chapter chap : getStory(null)) {
                        if (chap.getName() != null && !chap.getName().isEmpty()) {
-                               System.out.println(Instance.getTrans().getString(
-                                               StringId.CHAPTER_NAMED, chap.getNumber(),
+                               System.out.println(Instance.getInstance().getTrans().getString(StringId.CHAPTER_NAMED, chap.getNumber(),
                                                chap.getName()));
                        } else {
-                               System.out.println(Instance.getTrans().getString(
-                                               StringId.CHAPTER_UNNAMED, chap.getNumber()));
+                               System.out.println(
+                                               Instance.getInstance().getTrans().getString(StringId.CHAPTER_UNNAMED, chap.getNumber()));
                        }
                }
        }
index 4da86c51e7825b719c01260aa858891d100153d2..ef5e71bc676a237dd59dd2e53d7fad4affb527be 100644 (file)
@@ -64,7 +64,7 @@ class TuiReader extends BasicReader {
                                        guessBackendType());
                        app.run();
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -75,7 +75,7 @@ class TuiReader extends BasicReader {
                                        guessBackendType());
                        app.run();
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
index 1e7e8ebf25c2b9870ea8009ec2293aa19a97a42d..f85f12fdb865ec1aaa25540a5cf131d6c6b0e910 100644 (file)
@@ -120,7 +120,7 @@ class TuiReaderApplication extends TApplication implements Reader {
                try {
                        reader.browse(source);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -219,7 +219,7 @@ class TuiReaderApplication extends TApplication implements Reader {
                this.reader = reader;
 
                // TODO: traces/errors?
-               Instance.setTraceHandler(null);
+               Instance.getInstance().setTraceHandler(null);
 
                // Add the menus TODO: i18n
                TMenu fileMenu = addMenu("&File");
@@ -423,9 +423,9 @@ class TuiReaderApplication extends TApplication implements Reader {
         *            the exception to log if any (can be NULL)
         */
        private void error(String message, String title, Exception e) {
-               Instance.getTraceHandler().error(title + ": " + message);
+               Instance.getInstance().getTraceHandler().error(title + ": " + message);
                if (e != null) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
 
                if (e != null) {
index 97e46f142abb2fabb632cbe88444b66db1786f76..b1ebcc2e6971de4c25e119c5e6fbbb7a32043844 100644 (file)
@@ -164,7 +164,7 @@ class TuiReaderMainWindow extends TWindow {
                                                        selectTargets.add(source);
                                                }
                                        } catch (IOException e) {
-                                               Instance.getTraceHandler().error(e);
+                                               Instance.getInstance().getTraceHandler().error(e);
                                        }
 
                                        showTarget = true;
@@ -176,7 +176,7 @@ class TuiReaderMainWindow extends TWindow {
                                                        selectTargets.add(author);
                                                }
                                        } catch (IOException e) {
-                                               Instance.getTraceHandler().error(e);
+                                               Instance.getInstance().getTraceHandler().error(e);
                                        }
 
                                        showTarget = true;
@@ -250,7 +250,7 @@ class TuiReaderMainWindow extends TWindow {
                                metas = reader.getLibrary().getList();
                        }
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                        metas = new ArrayList<MetaData>();
                }
 
@@ -316,7 +316,7 @@ class TuiReaderMainWindow extends TWindow {
                        reader.setMeta(meta);
                        reader.read(false);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
index a27cdbe7a5b2030184d67a971e92c3affcf16b2e..451eef6a206d88044d377c8f78595dd549dffd39 100644 (file)
@@ -8,8 +8,7 @@ import be.nikiroo.fanfix.bundles.UiConfig;
 class TuiReaderOptionWindow extends TOptionWindow {
        public TuiReaderOptionWindow(TuiReaderApplication reader, boolean uiOptions) {
                super(reader, uiOptions ? UiConfig.class : Config.class,
-                               uiOptions ? Instance.getUiConfig() : Instance.getConfig(),
-                               "Options");
+                               uiOptions ? Instance.getInstance().getUiConfig() : Instance.getInstance().getConfig(), "Options");
 
                TStatusBar statusBar = reader.setStatusBar(this, "Options");
        }
index 0205e11489ba783b85102781c93d7932207489eb..a02cc84f558892bfa4f055db720cda8db8c21097 100644 (file)
@@ -63,7 +63,7 @@ class GuiReader extends BasicReader {
                        nativeLookLoaded = true;
                }
 
-               cacheDir = Instance.getReaderDir();
+               cacheDir = Instance.getInstance().getReaderDir();
                cacheDir.mkdirs();
                if (!cacheDir.exists()) {
                        throw new IOException(
@@ -79,7 +79,7 @@ class GuiReader extends BasicReader {
                        if (lib instanceof CacheLibrary) {
                                cacheLib = (CacheLibrary) lib;
                        } else {
-                               cacheLib = new CacheLibrary(cacheDir, lib);
+                               cacheLib = new CacheLibrary(cacheDir, lib, Instance.getInstance().getUiConfig());
                        }
                }
 
@@ -150,9 +150,9 @@ class GuiReader extends BasicReader {
                                                try {
                                                        Desktop.getDesktop().browse(e.getURL().toURI());
                                                } catch (IOException ee) {
-                                                       Instance.getTraceHandler().error(ee);
+                                                       Instance.getInstance().getTraceHandler().error(ee);
                                                } catch (URISyntaxException ee) {
-                                                       Instance.getTraceHandler().error(ee);
+                                                       Instance.getInstance().getTraceHandler().error(ee);
                                                }
                                }
                        });
@@ -184,7 +184,7 @@ class GuiReader extends BasicReader {
                                                                        GuiReader.this, typeFinal);
                                                        sync(gui);
                                                } catch (Exception e) {
-                                                       Instance.getTraceHandler().error(e);
+                                                       Instance.getInstance().getTraceHandler().error(e);
                                                } finally {
                                                        done[0] = true;
                                                }
@@ -259,7 +259,7 @@ class GuiReader extends BasicReader {
                                try {
                                        tag = searchable.getTag(tags);
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                }
 
                                search.searchTag(searchOn, page, item, tag);
@@ -293,7 +293,7 @@ class GuiReader extends BasicReader {
                try {
                        cacheLib.clearFromCache(luid);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -310,7 +310,7 @@ class GuiReader extends BasicReader {
                try {
                        cacheLib.delete(luid);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -333,10 +333,10 @@ class GuiReader extends BasicReader {
        void read(String luid, boolean sync, Progress pg) throws IOException {
                MetaData meta = cacheLib.getInfo(luid);
 
-               boolean textInternal = Instance.getUiConfig().getBoolean(
-                               UiConfig.NON_IMAGES_DOCUMENT_USE_INTERNAL_READER, true);
-               boolean imageInternal = Instance.getUiConfig().getBoolean(
-                               UiConfig.IMAGES_DOCUMENT_USE_INTERNAL_READER, true);
+               boolean textInternal = Instance.getInstance().getUiConfig()
+                               .getBoolean(UiConfig.NON_IMAGES_DOCUMENT_USE_INTERNAL_READER, true);
+               boolean imageInternal = Instance.getInstance().getUiConfig()
+                               .getBoolean(UiConfig.IMAGES_DOCUMENT_USE_INTERNAL_READER, true);
 
                boolean useInternalViewer = true;
                if (meta.isImageDocument() && !imageInternal) {
@@ -395,7 +395,7 @@ class GuiReader extends BasicReader {
                try {
                        cacheLib.changeSource(luid, newSource, null);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -411,7 +411,7 @@ class GuiReader extends BasicReader {
                try {
                        cacheLib.changeTitle(luid, newTitle, null);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -429,7 +429,7 @@ class GuiReader extends BasicReader {
                try {
                        cacheLib.changeAuthor(luid, newAuthor, null);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
        }
 
@@ -442,7 +442,7 @@ class GuiReader extends BasicReader {
         * @return the translated result
         */
        static String trans(StringIdGui id, Object... params) {
-               return Instance.getTransGui().getString(id, params);
+               return Instance.getInstance().getTransGui().getString(id, params);
        }
 
        /**
@@ -484,7 +484,7 @@ class GuiReader extends BasicReader {
                                EventQueue.invokeLater(run);
                        }
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                        done[0] = true;
                }
 
index f46ec1bb8c2d9279b58666d015b4ab9e7c7ad48b..8d5aaebcc73674c27f32d4e931c9d1ebae871445 100644 (file)
@@ -162,14 +162,14 @@ class GuiReaderCoverImager {
                BufferedImage resizedImage = null;
                String id = getIconId(info);
 
-               InputStream in = Instance.getCache().getFromCache(id);
+               InputStream in = Instance.getInstance().getCache().getFromCache(id);
                if (in != null) {
                        try {
                                resizedImage = ImageUtilsAwt.fromImage(new Image(in));
                                in.close();
                                in = null;
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
 
@@ -204,14 +204,14 @@ class GuiReaderCoverImager {
                                        ImageIO.write(resizedImage, "png", out);
                                        byte[] imageBytes = out.toByteArray();
                                        in = new ByteArrayInputStream(imageBytes);
-                                       Instance.getCache().addToCache(in, id);
+                                       Instance.getInstance().getCache().addToCache(in, id);
                                        in.close();
                                        in = null;
                                }
                        } catch (MalformedURLException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
 
@@ -226,7 +226,7 @@ class GuiReaderCoverImager {
         */
        static public void clearIcon(GuiReaderBookInfo info) {
                String id = getIconId(info);
-               Instance.getCache().removeFromCache(id);
+               Instance.getInstance().getCache().removeFromCache(id);
        }
 
        /**
index f3748218fcbbcd1b25b70816454cd0d56d2870ac..e0ef6d72f8a6b75805e3989a46591ae5e7abbbaf 100644 (file)
@@ -388,8 +388,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                ConfigEditor<Config> ed = new ConfigEditor<Config>(
-                                               Config.class, Instance.getConfig(), GuiReader
-                                                               .trans(StringIdGui.SUBTITLE_CONFIG));
+                                               Config.class, Instance.getInstance().getConfig(), GuiReader.trans(StringIdGui.SUBTITLE_CONFIG));
                                JFrame frame = new JFrame(title);
                                frame.add(ed);
                                frame.setSize(850, 600);
@@ -414,8 +413,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                ConfigEditor<UiConfig> ed = new ConfigEditor<UiConfig>(
-                                               UiConfig.class, Instance.getUiConfig(), GuiReader
-                                                               .trans(StringIdGui.SUBTITLE_CONFIG_UI));
+                                               UiConfig.class, Instance.getInstance().getUiConfig(),
+                                               GuiReader.trans(StringIdGui.SUBTITLE_CONFIG_UI));
                                JFrame frame = new JFrame(title);
                                frame.add(ed);
                                frame.setSize(800, 600);
@@ -477,7 +476,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                                                                        selectedBook.getInfo().getMeta()
                                                                                                        .getLuid(), type, path, pg);
                                                                } catch (IOException e) {
-                                                                       Instance.getTraceHandler().error(e);
+                                                                       Instance.getInstance().getTraceHandler().error(e);
                                                                }
                                                        }
                                                });
@@ -976,9 +975,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         *            the exception to log if any
         */
        public void error(final String message, final String title, Exception e) {
-               Instance.getTraceHandler().error(title + ": " + message);
+               Instance.getInstance().getTraceHandler().error(title + ": " + message);
                if (e != null) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
 
                SwingUtilities.invokeLater(new Runnable() {
index 476e130b01bc6acd7eb4804ddd7d19ddc15db4c4..2843a0519a82c6a6771c659b6805c5baf2f4171a 100644 (file)
@@ -142,8 +142,7 @@ class GuiReaderMainPanel extends JPanel {
                pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
                JScrollPane scroll = new JScrollPane(pane);
 
-               Integer icolor = Instance.getUiConfig().getColor(
-                               UiConfig.BACKGROUND_COLOR);
+               Integer icolor = Instance.getInstance().getUiConfig().getColor(UiConfig.BACKGROUND_COLOR);
                if (icolor != null) {
                        color = new Color(icolor);
                        setBackground(color);
@@ -224,8 +223,7 @@ class GuiReaderMainPanel extends JPanel {
                                                        helper.createMenu(status);
                                                        validate();
 
-                                                       String desc = Instance.getTransGui().getStringX(
-                                                                       StringIdGui.ERROR_LIB_STATUS,
+                                                       String desc = Instance.getInstance().getTransGui().getStringX(StringIdGui.ERROR_LIB_STATUS,
                                                                        status.toString());
                                                        if (desc == null) {
                                                                desc = GuiReader
@@ -409,7 +407,7 @@ class GuiReaderMainPanel extends JPanel {
                                                }
                                        });
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                        error(GuiReader.trans(StringIdGui.ERROR_CANNOT_OPEN),
                                                        GuiReader.trans(StringIdGui.TITLE_ERROR), e);
                                }
@@ -445,7 +443,7 @@ class GuiReaderMainPanel extends JPanel {
                                break;
                        }
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
 
                final Progress pg = new Progress();
@@ -473,7 +471,7 @@ class GuiReaderMainPanel extends JPanel {
                                                });
                                        }
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                        error(GuiReader.trans(StringIdGui.ERROR_CANNOT_OPEN),
                                                        GuiReader.trans(StringIdGui.TITLE_ERROR), e);
                                }
@@ -554,9 +552,9 @@ class GuiReaderMainPanel extends JPanel {
                        try {
                                EventQueue.invokeAndWait(run);
                        } catch (InterruptedException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        } catch (InvocationTargetException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
        }
@@ -776,9 +774,9 @@ class GuiReaderMainPanel extends JPanel {
         *            the exception to log if any
         */
        private void error(final String message, final String title, Exception e) {
-               Instance.getTraceHandler().error(title + ": " + message);
+               Instance.getInstance().getTraceHandler().error(title + ": " + message);
                if (e != null) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
 
                SwingUtilities.invokeLater(new Runnable() {
index fb726bb44532b4cb0b023951b2424f4feaa0c292..43c1a993153028314fcaf2a96b8a2acb759f221a 100644 (file)
@@ -259,7 +259,7 @@ public class GuiReaderNavBar extends JPanel {
                                listener.actionPerformed(new ActionEvent(this,
                                                ActionEvent.ACTION_FIRST, "page changed"));
                        } catch (Exception e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
        }
index b3c8f8bdaa7a572eb454b65134e9b88250239240..6d91a0ce7e120d10bc32525447d2326d6f827966 100644 (file)
@@ -77,7 +77,7 @@ public class GuiReaderSearchAction extends JFrame {
                                                try {
                                                        lib.imprt(new URL(info.getMeta().getUrl()), null);
                                                } catch (IOException e) {
-                                                       Instance.getTraceHandler().error(e);
+                                                       Instance.getInstance().getTraceHandler().error(e);
                                                }
 
                                                pg.done();
index 5b997729469b9ae3bf2afee37a4f0365c295da3e..def9fc6f80c9ff7e4f5e5e2f1c55a4faea085680 100644 (file)
@@ -332,7 +332,7 @@ public class GuiReaderSearchFrame extends JFrame {
         *            the error
         */
        static void error(Exception e) {
-               Instance.getTraceHandler().error(e);
+               Instance.getInstance().getTraceHandler().error(e);
        }
 
        /**
@@ -342,7 +342,7 @@ public class GuiReaderSearchFrame extends JFrame {
         *            the error message
         */
        static void error(String e) {
-               Instance.getTraceHandler().error(e);
+               Instance.getInstance().getTraceHandler().error(e);
        }
 
        /**
index 4cc10b4dc54099a4511d5b06f207dc32148ee3f6..0577a0ab2f4bac5c734e5282d589f5d8004926cc 100644 (file)
@@ -285,7 +285,7 @@ public class GuiReaderViewerPanel extends JPanel {
                                }
                        });
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(
+                       Instance.getInstance().getTraceHandler().error(
                                        new Exception("Failed to load image into label", e));
                        EventQueue.invokeLater(new Runnable() {
                                @Override
index 47d9664d384fd28ad9057590e1e08aec62467837..fc914ddb458eefbe3f2bf273d38a8d07d71dad14 100644 (file)
@@ -121,7 +121,7 @@ public class GuiReaderViewerTextOutput {
                        fakeStory.setChapters(Arrays.asList(chap));
                        output.process(fakeStory, null, null);
                } catch (IOException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
                return builder.toString();
        }
index 2b94725b28d15ef88cb96e75125a4636bfa7d878..b943abd25401f426bad456140eea004be06437fb 100644 (file)
@@ -222,8 +222,7 @@ public abstract class BasicSearchable {
         *             in case of I/O error
         */
        protected Document load(URL url, boolean stable) throws IOException {
-               return DataUtil.load(Instance.getCache().open(url, support, stable),
-                               "UTF-8", url.toString());
+               return DataUtil.load(Instance.getInstance().getCache().open(url, support, stable), "UTF-8", url.toString());
        }
 
        /**
index c2dfd5d5714a8f4c5e388aeccf7a8cd51053f303..e2fba1ff404f17d2a23bc18defbc2b03d7a425e3 100644 (file)
@@ -285,8 +285,7 @@ class Fanfiction extends BasicSearchable {
                                        String coverUrl = cover.absUrl("src");
 
                                        try {
-                                               InputStream in = Instance.getCache().open(
-                                                               new URL(coverUrl), getSupport(), true);
+                                               InputStream in = Instance.getInstance().getCache().open(new URL(coverUrl), getSupport(), true);
                                                try {
                                                        meta.setCover(new Image(in));
                                                } finally {
@@ -294,10 +293,8 @@ class Fanfiction extends BasicSearchable {
                                                }
                                        } catch (Exception e) {
                                                // Should not happen on Fanfiction.net
-                                               Instance.getTraceHandler().error(
-                                                               new Exception(
-                                                                               "Cannot download cover for Fanfiction story in search mode: "
-                                                                                               + meta.getTitle(), e));
+                                               Instance.getInstance().getTraceHandler().error(new Exception(
+                                                               "Cannot download cover for Fanfiction story in search mode: " + meta.getTitle(), e));
                                        }
                                }
                        }
@@ -337,8 +334,7 @@ class Fanfiction extends BasicSearchable {
                                }
 
                                meta.setResume(getSupport().makeChapter(new URL(sourceUrl), 0,
-                                               Instance.getTrans().getString(StringId.DESCRIPTION),
-                                               resume));
+                                               Instance.getInstance().getTrans().getString(StringId.DESCRIPTION), resume));
                        }
 
                        // How are the tags ordered?
index 3e2924f31d5d84a5082fec20b0058a7091c86f5d..5ba21a0e1ce25b799dc0b9a6d14d3a447135ef01 100644 (file)
@@ -89,9 +89,8 @@ class MangaLel extends BasicSearchable {
        private List<MetaData> getResults(String sourceUrl) throws IOException {
                List<MetaData> metas = new ArrayList<MetaData>();
 
-               Document doc = DataUtil.load(
-                               Instance.getCache().open(new URL(sourceUrl), getSupport(),
-                                               false), "UTF-8", sourceUrl);
+               Document doc = DataUtil.load(Instance.getInstance().getCache().open(new URL(sourceUrl), getSupport(), false),
+                               "UTF-8", sourceUrl);
 
                for (Element result : doc.getElementsByClass("rechercheAffichage")) {
                        Element a = result.getElementsByTag("a").first();
@@ -123,13 +122,8 @@ class MangaLel extends BasicSearchable {
                                        meta.setAuthor(getVal(tab, 1));
                                        meta.setTags(Arrays.asList(getVal(tab, 2).split(" ")));
 
-                                       meta.setResume(getSupport()
-                                                       .makeChapter(
-                                                                       new URL(sourceUrl),
-                                                                       0,
-                                                                       Instance.getTrans().getString(
-                                                                                       StringId.DESCRIPTION),
-                                                                       getVal(tab, 5)));
+                                       meta.setResume(getSupport().makeChapter(new URL(sourceUrl), 0,
+                                                       Instance.getInstance().getTrans().getString(StringId.DESCRIPTION), getVal(tab, 5)));
                                }
 
                                Element img = result.getElementsByTag("img").first();
@@ -143,8 +137,8 @@ class MangaLel extends BasicSearchable {
 
                                                String coverUrl = img.absUrl("src");
                                                try {
-                                                       InputStream in = Instance.getCache().open(
-                                                                       new URL(coverUrl), getSupport(), true);
+                                                       InputStream in = Instance.getInstance().getCache().open(new URL(coverUrl), getSupport(),
+                                                                       true);
                                                        try {
                                                                meta.setCover(new Image(in));
                                                        } finally {
@@ -152,15 +146,13 @@ class MangaLel extends BasicSearchable {
                                                        }
                                                } catch (Exception e) {
                                                        // Happen often on MangaLEL...
-                                                       Instance.getTraceHandler().trace(
-                                                                       "Cannot download cover for MangaLEL story in search mode: "
-                                                                                       + meta.getTitle());
+                                                       Instance.getInstance().getTraceHandler().trace(
+                                                                       "Cannot download cover for MangaLEL story in search mode: "     + meta.getTitle());
                                                }
                                        } catch (Exception e) {
                                                // no project id... cannot use the story :(
-                                               Instance.getTraceHandler().error(
-                                                               "Cannot find ProjectId for MangaLEL story in search mode: "
-                                                                               + meta.getTitle());
+                                               Instance.getInstance().getTraceHandler()
+                                                               .error("Cannot find ProjectId for MangaLEL story in search mode: " + meta.getTitle());
                                        }
                                }
 
index d07fbcd93cdd3aa72c1bba621c1595918beb2385..bc91e8b40d0688e96b8ae8698f9e252ae2fe3bec 100644 (file)
@@ -224,8 +224,7 @@ public abstract class BasicSupport {
         */
        protected Document loadDocument(URL source) throws IOException {
                String url = getCanonicalUrl(source).toString();
-               return DataUtil.load(Instance.getCache().open(source, this, false),
-                               "UTF-8", url.toString());
+               return DataUtil.load(Instance.getInstance().getCache().open(source, this, false), "UTF-8", url.toString());
        }
 
        /**
@@ -284,12 +283,9 @@ public abstract class BasicSupport {
                pg.setProgress(60);
 
                if (getDesc) {
-                       String descChapterName = Instance.getTrans().getString(
-                                       StringId.DESCRIPTION);
-                       story.getMeta().setResume(
-                                       bsPara.makeChapter(this, source, 0,
-                                                       descChapterName, //
-                                                       getDesc(), isHtml(), null));
+                       String descChapterName = Instance.getInstance().getTrans().getString(StringId.DESCRIPTION);
+                       story.getMeta().setResume(bsPara.makeChapter(this, source, 0, descChapterName, //
+                                       getDesc(), isHtml(), null));
                }
 
                pg.done();
index 41716df4e4d17952cd0e77aeac28eee20e837aca..b5c7bb9cdee9ccaf96c1de6c38eeb4aaa76a9537 100644 (file)
@@ -26,10 +26,9 @@ public class BasicSupportHelper {
         * @return the cover if any, or NULL
         */
        public Image getDefaultCover(String subject) {
-               if (subject != null && !subject.isEmpty()
-                               && Instance.getCoverDir() != null) {
+               if (subject != null && !subject.isEmpty() && Instance.getInstance().getCoverDir() != null) {
                        try {
-                               File fileCover = new File(Instance.getCoverDir(), subject);
+                               File fileCover = new File(Instance.getInstance().getCoverDir(), subject);
                                return getImage(null, fileCover.toURI().toURL(), subject);
                        } catch (MalformedURLException e) {
                        }
@@ -81,7 +80,7 @@ public class BasicSupportHelper {
                        }
                        InputStream in = null;
                        try {
-                               in = Instance.getCache().open(url, support, true);
+                               in = Instance.getInstance().getCache().open(url, support, true);
                                return new Image(in);
                        } catch (IOException e) {
                        } finally {
@@ -156,8 +155,7 @@ public class BasicSupportHelper {
                                // try for URLs
                                try {
                                        for (String ext : getImageExt(true)) {
-                                               if (Instance.getCache()
-                                                               .check(new URL(line + ext), true)) {
+                                               if (Instance.getInstance().getCache().check(new URL(line + ext), true)) {
                                                        url = new URL(line + ext);
                                                        break;
                                                }
@@ -168,7 +166,7 @@ public class BasicSupportHelper {
                                                for (String ext : getImageExt(true)) {
                                                        try {
                                                                url = new URL(line + ext);
-                                                               Instance.getCache().refresh(url, support, true);
+                                                               Instance.getInstance().getCache().refresh(url, support, true);
                                                                break;
                                                        } catch (IOException e) {
                                                                // no image with this ext
@@ -184,7 +182,7 @@ public class BasicSupportHelper {
                        // refresh the cached file
                        if (url != null) {
                                try {
-                                       Instance.getCache().refresh(url, support, true);
+                                       Instance.getInstance().getCache().refresh(url, support, true);
                                } catch (IOException e) {
                                        // woops, broken image
                                        url = null;
@@ -206,7 +204,7 @@ public class BasicSupportHelper {
        public String fixAuthor(String author) {
                if (author != null) {
                        for (String suffix : new String[] { " ", ":" }) {
-                               for (String byString : Instance.getConfig().getList(Config.CONF_BYS)) {
+                               for (String byString : Instance.getInstance().getConfig().getList(Config.CONF_BYS)) {
                                        byString += suffix;
                                        if (author.toUpperCase().startsWith(byString.toUpperCase())) {
                                                author = author.substring(byString.length()).trim();
index 4b7eeba36574f084ee6c044b1d1dd4ced798416e..576cb17e78bb3abfe845a1b053df47618636e5c6 100644 (file)
@@ -54,7 +54,7 @@ public class BasicSupportImages {
                        }
                        InputStream in = null;
                        try {
-                               in = Instance.getCache().open(url, support, true);
+                               in = Instance.getInstance().getCache().open(url, support, true);
                                return new Image(in);
                        } catch (IOException e) {
                        } finally {
@@ -126,7 +126,7 @@ public class BasicSupportImages {
                                // try for URLs
                                try {
                                        for (String ext : getImageExt(true)) {
-                                               if (Instance.getCache()
+                                               if (Instance.getInstance().getCache()
                                                                .check(new URL(line + ext), true)) {
                                                        url = new URL(line + ext);
                                                        break;
@@ -138,7 +138,7 @@ public class BasicSupportImages {
                                                for (String ext : getImageExt(true)) {
                                                        try {
                                                                url = new URL(line + ext);
-                                                               Instance.getCache().refresh(url, support, true);
+                                                               Instance.getInstance().getCache().refresh(url, support, true);
                                                                break;
                                                        } catch (IOException e) {
                                                                // no image with this ext
@@ -154,7 +154,7 @@ public class BasicSupportImages {
                        // refresh the cached file
                        if (url != null) {
                                try {
-                                       Instance.getCache().refresh(url, support, true);
+                                       Instance.getInstance().getCache().refresh(url, support, true);
                                } catch (IOException e) {
                                        // woops, broken image
                                        url = null;
index ef4d7d778f192ed10335366886768517399d9f3a..58c363af59b77e1b4f4d1c323fefe2af350ad31b 100644 (file)
@@ -26,14 +26,10 @@ import be.nikiroo.utils.StringUtils;
  */
 public class BasicSupportPara {
        // quote chars
-       private static char openQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_SINGLE_QUOTE);
-       private static char closeQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_SINGLE_QUOTE);
-       private static char openDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_DOUBLE_QUOTE);
-       private static char closeDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_DOUBLE_QUOTE);
+       private static char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
+       private static char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
+       private static char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+       private static char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
 
        // used by this class:
        BasicSupportHelper bsHelper;
@@ -77,9 +73,8 @@ public class BasicSupportPara {
                // "Chapter 5: - Fun!" after the ": " was automatically added)
                String chapterName = processPara(name, false)
                                .getContent().trim();
-               for (String lang : Instance.getConfig().getList(Config.CONF_CHAPTER)) {
-                       String chapterWord = Instance.getConfig().getStringX(
-                                       Config.CONF_CHAPTER, lang);
+               for (String lang : Instance.getInstance().getConfig().getList(Config.CONF_CHAPTER)) {
+                       String chapterWord = Instance.getInstance().getConfig().getStringX(Config.CONF_CHAPTER, lang);
                        if (chapterName.startsWith(chapterWord)) {
                                chapterName = chapterName.substring(chapterWord.length())
                                                .trim();
index 1faac03eba405657f6861f53660f2150357a4387..4a7b65b93d66c1899853888a759842e49e92ff9f 100644 (file)
@@ -42,14 +42,10 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
        private InputStream in;
 
        // quote chars
-       private char openQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_SINGLE_QUOTE);
-       private char closeQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_SINGLE_QUOTE);
-       private char openDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_DOUBLE_QUOTE);
-       private char closeDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_DOUBLE_QUOTE);
+       private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
+       private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
+       private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+       private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
 
        // New methods not used in Deprecated mode
        @Override
@@ -223,11 +219,8 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        pg.setProgress(60);
 
                        if (getDesc) {
-                               String descChapterName = Instance.getTrans().getString(
-                                               StringId.DESCRIPTION);
-                               story.getMeta().setResume(
-                                               makeChapter(url, 0, descChapterName,
-                                                               getDesc(url, getInput()), null));
+                               String descChapterName = Instance.getInstance().getTrans().getString(StringId.DESCRIPTION);
+                               story.getMeta().setResume(makeChapter(url, 0, descChapterName, getDesc(url, getInput()), null));
                        }
 
                        pg.setProgress(100);
@@ -299,8 +292,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                                        InputStream chapIn = null;
                                        if (chap.getValue() != null) {
                                                setCurrentReferer(chap.getValue());
-                                               chapIn = Instance.getCache().open(chap.getValue(),
-                                                               this, false);
+                                               chapIn = Instance.getInstance().getCache().open(chap.getValue(), this, false);
                                        }
                                        pgChaps.setProgress(i * 100);
                                        try {
@@ -391,9 +383,8 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                // redundant "Chapter x: " in front of it, or "-" (as in
                // "Chapter 5: - Fun!" after the ": " was automatically added)
                String chapterName = processPara(name).getContent().trim();
-               for (String lang : Instance.getConfig().getList(Config.CONF_CHAPTER)) {
-                       String chapterWord = Instance.getConfig().getStringX(
-                                       Config.CONF_CHAPTER, lang);
+               for (String lang : Instance.getInstance().getConfig().getList(Config.CONF_CHAPTER)) {
+                       String chapterWord = Instance.getInstance().getConfig().getStringX(Config.CONF_CHAPTER, lang);
                        if (chapterName.startsWith(chapterWord)) {
                                chapterName = chapterName.substring(chapterWord.length())
                                                .trim();
@@ -591,10 +582,9 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
         * @return the cover if any, or NULL
         */
        static Image getDefaultCover(String subject) {
-               if (subject != null && !subject.isEmpty()
-                               && Instance.getCoverDir() != null) {
+               if (subject != null && !subject.isEmpty() && Instance.getInstance().getCoverDir() != null) {
                        try {
-                               File fileCover = new File(Instance.getCoverDir(), subject);
+                               File fileCover = new File(Instance.getInstance().getCoverDir(), subject);
                                return getImage(null, fileCover.toURI().toURL(), subject);
                        } catch (MalformedURLException e) {
                        }
@@ -644,7 +634,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        }
                        InputStream in = null;
                        try {
-                               in = Instance.getCache().open(url, getSupport(url), true);
+                               in = Instance.getInstance().getCache().open(url, getSupport(url), true);
                                return new Image(in);
                        } catch (IOException e) {
                        } finally {
@@ -716,8 +706,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                                // try for URLs
                                try {
                                        for (String ext : getImageExt(true)) {
-                                               if (Instance.getCache()
-                                                               .check(new URL(line + ext), true)) {
+                                               if (Instance.getInstance().getCache().check(new URL(line + ext), true)) {
                                                        url = new URL(line + ext);
                                                        break;
                                                }
@@ -728,7 +717,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                                                for (String ext : getImageExt(true)) {
                                                        try {
                                                                url = new URL(line + ext);
-                                                               Instance.getCache().refresh(url, support, true);
+                                                               Instance.getInstance().getCache().refresh(url, support, true);
                                                                break;
                                                        } catch (IOException e) {
                                                                // no image with this ext
@@ -744,7 +733,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        // refresh the cached file
                        if (url != null) {
                                try {
-                                       Instance.getCache().refresh(url, support, true);
+                                       Instance.getInstance().getCache().refresh(url, support, true);
                                } catch (IOException e) {
                                        // woops, broken image
                                        url = null;
@@ -770,7 +759,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
         *             in case of I/O error
         */
        protected InputStream openInput(URL source) throws IOException {
-               return Instance.getCache().open(source, this, false);
+               return Instance.getInstance().getCache().open(source, this, false);
        }
 
        /**
index 22e436a22188b6e0442ba5f21c977ca0ddaed90c..76b66aba7c75fa24317eb4daca6ff75854658326 100644 (file)
@@ -71,7 +71,7 @@ class Cbz extends Epub {
 
                pgMeta.done(); // 10%
 
-               File tmpDir = Instance.getTempFiles().createTempDir("info-text");
+               File tmpDir = Instance.getInstance().getTempFiles().createTempDir("info-text");
                String basename = null;
 
                Map<String, Image> images = new HashMap<String, Image>();
@@ -97,7 +97,7 @@ class Cbz extends Epub {
                                                try {
                                                        images.put(uuid, new Image(zipIn));
                                                } catch (Exception e) {
-                                                       Instance.getTraceHandler().error(e);
+                                                       Instance.getInstance().getTraceHandler().error(e);
                                                }
 
                                                if (pg.getProgress() < 85) {
@@ -114,9 +114,7 @@ class Cbz extends Epub {
                        }
                        
                        String ext = "."
-                                       + Instance.getConfig()
-                                                       .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER)
-                                                       .toLowerCase();
+                                       + Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase();
                        String coverName = meta.getUuid() + "_" + basename + ext;
                        Image cover = images.get(coverName);
                        images.remove(coverName);
@@ -176,7 +174,7 @@ class Cbz extends Epub {
                                                chap.getParagraphs().add(
                                                                new Paragraph(images.get(uuid)));
                                        } catch (Exception e) {
-                                               Instance.getTraceHandler().error(e);
+                                               Instance.getInstance().getTraceHandler().error(e);
                                        }
                                }
                        }
index 94010a73ae4b61165598b35b4f7ff8743b4b2e41..f1660e18cb34a9da6373ac03e6918ccc630ff25f 100644 (file)
@@ -123,7 +123,7 @@ class E621 extends BasicSupport {
                for (int i = 1; true; i++) {
                        URL url = new URL(baseUrl + i + parameters);
                        try {
-                               InputStream pageI = Instance.getCache().open(url, this, false);
+                               InputStream pageI = Instance.getInstance().getCache().open(url, this, false);
                                try {
                                        if (IOUtils.readSmallStream(pageI).contains("Nobody here but us chickens!")) {
                                                break;
@@ -159,7 +159,7 @@ class E621 extends BasicSupport {
        protected URL getCanonicalUrl(URL source) {
                if (isSetOriginalUrl(source)) {
                        try {
-                               Document doc = DataUtil.load(Instance.getCache().open(source, this, false), "UTF-8", source.toString());
+                               Document doc = DataUtil.load(Instance.getInstance().getCache().open(source, this, false), "UTF-8", source.toString());
                                for (Element shortname : doc.getElementsByClass("set-shortname")) {
                                        for (Element el : shortname.getElementsByTag("a")) {
                                                if (!el.attr("href").isEmpty())
@@ -167,7 +167,7 @@ class E621 extends BasicSupport {
                                        }
                                }
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
 
index 67585cd477f90a257acd94c9d28c67bac07575f7..03c1557432194187cb54e2b43e9f4239d42c1668 100644 (file)
@@ -255,10 +255,8 @@ class EHentai extends BasicSupport_Deprecated {
                                try {
                                        pages.add(new URL(line));
                                } catch (MalformedURLException e) {
-                                       Instance.getTraceHandler().error(
-                                                       new IOException(
-                                                                       "Parsing error, a link is not correctly parsed: "
-                                                                                       + line, e));
+                                       Instance.getInstance().getTraceHandler()
+                                                       .error(new IOException("Parsing error, a link is not correctly parsed: " + line, e));
                                }
                        }
                }
@@ -272,7 +270,7 @@ class EHentai extends BasicSupport_Deprecated {
                StringBuilder builder = new StringBuilder();
 
                for (URL page : pages) {
-                       InputStream pageIn = Instance.getCache().open(page, this, false);
+                       InputStream pageIn = Instance.getInstance().getCache().open(page, this, false);
                        try {
                                String link = getKeyLine(pageIn, "id=\"img\"", "src=\"", "\"");
                                if (link != null && !link.isEmpty()) {
index 82af11855fdc299226fe2f52ca536f17a07d1d00..f8e467831381185244eae24b15d3a96a6cb0f6cb 100644 (file)
@@ -42,10 +42,8 @@ class Epub extends InfoText {
                try {
                        return new File(fakeSource.toURI());
                } catch (URISyntaxException e) {
-                       Instance.getTraceHandler()
-                                       .error(new IOException(
-                                                       "Cannot get the source file from the info-text URL",
-                                                       e));
+                       Instance.getInstance().getTraceHandler()
+                                       .error(new IOException("Cannot get the source file from the info-text URL", e));
                }
 
                return null;
@@ -57,9 +55,7 @@ class Epub extends InfoText {
                        try {
                                fakeIn.reset();
                        } catch (IOException e) {
-                               Instance.getTraceHandler()
-                                               .error(new IOException(
-                                                               "Cannot reset the Epub Text stream", e));
+                               Instance.getInstance().getTraceHandler().error(new IOException("Cannot reset the Epub Text stream", e));
                        }
 
                        return fakeIn;
@@ -87,8 +83,7 @@ class Epub extends InfoText {
                ZipInputStream zipIn = null;
                try {
                        zipIn = new ZipInputStream(in);
-                       tmpDir = Instance.getTempFiles().createTempDir(
-                                       "fanfic-reader-parser");
+                       tmpDir = Instance.getInstance().getTempFiles().createTempDir("fanfic-reader-parser");
                        File tmp = new File(tmpDir, "file.txt");
                        File tmpInfo = new File(tmpDir, "file.info");
 
@@ -129,7 +124,7 @@ class Epub extends InfoText {
                                                        try {
                                                                cover = new Image(zipIn);
                                                        } catch (Exception e) {
-                                                               Instance.getTraceHandler().error(e);
+                                                               Instance.getInstance().getTraceHandler().error(e);
                                                        }
                                                }
                                        } else if (entry.getName().equals(getDataPrefix() + "URL")) {
index fcf773bd78b787693cd3afa28febd8502f997fc6..282192e065bb82fd238c06b863d0e9a3647f4917 100644 (file)
@@ -157,10 +157,8 @@ class Fanfiction extends BasicSupport_Deprecated {
                                                return sdf
                                                                .format(new Date(1000 * Long.parseLong(line)));
                                        } catch (NumberFormatException e) {
-                                               Instance.getTraceHandler().error(
-                                                               new IOException(
-                                                                               "Cannot convert publication date: "
-                                                                                               + line, e));
+                                               Instance.getInstance().getTraceHandler()
+                                                               .error(new IOException("Cannot convert publication date: " + line, e));
                                        }
                                }
                        }
@@ -243,11 +241,8 @@ class Fanfiction extends BasicSupport_Deprecated {
                                                        urls.add(new AbstractMap.SimpleEntry<String, URL>(
                                                                        name.trim(), new URL(base + i + suffix)));
                                                } catch (MalformedURLException e) {
-                                                       Instance.getTraceHandler()
-                                                                       .error(new IOException(
-                                                                                       "Cannot parse chapter " + i
-                                                                                                       + " url: "
-                                                                                                       + (base + i + suffix), e));
+                                                       Instance.getInstance().getTraceHandler().error(
+                                                                       new IOException("Cannot parse chapter " + i + " url: " + (base + i + suffix), e));
                                                }
                                        }
                                }
@@ -304,10 +299,9 @@ class Fanfiction extends BasicSupport_Deprecated {
                                        int pos = line.indexOf("<hr");
                                        if (pos >= 0) {
                                                boolean chaptered = false;
-                                               for (String lang : Instance.getConfig().getList(
-                                                               Config.CONF_CHAPTER)) {
-                                                       String chapterWord = Instance.getConfig()
-                                                                       .getStringX(Config.CONF_CHAPTER, lang);
+                                               for (String lang : Instance.getInstance().getConfig().getList(Config.CONF_CHAPTER)) {
+                                                       String chapterWord = Instance.getInstance().getConfig().getStringX(Config.CONF_CHAPTER,
+                                                                       lang);
                                                        int posChap = line.indexOf(chapterWord + " ");
                                                        if (posChap < pos) {
                                                                chaptered = true;
index e96ac4f5766eb601886e3b6574c27044fb33b81a..77267c1188a24438bec7f46c1097219f0d20e58c 100644 (file)
@@ -230,7 +230,7 @@ class Fimfiction extends BasicSupport_Deprecated {
                                                urls.add(new AbstractMap.SimpleEntry<String, URL>(name,
                                                                new URL("http://www.fimfiction.net" + line)));
                                        } catch (MalformedURLException e) {
-                                               Instance.getTraceHandler().error(e);
+                                               Instance.getInstance().getTraceHandler().error(e);
                                        }
                                }
                        }
index c97ecf7d3e9ea2ff8a7cc782eea5bca660f9f265..6c6d7ba31caf2197356b68168447c7871b257a52 100644 (file)
@@ -37,22 +37,17 @@ class FimfictionApi extends BasicSupport {
        private Map<Integer, String> chapterContents;
 
        public FimfictionApi() throws IOException {
-               if (Instance.getConfig().getBoolean(
-                               Config.LOGIN_FIMFICTION_APIKEY_FORCE_HTML, false)) {
-                       throw new IOException(
-                                       "Configuration is set to force HTML scrapping");
+               if (Instance.getInstance().getConfig().getBoolean(Config.LOGIN_FIMFICTION_APIKEY_FORCE_HTML, false)) {
+                       throw new IOException("Configuration is set to force HTML scrapping");
                }
 
-               String oauth = Instance.getConfig().getString(
-                               Config.LOGIN_FIMFICTION_APIKEY_TOKEN);
+               String oauth = Instance.getInstance().getConfig().getString(Config.LOGIN_FIMFICTION_APIKEY_TOKEN);
 
                if (oauth == null || oauth.isEmpty()) {
-                       String clientId = Instance.getConfig().getString(
-                                       Config.LOGIN_FIMFICTION_APIKEY_CLIENT_ID)
-                                       + "";
-                       String clientSecret = Instance.getConfig().getString(
-                                       Config.LOGIN_FIMFICTION_APIKEY_CLIENT_SECRET)
+                       String clientId = Instance.getInstance().getConfig().getString(Config.LOGIN_FIMFICTION_APIKEY_CLIENT_ID)
                                        + "";
+                       String clientSecret = Instance.getInstance().getConfig()
+                                       .getString(Config.LOGIN_FIMFICTION_APIKEY_CLIENT_SECRET) + "";
 
                        if (clientId.trim().isEmpty() || clientSecret.trim().isEmpty()) {
                                throw new IOException("API key required for the beta API v2");
@@ -60,9 +55,8 @@ class FimfictionApi extends BasicSupport {
 
                        oauth = generateOAuth(clientId, clientSecret);
 
-                       Instance.getConfig().setString(
-                                       Config.LOGIN_FIMFICTION_APIKEY_TOKEN, oauth);
-                       Instance.getConfig().updateFile();
+                       Instance.getInstance().getConfig().setString(Config.LOGIN_FIMFICTION_APIKEY_TOKEN, oauth);
+                       Instance.getInstance().getConfig().updateFile();
                }
 
                this.oauth = oauth;
@@ -116,7 +110,7 @@ class FimfictionApi extends BasicSupport {
                urlString = urlString.replace("[", "%5B").replace("]", "%5D");
 
                URL url = new URL(urlString);
-               InputStream jsonIn = Instance.getCache().open(url, this, false);
+               InputStream jsonIn = Instance.getInstance().getCache().open(url, this, false);
                try {
                        return IOUtils.readSmallStream(jsonIn);
                } finally {
@@ -150,17 +144,15 @@ class FimfictionApi extends BasicSupport {
                        // No need to use the oauth, cookies... for the cover
                        // Plus: it crashes on Android because of the referer
                        try {
-                               InputStream in = Instance.getCache().open(coverImageUrl, null,
-                                               true);
+                               InputStream in = Instance.getInstance().getCache().open(coverImageUrl, null, true);
                                try {
                                        meta.setCover(new Image(in));
                                } finally {
                                        in.close();
                                }
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(
-                                               new IOException(
-                                                               "Cannot get the story cover, ignoring...", e));
+                               Instance.getInstance().getTraceHandler()
+                                               .error(new IOException("Cannot get the story cover, ignoring...", e));
                        }
                }
 
@@ -258,8 +250,7 @@ class FimfictionApi extends BasicSupport {
                params.put("client_id", clientId);
                params.put("client_secret", clientSecret);
                params.put("grant_type", "client_credentials");
-               InputStream in = Instance.getCache().openNoCache(url, null, params,
-                               null, null);
+               InputStream in = Instance.getInstance().getCache().openNoCache(url, null, params, null, null);
 
                String jsonToken = IOUtils.readSmallStream(in);
                in.close();
index c27dd32f181651186446bbe597c09b6f6b7d8c5b..900fa0a1772f0ffd5ecfcaf2fecfbd8b248168a0 100644 (file)
@@ -51,9 +51,8 @@ class Html extends InfoText {
                        try {
                                source = txt.toURI().toURL();
                        } catch (MalformedURLException e) {
-                               Instance.getTraceHandler().error(
-                                               new IOException("Cannot convert the right URL for "
-                                                               + source, e));
+                               Instance.getInstance().getTraceHandler()
+                                               .error(new IOException("Cannot convert the right URL for " + source, e));
                        }
                }
 
index c22dbd711bedca99d1bde9f08400ba8e83b069b7..220350e6dc904495de7de918e4843cf3d15dda01 100644 (file)
@@ -98,8 +98,7 @@ public class InfoReader {
                File basefile = new File(sourceInfoFile.getFile());
 
                String ext = "."
-                               + Instance.getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER)
-                                               .toLowerCase();
+                               + Instance.getInstance().getConfig().getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase();
 
                // Without removing ext
                cover = bsHelper.getImage(null, sourceInfoFile,
index 99e85693e1e819de4b3c08d1c638608c2f0cbac9..706a59114adf62949044cf1eb52b8347d38749dc 100644 (file)
@@ -109,7 +109,7 @@ class MangaHub extends BasicSupport {
                        try {
                                return bsImages.getImage(this, new URL(cover.absUrl("src")));
                        } catch (MalformedURLException e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
 
@@ -137,7 +137,7 @@ class MangaHub extends BasicSupport {
                        try {
                                urls.add(new AbstractMap.SimpleEntry<String, URL>(title, new URL(url)));
                        } catch (Exception e) {
-                               Instance.getTraceHandler().error(e);
+                               Instance.getInstance().getTraceHandler().error(e);
                        }
                }
 
@@ -193,7 +193,7 @@ class MangaHub extends BasicSupport {
                        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                        try {
                                conn.setRequestMethod("HEAD");
-                               conn.setRequestProperty("User-Agent", Instance.getConfig().getString(Config.NETWORK_USER_AGENT));
+                               conn.setRequestProperty("User-Agent", Instance.getInstance().getConfig().getString(Config.NETWORK_USER_AGENT));
                                conn.setRequestProperty("Accept-Encoding", "gzip");
                                conn.setRequestProperty("Accept", "*/*");
                                conn.setRequestProperty("Charset", "utf-8");
index 1ba51bc0f5d8a5c32a0341526a5aac142ae3fff6..9929699cc43839b93e1b98752d205d562a08a845 100644 (file)
@@ -149,15 +149,14 @@ class MangaLel extends BasicSupport {
 
                                InputStream coverIn;
                                try {
-                                       coverIn = Instance.getCache().open(new URL(coverUrl), this,
-                                                       true);
+                                       coverIn = Instance.getInstance().getCache().open(new URL(coverUrl), this, true);
                                        try {
                                                return new Image(coverIn);
                                        } finally {
                                                coverIn.close();
                                        }
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(e);
+                                       Instance.getInstance().getTraceHandler().error(e);
                                }
                        }
                }
@@ -209,7 +208,7 @@ class MangaLel extends BasicSupport {
 
                StringBuilder builder = new StringBuilder();
 
-               InputStream in = Instance.getCache().open(chapUrl, this, false);
+               InputStream in = Instance.getInstance().getCache().open(chapUrl, this, false);
                try {
                        Element pageDoc = DataUtil.load(in, "UTF-8", chapUrl.toString());
                        Element content = pageDoc.getElementById("content");
index 0df30f268a7c09b8656d4e3b5c78d628e565be39..7ace7269397ca5f679b0ee85cff8a6e094fb4a67 100644 (file)
@@ -77,11 +77,10 @@ public enum SupportType {
         * @return the description
         */
        public String getDesc() {
-               String desc = Instance.getTrans().getStringX(StringId.INPUT_DESC,
-                               this.name());
+               String desc = Instance.getInstance().getTrans().getStringX(StringId.INPUT_DESC, this.name());
 
                if (desc == null) {
-                       desc = Instance.getTrans().getString(StringId.INPUT_DESC, this);
+                       desc = Instance.getInstance().getTrans().getString(StringId.INPUT_DESC, this);
                }
 
                return desc;
index 8af4a4084b2a2c91ca3bc0aea7f726c7781bc821..c54b6a5d44ce0a328d63451420c6a9c00a82bd3c 100644 (file)
@@ -53,8 +53,7 @@ class Text extends BasicSupport {
                        try {
                                in.reset();
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(
-                                               new IOException("Cannot reset the Text stream", e));
+                               Instance.getInstance().getTraceHandler().error(new IOException("Cannot reset the Text stream", e));
                        }
 
                        return in;
@@ -201,8 +200,7 @@ class Text extends BasicSupport {
                Image cover = bsImages.getImage(this, sourceFile.getParentFile(), path);
                if (cover != null) {
                        try {
-                               File tmp = Instance.getTempFiles().createTempFile(
-                                               "test_cover_image");
+                               File tmp = Instance.getInstance().getTempFiles().createTempFile("test_cover_image");
                                ImageUtils.getInstance().saveAsImage(cover, tmp, "png");
                                tmp.delete();
                        } catch (IOException e) {
@@ -271,9 +269,8 @@ class Text extends BasicSupport {
                        try {
                                in.close();
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(
-                                               new IOException(
-                                                               "Cannot close the text source file input", e));
+                               Instance.getInstance().getTraceHandler()
+                                               .error(new IOException("Cannot close the text source file input", e));
                        }
                }
 
@@ -310,7 +307,7 @@ class Text extends BasicSupport {
                        file = assureNoTxt(file);
                        file = new File(file.getPath() + ".info");
                } catch (URISyntaxException e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                        file = null;
                }
 
@@ -350,9 +347,8 @@ class Text extends BasicSupport {
         */
        static private String detectChapter(String line, int number) {
                line = line.toUpperCase();
-               for (String lang : Instance.getConfig().getList(Config.CONF_CHAPTER)) {
-                       String chapter = Instance.getConfig().getStringX(
-                                       Config.CONF_CHAPTER, lang);
+               for (String lang : Instance.getInstance().getConfig().getList(Config.CONF_CHAPTER)) {
+                       String chapter = Instance.getInstance().getConfig().getStringX(Config.CONF_CHAPTER, lang);
                        if (chapter != null && !chapter.isEmpty()) {
                                chapter = chapter.toUpperCase() + " ";
                                if (line.startsWith(chapter)) {
index aad01a68d06f515999c4557b902136603ffa13ad..6974e9ae98a52bfde44f703cb585a63a26810033 100644 (file)
@@ -67,10 +67,8 @@ class YiffStar extends BasicSupport_Deprecated {
        public void login() throws IOException {
                // Note: this should not be necessary anymore
                // (the "/guest" trick is enough)
-               String login = Instance.getConfig().getString(
-                               Config.LOGIN_YIFFSTAR_USER);
-               String password = Instance.getConfig().getString(
-                               Config.LOGIN_YIFFSTAR_PASS);
+               String login = Instance.getInstance().getConfig().getString(Config.LOGIN_YIFFSTAR_USER);
+               String password = Instance.getInstance().getConfig().getString(Config.LOGIN_YIFFSTAR_PASS);
 
                if (login != null && !login.isEmpty() && password != null
                                && !password.isEmpty()) {
@@ -84,9 +82,8 @@ class YiffStar extends BasicSupport_Deprecated {
 
                        // Cookies will actually be retained by the cache manager once
                        // logged in
-                       Instance.getCache()
-                                       .openNoCache(new URL("https://www.sofurry.com/user/login"),
-                                                       this, post, null, null).close();
+                       Instance.getInstance().getCache()
+                                       .openNoCache(new URL("https://www.sofurry.com/user/login"), this, post, null, null).close();
                }
        }
 
@@ -96,8 +93,7 @@ class YiffStar extends BasicSupport_Deprecated {
                        if (source.getPath().startsWith("/view")) {
                                source = guest(source.toString());
                                // NO CACHE because we don't want the NotLoggedIn message later
-                               InputStream in = Instance.getCache().openNoCache(source, this,
-                                               null, null, null);
+                               InputStream in = Instance.getInstance().getCache().openNoCache(source, this, null, null, null);
                                String line = getLine(in, "/browse/folder/", 0);
                                if (line != null) {
                                        String[] tab = line.split("\"");
@@ -109,7 +105,7 @@ class YiffStar extends BasicSupport_Deprecated {
                                }
                        }
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
 
                return super.getCanonicalUrl(source);
@@ -136,7 +132,7 @@ class YiffStar extends BasicSupport_Deprecated {
 
                List<Entry<String, URL>> chaps = getChapters(source, in, null);
                if (!chaps.isEmpty()) {
-                       in = Instance.getCache().open(chaps.get(0).getValue(), this, true);
+                       in = Instance.getInstance().getCache().open(chaps.get(0).getValue(), this, true);
                        String line = getLine(in, " name=\"og:image\"", 0);
                        if (line != null) {
                                int pos = -1;
index 9f40a8040d63b3bda175a4af1b531ccbf3aa0cdb..c8c4b401727e7927af3ccca210ed158e4902c97b 100644 (file)
@@ -24,14 +24,10 @@ import be.nikiroo.utils.test.TestLauncher;
 
 class BasicSupportDeprecatedTest extends TestLauncher {
        // quote chars
-       private char openQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_SINGLE_QUOTE);
-       private char closeQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_SINGLE_QUOTE);
-       private char openDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_DOUBLE_QUOTE);
-       private char closeDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_DOUBLE_QUOTE);
+       private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
+       private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
+       private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+       private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
 
        public BasicSupportDeprecatedTest(String[] args) {
                super("BasicSupportDeprecated", args);
@@ -256,9 +252,9 @@ class BasicSupportDeprecatedTest extends TestLauncher {
                                        public void test() throws Exception {
                                                BasicSupportEmpty support = new BasicSupportEmpty();
 
-                                               char openDoubleQuote = Instance.getTrans()
+                                               char openDoubleQuote = Instance.getInstance().getTrans()
                                                                .getCharacter(StringId.OPEN_DOUBLE_QUOTE);
-                                               char closeDoubleQuote = Instance.getTrans()
+                                               char closeDoubleQuote = Instance.getInstance().getTrans()
                                                                .getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
 
                                                String content = null;
index 4e348913ca9ee29a81cc1c06c36c8a059758979c..9cec2208c28a03a189adc10b31b4a97ac0b4b722 100644 (file)
@@ -23,14 +23,10 @@ import be.nikiroo.utils.test.TestLauncher;
 
 class BasicSupportUtilitiesTest extends TestLauncher {
        // quote chars
-       private char openQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_SINGLE_QUOTE);
-       private char closeQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_SINGLE_QUOTE);
-       private char openDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.OPEN_DOUBLE_QUOTE);
-       private char closeDoubleQuote = Instance.getTrans().getCharacter(
-                       StringId.CLOSE_DOUBLE_QUOTE);
+       private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
+       private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
+       private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+       private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
        
        public BasicSupportUtilitiesTest(String[] args) {
                super("BasicSupportUtilities", args);
@@ -229,9 +225,9 @@ class BasicSupportUtilitiesTest extends TestLauncher {
                                        public void test() throws Exception {
                                                BasicSupportParaPublic support = new BasicSupportParaPublic();
 
-                                               char openDoubleQuote = Instance.getTrans()
+                                               char openDoubleQuote = Instance.getInstance().getTrans()
                                                                .getCharacter(StringId.OPEN_DOUBLE_QUOTE);
-                                               char closeDoubleQuote = Instance.getTrans()
+                                               char closeDoubleQuote = Instance.getInstance().getTrans()
                                                                .getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
 
                                                String content = null;
index 607f49ba744b955eba4bf21796ee54b03b9ba9a4..d730b3b5efecc85f8a1b581c0ae16dc719e66187 100644 (file)
@@ -138,8 +138,8 @@ class ConversionTest extends TestLauncher {
                        BasicOutput.OutputType type) throws Exception {
                final List<String> errors = new ArrayList<String>();
 
-               TraceHandler previousTraceHandler = Instance.getTraceHandler();
-               Instance.setTraceHandler(new TraceHandler(true, true, 0) {
+               TraceHandler previousTraceHandler = Instance.getInstance().getTraceHandler();
+               Instance.getInstance().setTraceHandler(new TraceHandler(true, true, 0) {
                        @Override
                        public void error(String message) {
                                errors.add(message);
@@ -178,7 +178,7 @@ class ConversionTest extends TestLauncher {
 
                        return target;
                } finally {
-                       Instance.setTraceHandler(previousTraceHandler);
+                       Instance.getInstance().setTraceHandler(previousTraceHandler);
                }
        }
 
index d772561ad6ff008069ccecb6e98d894475ca6977..5ec24a43b1b6a0eee8ba68991c9b2fe9d86c2c7b 100644 (file)
@@ -51,7 +51,7 @@ public class Test extends TestLauncher {
         */
        public Test(String[] args, boolean urlsAllowed) throws IOException {
                super("Fanfix", args);
-               Instance.setTraceHandler(null);
+               Instance.getInstance().setTraceHandler(null);
                addSeries(new BasicSupportUtilitiesTest(args));
                addSeries(new BasicSupportDeprecatedTest(args));
                addSeries(new LibraryTest(args));
@@ -106,7 +106,7 @@ public class Test extends TestLauncher {
                
                // Only download files if allowed:
                boolean offline = new File("test/OFFLINE").exists();
-               Instance.getCache().setOffline(offline);
+               Instance.getInstance().getCache().setOffline(offline);
 
 
                
@@ -126,7 +126,7 @@ public class Test extends TestLauncher {
                        System.setProperty("CONFIG_DIR", tmpConfig.getAbsolutePath());
 
                        Instance.init(true);
-                       Instance.getCache().setOffline(offline);
+                       Instance.getInstance().getCache().setOffline(offline);
 
                        TestLauncher tests = new Test(args, urlsAllowed);
                        tests.setDetails(verbose);
@@ -140,7 +140,7 @@ public class Test extends TestLauncher {
                        tempFiles.close();
 
                        // This is usually done in Fanfix.Main:
-                       Instance.getTempFiles().close();
+                       Instance.getInstance().getTempFiles().close();
                }
 
                System.exit(result);