[jsword-svn] r1194 - in trunk: common/src/main/java/org/crosswire/common/util jsword/src/main/java/org/crosswire/jsword/book/sword jsword/src/main/java/org/crosswire/jsword/util

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Sat Dec 2 15:42:11 MST 2006


Author: dmsmith
Date: 2006-12-02 15:42:07 -0700 (Sat, 02 Dec 2006)
New Revision: 1194

Modified:
   trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java
   trunk/jsword/src/main/java/org/crosswire/jsword/util/Project.java
Log:
USB Drive changes

Modified: trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java	2006-12-02 13:51:58 UTC (rev 1193)
+++ trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java	2006-12-02 22:42:07 UTC (rev 1194)
@@ -208,6 +208,22 @@
     }
 
     /**
+     * If there is a writable directory or file at the other end of this URL return true.
+     * Note non file: type URLs will always return false
+     * @param orig The URL to check
+     * @return true if the URL points at a file: directory
+     */
+    public static boolean canWrite(URL orig)
+    {
+        if (!orig.getProtocol().equals(PROTOCOL_FILE))
+        {
+            return false;
+        }
+
+        return new File(orig.getFile()).canWrite();
+    }
+
+    /**
      * Move a URL from one place to another. Currently this only works for
      * file: URLs, however the interface should not need to change to
      * handle more complex URLs

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java	2006-12-02 13:51:58 UTC (rev 1193)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookPath.java	2006-12-02 22:42:07 UTC (rev 1194)
@@ -84,7 +84,7 @@
 
     /**
      * Obtain a prioritized path of Book locations.
-     * This contains the downloadDir as the first location,
+     * This contains the download dir as the first location,
      * the user's augment path and finally all the discovered
      * standard locations.
      * 
@@ -95,7 +95,7 @@
         ArrayList swordPath = new ArrayList();
 
         // The first place to look for Books
-        swordPath.add(downloadDir);
+        swordPath.add(getDownloadDir());
 
         // Then all the user's augments
         if (augmentPath != null)
@@ -366,7 +366,11 @@
      */
     public static File getDownloadDir()
     {
-        return downloadDir;
+        if (overrideDownloadDir != null)
+        {
+            return overrideDownloadDir;
+        }
+        return defaultDownloadDir;
     }
 
     /**
@@ -376,7 +380,7 @@
     {
         if (!dlDir.getPath().equals("")) //$NON-NLS-1$
         {
-            downloadDir = dlDir;
+            overrideDownloadDir = dlDir;
             log.debug("Setting sword download directory to: " + dlDir); //$NON-NLS-1$
         }
     }
@@ -459,9 +463,14 @@
     /**
      * The directory URL
      */
-    private static File downloadDir = getDefaultDownloadPath();
+    private static File defaultDownloadDir = getDefaultDownloadPath();
 
     /**
+     * The directory URL
+     */
+    private static File overrideDownloadDir = null;
+
+    /**
      * The log stream
      */
     private static final Logger log = Logger.getLogger(SwordBookPath.class);

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/util/Project.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/util/Project.java	2006-12-02 13:51:58 UTC (rev 1193)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/util/Project.java	2006-12-02 22:42:07 UTC (rev 1194)
@@ -23,6 +23,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 
 import org.crosswire.common.util.CWClassLoader;
@@ -47,6 +48,12 @@
  * if different and possible.
  * </p>
  * 
+ * <p>
+ * Note: If the Java System property jsword.home is set and it exists and is writeable
+ * then it will be used instead of the above location. This is useful for USB Drives
+ * and other portable implementations of JSword. I is recommended that this name be JSword.
+ * </p>
+ * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
  * @author Joe Walker [joe at eireneh dot com]
@@ -117,6 +124,27 @@
     {
         if (home == null)
         {
+            // if there is a property set for the jsword home directory
+            String jswordhome = System.getProperty(PROPERTY_JSWORD_HOME);
+            if (jswordhome != null)
+            {
+                try
+                {
+                    home = new URL(NetUtil.PROTOCOL_FILE, null, jswordhome);
+                    if (!NetUtil.canWrite(home))
+                    {
+                        home = null;
+                    }
+                }
+                catch (MalformedURLException e)
+                {
+                    home = null;
+                }
+            }
+        }
+
+        if (home == null)
+        {
             URL path = getUserProjectDir(DIR_PROJECT, DIR_PROJECT_ALT);
             URL oldPath = getDeprecatedUserProjectDir();
             home = migrateUserProjectDir(oldPath, path);
@@ -207,6 +235,11 @@
     }
 
     /**
+     * System property for jsword home directory
+     */
+    private static final String PROPERTY_JSWORD_HOME = "jsword.home"; //$NON-NLS-1$
+
+    /**
      * The home for this application
      */
     private URL home;




More information about the jsword-svn mailing list