+ private BasicLibrary createDefaultLibrary(File remoteDir) {
+ BasicLibrary lib = null;
+
+ boolean useRemote = config.getBoolean(Config.REMOTE_LIBRARY_ENABLED,
+ false);
+ if (useRemote) {
+ String host = null;
+ int port = -1;
+ try {
+ host = config.getString(Config.REMOTE_LIBRARY_HOST,
+ "fanfix://localhost");
+ port = config.getInteger(Config.REMOTE_LIBRARY_PORT, -1);
+ String key = config.getString(Config.REMOTE_LIBRARY_KEY);
+
+ if (!host.startsWith("http://") && !host.startsWith("https://")
+ && !host.startsWith("fanfix://")) {
+ host = "fanfix://" + host;
+ }
+
+ tracer.trace("Selecting remote library " + host + ":" + port);
+
+ if (host.startsWith("fanfix://")) {
+ lib = new RemoteLibrary(key, host, port);
+ } else {
+ lib = new WebLibrary(key, host, port);
+ }
+
+ lib = new CacheLibrary(getRemoteDir(remoteDir, host), lib,
+ uiconfig);
+ } catch (Exception e) {
+ tracer.error(
+ new IOException("Cannot create remote library for: "
+ + host + ":" + port, e));
+ }
+ } else {
+ String libDir = System.getenv("BOOKS_DIR");
+ if (libDir == null || libDir.isEmpty()) {
+ libDir = getFile(Config.LIBRARY_DIR, configDir, "$HOME/Books")
+ .getPath();
+ }
+ try {
+ lib = new LocalLibrary(new File(libDir), config);
+ } catch (Exception e) {
+ tracer.error(new IOException(
+ "Cannot create library for directory: " + libDir, e));
+ }
+ }
+
+ return lib;