[jsword-svn] r1312 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop bibledesktop/src/main/java/org/crosswire/bibledesktop/display common/src/main/java/org/crosswire/common/config common/src/main/java/org/crosswire/common/progress common/src/main/java/org/crosswire/common/util common/src/main/java/org/crosswire/common/xml common-swing/src/main/java/org/crosswire/common/swing jsword/src/main/java/org/crosswire/jsword/book/install/sword jsword/src/main/java/org/crosswire/jsword/book/sword jsword/src/main/java/org/crosswire/jsword/passage jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc jsword-limbo/src/main/java/org/crosswire/jsword/book/raw jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser jsword-limbo/src/main/java/org/crosswire/jsword/book/ser

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Thu May 3 14:39:51 MST 2007


Author: dmsmith
Date: 2007-05-03 14:39:51 -0700 (Thu, 03 May 2007)
New Revision: 1312

Removed:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEvent.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEventListener.java
Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/StatusBar.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java
   trunk/common/src/main/java/org/crosswire/common/config/Config.java
   trunk/common/src/main/java/org/crosswire/common/progress/Job.java
   trunk/common/src/main/java/org/crosswire/common/util/CollectionUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/IOUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
   trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java
   trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java
   trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java
   trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/Mem.java
   trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBookDriver.java
   trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java
   trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/ser/BookDataCache.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/KeyIterator.java
Log:
More URL cleanup.
Fixed potential bugs.
Cleaned up QA complaints.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -183,8 +183,8 @@
         Reporter.grabAWTExecptions(true);
 
         // Splash screen
-        URI predicturl = PROJECT.getWritablePropertiesURI(SPLASH_PROPS);
-        Progress startJob = JobManager.createJob(Msg.STARTUP_TITLE.toString(), predicturl, true);
+        URI predictURI = PROJECT.getWritablePropertiesURI(SPLASH_PROPS);
+        Progress startJob = JobManager.createJob(Msg.STARTUP_TITLE.toString(), predictURI, true);
 
         //startJob.setProgress(Msg.STARTUP_CONFIG.toString());
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -477,7 +477,7 @@
             try
             {
                 //org.crosswire.common.aqua.OSXAdapter.registerMacOSXApplication(actions, DesktopActions.ABOUT, DesktopActions.OPTIONS, DesktopActions.EXIT);
-                
+
                 Class osxAdapter = ClassLoader.getSystemClassLoader().loadClass("org.crosswire.common.aqua.OSXAdapter"); //$NON-NLS-1$
 
                 Class[] defRegisterArgs = { Actionable.class, String.class, String.class, String.class };
@@ -492,7 +492,7 @@
                 Method prefsEnableMethod = osxAdapter.getDeclaredMethod("enablePrefs", defEnablePrefArgs); //$NON-NLS-1$
                 if (prefsEnableMethod != null)
                 {
-                    Object args[] = { Boolean.TRUE };
+                    Object[] args = { Boolean.TRUE };
                     prefsEnableMethod.invoke(osxAdapter, args);
                 }
             }

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/StatusBar.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/StatusBar.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/StatusBar.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -111,14 +111,14 @@
     public void enterURI(URIEvent ev)
     {
         String protocol = ev.getScheme();
-        String URI = ev.getURI();
+        String uri = ev.getURI();
         if (protocol.length() == 0)
         {
-            labelMessage.setText(URI);
+            labelMessage.setText(uri);
         }
         else
         {
-            labelMessage.setText(protocol + "://" + URI); //$NON-NLS-1$
+            labelMessage.setText(protocol + "://" + uri); //$NON-NLS-1$
         }
     }
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -100,7 +100,7 @@
             osissep.provideSAXEvents(osis);
 
             TransformingSAXEventProvider htmlsep = (TransformingSAXEventProvider) converter.convert(osissep);
-  
+
             XSLTProperty.DIRECTION.setState(bmd.isLeftToRight() ? "ltr" : "rtl"); //$NON-NLS-1$ //$NON-NLS-2$
 
             URI loc = bmd.getLocation();

Deleted: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEvent.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEvent.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEvent.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -1,70 +0,0 @@
-/**
- * Distribution License:
- * BibleDesktop is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, version 2 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * The License is available on the internet at:
- *       http://www.gnu.org/copyleft/gpl.html
- * or by writing to:
- *      Free Software Foundation, Inc.
- *      59 Temple Place - Suite 330
- *      Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- *     The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.bibledesktop.display;
-
-import java.util.EventObject;
-
-/**
- * A URLEvent happens whenever a user changes an URL.
- * 
- * @see gnu.gpl.License for license details.
- *      The copyright to this program is held by it's authors.
- * @author DM Smith [dmsmith555 at yahoo dot com]
- */
-public class URLEvent extends EventObject
-{
-    /**
-     * For when a command has been made
-     * @param source The thing that started this off
-     */
-    public URLEvent(Object source, String protocol, String url)
-    {
-        super(source);
-
-        this.protocol = protocol;
-        this.url = url;
-    }
-
-    /**
-     * @return Returns the protocol.
-     */
-    public String getProtocol()
-    {
-        return protocol;
-    }
-
-    /**
-     * @return Returns the url.
-     */
-    public String getURL()
-    {
-        return url;
-    }
-
-    private String protocol;
-    private String url;
-
-    /**
-     * Serialization ID
-     */
-    private static final long serialVersionUID = 3978710575457187634L;
-}

Deleted: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEventListener.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEventListener.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/URLEventListener.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -1,53 +0,0 @@
-/**
- * Distribution License:
- * BibleDesktop is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, version 2 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * The License is available on the internet at:
- *       http://www.gnu.org/copyleft/gpl.html
- * or by writing to:
- *      Free Software Foundation, Inc.
- *      59 Temple Place - Suite 330
- *      Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- *     The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.bibledesktop.display;
-
-import java.util.EventListener;
-
-/**
- * Implement URLEventListener to recieve URLEvents whenever someone
- * activates an URL.
- * 
- * @see gnu.gpl.License for license details.
- *      The copyright to this program is held by it's authors.
- * @author DM Smith [dmsmith555 at yahoo dot com]
- */
-public interface URLEventListener extends EventListener
-{
-    /**
-     * This method is called to indicate that an URL can be processed.
-     * @param ev Describes the URL
-     */
-    void activateURL(URLEvent ev);
-
-    /**
-     * This method is called to indicate that the mouse has entered the URL.
-     * @param ev Describes the URL
-     */
-    void enterURL(URLEvent ev);
-
-    /**
-     * This method is called to indicate that the mouse has left the URL.
-     * @param ev Describes the URL
-     */
-    void leaveURL(URLEvent ev);
-}

Modified: trunk/common/src/main/java/org/crosswire/common/config/Config.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/Config.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common/src/main/java/org/crosswire/common/config/Config.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -23,9 +23,9 @@
 
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URI;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -33,8 +33,10 @@
 import java.util.ResourceBundle;
 
 import org.crosswire.common.util.EventListenerList;
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.LucidException;
+import org.crosswire.common.util.NetUtil;
 import org.crosswire.common.util.Reporter;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -428,13 +430,23 @@
     /**
      * Take the data stored permanently and copy it to the local
      * storage area, using the configured storage area
+     * @throws IOException 
      */
-    public void permanentToLocal(URL url) throws IOException
+    public void permanentToLocal(URI uri) throws IOException
     {
-        Properties prop = new Properties();
-        prop.load(url.openStream());
-
-        setProperties(prop);
+        InputStream is = null;
+        try
+        {
+            is = NetUtil.getInputStream(uri);
+            Properties prop = new Properties();
+            prop.load(is);
+            is.close();
+            setProperties(prop);
+        }
+        finally
+        {
+            IOUtil.close(is);
+        }
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/progress/Job.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/progress/Job.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common/src/main/java/org/crosswire/common/progress/Job.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -35,6 +35,7 @@
 import java.util.Timer;
 import java.util.TimerTask;
 
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
 
@@ -53,7 +54,7 @@
      * @param description Short description of this job
      * @param predicturl Optional URI to save/load prediction times from
      * @param worker Optional thread to use in request to stop worker
-     * @param totalwork the size of the work to do
+     * @param totalWork the size of the work to do
      */
     protected Job(String description, URI predicturl, Thread worker, int totalWork)
     {
@@ -451,9 +452,10 @@
      */
     private synchronized void loadPredictions()
     {
+        InputStream in = null;
         try
         {
-            InputStream in = NetUtil.getInputStream(predictURI);
+            in = NetUtil.getInputStream(predictURI);
             if (in != null)
             {
                 predicted = new HashMap();
@@ -489,6 +491,10 @@
         {
             log.debug("Failed to load prediction times - guessing"); //$NON-NLS-1$
         }
+        finally
+        {
+            IOUtil.close(in);
+        }
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/util/CollectionUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/CollectionUtil.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common/src/main/java/org/crosswire/common/util/CollectionUtil.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -22,6 +22,7 @@
 package org.crosswire.common.util;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -96,9 +97,19 @@
 
     public static Map properties2Map(URI propUri) throws IOException
     {
-        Properties prop = new Properties();
-        prop.load(NetUtil.getInputStream(propUri));
-        return properties2Map(prop);
+        InputStream in = null;
+        try
+        {
+            in = NetUtil.getInputStream(propUri);
+            Properties prop = new Properties();
+            prop.load(in);
+            in.close();
+            return properties2Map(prop);
+        }
+        finally
+        {
+            IOUtil.close(in);
+        }
     }
 
 }

Modified: trunk/common/src/main/java/org/crosswire/common/util/IOUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/IOUtil.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common/src/main/java/org/crosswire/common/util/IOUtil.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -25,6 +25,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.RandomAccessFile;
+import java.io.Reader;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.util.Enumeration;
@@ -98,6 +100,25 @@
     }
 
     /**
+     * Close the random access file without complaining
+     * @param raf The random access file to close
+     */
+    public static void close(RandomAccessFile raf)
+    {
+        if (null != raf)
+        {
+            try
+            {
+                raf.close();
+            }
+            catch (IOException ex)
+            {
+                log.error("close", ex); //$NON-NLS-1$
+            }
+        }
+    }
+
+    /**
      * Close the stream whatever without complaining
      * @param out The stream to close
      */
@@ -136,6 +157,25 @@
     }
 
     /**
+     * Close the stream whatever without complaining
+     * @param in The stream to close
+     */
+    public static void close(Reader in)
+    {
+        if (null != in)
+        {
+            try
+            {
+                in.close();
+            }
+            catch (IOException ex)
+            {
+                log.error("close", ex); //$NON-NLS-1$
+            }
+        }
+    }
+
+    /**
      * The log stream
      */
     private static final Logger log = Logger.getLogger(IOUtil.class);

Modified: trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -566,32 +566,41 @@
     /**
      * List all the files specified by the index file passed in.
      * @return String[] Matching results.
+     * @throws FileNotFoundException 
      */
     public static String[] listByIndexFile(URI index, URLFilter filter) throws IOException
     {
-        InputStream in = NetUtil.getInputStream(index);
-        String contents = StringUtil.read(new InputStreamReader(in));
-
-        // We still need to do the filtering
-        List list = new ArrayList();
-        String[] names = StringUtil.split(contents, "\n"); //$NON-NLS-1$
-        for (int i = 0; i < names.length; i++)
+        InputStream in = null;
+        try
         {
-            // we need to trim, as we may have \r\n not \n
-            String name = names[i].trim();
+            in = NetUtil.getInputStream(index);
+            String contents = StringUtil.read(new InputStreamReader(in));
 
-            // to be acceptable it must be a non-0 length string, not commented
-            // with #, not the index file itself and acceptable by the filter.
-            if (name.length() > 0
-                && name.charAt(0) != '#'
-                && !name.equals(INDEX_FILE)
-                && filter.accept(name))
+            // We still need to do the filtering
+            List list = new ArrayList();
+            String[] names = StringUtil.split(contents, "\n"); //$NON-NLS-1$
+            for (int i = 0; i < names.length; i++)
             {
-                list.add(name);
+                // we need to trim, as we may have \r\n not \n
+                String name = names[i].trim();
+
+                // to be acceptable it must be a non-0 length string, not commented
+                // with #, not the index file itself and acceptable by the filter.
+                if (name.length() > 0
+                    && name.charAt(0) != '#'
+                    && !name.equals(INDEX_FILE)
+                    && filter.accept(name))
+                {
+                    list.add(name);
+                }
             }
+
+            return (String[]) list.toArray(new String[list.size()]);
         }
-
-        return (String[]) list.toArray(new String[list.size()]);
+        finally
+        {
+            IOUtil.close(in);
+        }
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -42,6 +42,7 @@
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
 
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
 import org.xml.sax.ContentHandler;
@@ -68,8 +69,9 @@
 
     /**
      * Compile the XSL or retrieve it from the cache
+     * @throws IOException 
      */
-    private TemplateInfo getTemplateInfo() throws IOException, TransformerConfigurationException
+    private TemplateInfo getTemplateInfo() throws TransformerConfigurationException, IOException
     {
         long modtime = NetUtil.getLastModified(xsluri);
 
@@ -88,12 +90,20 @@
         {
             log.debug("generating templates for " + xsluri); //$NON-NLS-1$
 
-            InputStream xsl_in = NetUtil.getInputStream(xsluri);
-            Templates templates = transfact.newTemplates(new StreamSource(xsl_in));
+            InputStream xslStream = null;
+            try
+            {
+                xslStream = NetUtil.getInputStream(xsluri);
+                Templates templates = transfact.newTemplates(new StreamSource(xslStream));
 
-            tinfo = new TemplateInfo(templates, modtime);
+                tinfo = new TemplateInfo(templates, modtime);
 
-            txers.put(xsluri, tinfo);
+                txers.put(xsluri, tinfo);
+            }
+            finally
+            {
+                IOUtil.close(xslStream);
+            }
         }
 
         return tinfo;

Modified: trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -35,7 +35,7 @@
 {
     /**
      * Simple ctor
-     * @param xslurl The url of the stylesheet
+     * @param xsluri The url of the stylesheet
      */
     public TransformingSAXEventProviderConverter(URI xsluri)
     {

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/LookAndFeelUtil.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -106,17 +106,18 @@
     public static void setUIFont(FontUIResource f)
     {
         Enumeration keys = UIManager.getDefaults().keys();
-        while (keys.hasMoreElements()) {
-          Object key = keys.nextElement();
-          Object value = UIManager.get (key);
+        while (keys.hasMoreElements())
+        {
+            Object key = keys.nextElement();
+            Object value = UIManager.get(key);
 
-          if (value instanceof FontUIResource)
-          {
+            if (value instanceof FontUIResource)
+            {
 //              System.err.println(key + " = " + value);
-              UIManager.put (key, f);
-          }
+                UIManager.put(key, f);
+            }
         }
-    }    
+    }
 
     /**
      * The current PLAF

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -96,7 +96,7 @@
 
     /**
      * @param job
-     * @param url
+     * @param uri
      * @param dest
      * @throws LucidException
      */

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -205,19 +205,19 @@
     private byte[]            userData;
 
     /**
-     * The offset of the parent record in the offset. -1 means that there are no
+     * The offset of the parent record in the offset.<br/>-1 means that there are no
      * parents and this TreeNode is a root.
      */
     private int               parent;
 
     /**
-     * The offset of the next sibling record in the offset. -1 means that there is
+     * The offset of the next sibling record in the offset.<br/>-1 means that there is
      * no next sibling.
      */
     private int               nextSibling;
 
     /**
-     * The offset of the first child record in the offset. -1 means that there are
+     * The offset of the first child record in the offset.<br/>-1 means that there are
      * no children and this TreeNode is a leaf.
      */
     private int               firstChild;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/KeyIterator.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/KeyIterator.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/KeyIterator.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -65,7 +65,7 @@
     }
 
     public boolean hasNext()
-    {        
+    {
         prepare();
         return stack.size() != 0;
     }
@@ -90,7 +90,7 @@
         if (childNum == -1)
         {
             return peek.getParent();
-        }        
+        }
 
         stack.push(new Locator(peek.getParent().get(childNum)));
 
@@ -102,6 +102,9 @@
         throw new UnsupportedOperationException();
     }
 
+    /**
+     * A helper class that remembers where we've been and where we are.
+     */
     public static class Locator
     {
         private Key parent;
@@ -124,9 +127,9 @@
         /**
          * @param parent the parent to set
          */
-        public void setParent(Key children)
+        public void setParent(Key parent)
         {
-            this.parent = children;
+            this.parent = parent;
         }
 
         /**

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/jdbc/JDBCBookDriver.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -21,15 +21,19 @@
  */
 package org.crosswire.jsword.book.jdbc;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
-import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookException;
 import org.crosswire.jsword.book.basic.AbstractBookDriver;
 import org.crosswire.jsword.book.basic.BookRoot;
 
@@ -47,9 +51,11 @@
      */
     public Book[] getBooks()
     {
+        URI dir = null;
+        String[] names = null;
         try
         {
-            URI dir = BookRoot.findBibleRoot(getDriverName());
+            dir = BookRoot.findBibleRoot(getDriverName());
 
             if (!NetUtil.isDirectory(dir))
             {
@@ -57,7 +63,6 @@
                 return new Book[0];
             }
 
-            String[] names = null;
             if (dir == null)
             {
                 names = new String[0];
@@ -66,29 +71,48 @@
             {
                 names = NetUtil.list(dir, new NetUtil.IsDirectoryURIFilter(dir));
             }
+        }
+        catch (MalformedURLException e1)
+        {
+            names = new String[0];
+        }
+        catch (IOException e)
+        {
+            names = new String[0];
+        }
 
-            List books = new ArrayList();
+        List books = new ArrayList();
 
-            for (int i=0; i<names.length; i++)
+        for (int i = 0; i < names.length; i++)
+        {
+            URI url = NetUtil.lengthenURI(dir, names[i]);
+            URI propUri = NetUtil.lengthenURI(url, "bible.properties"); //$NON-NLS-1$
+            InputStream is = null;
+            try
             {
-                URI url = NetUtil.lengthenURI(dir, names[i]);
-                URI propUri = NetUtil.lengthenURI(url, "bible.properties"); //$NON-NLS-1$
-
+                is = NetUtil.getInputStream(propUri);
                 Properties prop = new Properties();
-                prop.load(NetUtil.getInputStream(propUri));
+                prop.load(is);
 
                 Book book = new JDBCBook(this, prop);
 
                 books.add(book);
             }
+            catch (IOException e)
+            {
+                continue;
+            }
+            catch (BookException e)
+            {
+                continue;
+            }
+            finally
+            {
+                IOUtil.close(is);
+            }
+        }
 
-            return (Book[]) books.toArray(new Book[books.size()]);
-        }
-        catch (Exception ex)
-        {
-            Reporter.informUser(this, ex);
-            return new Book[0];
-        }
+        return (Book[]) books.toArray(new Book[books.size()]);
     }
 
     /* (non-Javadoc)

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/Mem.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/Mem.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/Mem.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -26,6 +26,7 @@
 import java.io.OutputStream;
 import java.net.URI;
 
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.NetUtil;
 
 /**
@@ -110,6 +111,7 @@
 
     /**
      * Load the Resource from a named file
+     * @throws IOException 
      */
     public void load() throws IOException
     {
@@ -121,19 +123,25 @@
         // For the gzip version
         //String filename = raw.getDir()+leafname+".gz";
 
-        InputStream in = NetUtil.getInputStream(uri);
+        InputStream in = null;
+        try
+        {
+            in = NetUtil.getInputStream(uri);
 
-        // For the pkzip version
-        //ZipInputStream in = new ZipInputStream(new FileInputStream(filename));
-        //ZipEntry entry = in.getNextEntry();
-        //if (entry == null) throw new IOException("Empty ZIP file");
+            // For the pkzip version
+            //ZipInputStream in = new ZipInputStream(new FileInputStream(filename));
+            //ZipEntry entry = in.getNextEntry();
+            //if (entry == null) throw new IOException("Empty ZIP file");
 
-        // For the gzip version
-        //GZIPInputStream in = new GZIPInputStream(new FileInputStream(filename));
+            // For the gzip version
+            //GZIPInputStream in = new GZIPInputStream(new FileInputStream(filename));
 
-        load(in);
-
-        in.close();
+            load(in);
+        }
+        finally
+        {
+            IOUtil.close(in);
+        }
     }
 
     /**

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBookDriver.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBookDriver.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBookDriver.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -21,14 +21,17 @@
  */
 package org.crosswire.jsword.book.raw;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
-import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.Book;
 import org.crosswire.jsword.book.basic.AbstractBookDriver;
 import org.crosswire.jsword.book.basic.BookRoot;
@@ -47,9 +50,11 @@
      */
     public Book[] getBooks()
     {
+        URI dir = null;
+        String[] names = null;
         try
         {
-            URI dir = BookRoot.findBibleRoot(getDriverName());
+            dir = BookRoot.findBibleRoot(getDriverName());
 
             if (!NetUtil.isDirectory(dir))
             {
@@ -57,7 +62,6 @@
                 return new Book[0];
             }
 
-            String[] names = null;
             if (dir == null)
             {
                 names = new String[0];
@@ -66,14 +70,27 @@
             {
                 names = NetUtil.list(dir, new NetUtil.IsDirectoryURIFilter(dir));
             }
+        }
+        catch (MalformedURLException e1)
+        {
+            names = new String[0];
+        }
+        catch (IOException e)
+        {
+            names = new String[0];
+        }
 
-            List books = new ArrayList();
+        List books = new ArrayList();
 
-            for (int i=0; i<names.length; i++)
+        for (int i = 0; i < names.length; i++)
+        {
+            InputStream is = null;
+            try
             {
                 URI uri = NetUtil.lengthenURI(dir, names[i]);
                 URI propURI = NetUtil.lengthenURI(uri, RawConstants.FILE_BIBLE_PROPERTIES);
 
+                is = NetUtil.getInputStream(propURI);
                 Properties prop = new Properties();
                 prop.load(NetUtil.getInputStream(propURI));
 
@@ -81,14 +98,17 @@
 
                 books.add(book);
             }
+            catch (IOException e)
+            {
+                continue;
+            }
+            finally
+            {
+                IOUtil.close(is);
+            }
+        }
 
-            return (Book[]) books.toArray(new Book[books.size()]);
-        }
-        catch (Exception ex)
-        {
-            Reporter.informUser(this, ex);
-            return new Book[0];
-        }
+        return (Book[]) books.toArray(new Book[books.size()]);
     }
 
     /* (non-Javadoc)

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -22,6 +22,7 @@
 package org.crosswire.jsword.book.search.ser;
 
 import java.io.BufferedReader;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
@@ -40,6 +41,7 @@
 import org.crosswire.common.progress.JobManager;
 import org.crosswire.common.progress.Progress;
 import org.crosswire.common.util.FileUtil;
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
 import org.crosswire.common.util.Reporter;
@@ -342,14 +344,17 @@
      */
     public final void activate(Lock lock)
     {
+        URI dataUri = NetUtil.lengthenURI(uri, FILE_DATA);
+        URI indexUri = NetUtil.lengthenURI(uri, FILE_INDEX);
+        BufferedReader indexIn = null;
+
+        IOUtil.close(dataRaf);
         try
         {
-            URI dataUri = NetUtil.lengthenURI(uri, FILE_DATA);
             dataRaf = new RandomAccessFile(NetUtil.getAsFile(dataUri), FileUtil.MODE_READ);
-        
-            URI indexUri = NetUtil.lengthenURI(uri, FILE_INDEX);
-            BufferedReader indexIn = new BufferedReader(new InputStreamReader(NetUtil.getInputStream(indexUri)));
-        
+
+            indexIn = new BufferedReader(new InputStreamReader(NetUtil.getInputStream(indexUri)));
+
             while (true)
             {
                 String line = indexIn.readLine();
@@ -357,16 +362,16 @@
                 {
                     break;
                 }
-        
+
                 try
                 {
                     int colon1 = line.indexOf(":"); //$NON-NLS-1$
                     int colon2 = line.lastIndexOf(":"); //$NON-NLS-1$
                     String word = line.substring(0, colon1);
-        
+
                     long offset = Long.parseLong(line.substring(colon1 + 1, colon2));
                     int length = Integer.parseInt(line.substring(colon2 + 1));
-        
+
                     Section section = new Section(offset, length);
                     datamap.put(word, section);
                 }
@@ -376,10 +381,19 @@
                 }
             }
         }
+        catch (FileNotFoundException ex)
+        {
+            log.error("File not found exception", ex); //$NON-NLS-1$
+        }
         catch (IOException ex)
         {
-            log.error("Read failed on indexin", ex); //$NON-NLS-1$
+            log.error("IOException", ex); //$NON-NLS-1$
         }
+        finally
+        {
+            IOUtil.close(dataRaf);
+            IOUtil.close(indexIn);
+        }
 
         active = true;
     }

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/ser/BookDataCache.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/ser/BookDataCache.java	2007-05-03 19:36:51 UTC (rev 1311)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/ser/BookDataCache.java	2007-05-03 21:39:51 UTC (rev 1312)
@@ -33,6 +33,7 @@
 import org.crosswire.common.activate.Activator;
 import org.crosswire.common.activate.Lock;
 import org.crosswire.common.util.FileUtil;
+import org.crosswire.common.util.IOUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
 import org.crosswire.jsword.book.BookException;
@@ -68,17 +69,20 @@
      */
     public final void activate(Lock lock)
     {
+        dataUri = NetUtil.lengthenURI(uri, FILE_DATA);
+        indexUri = NetUtil.lengthenURI(uri, FILE_INDEX);
+
+        IOUtil.close(dataRaf);
+        IOUtil.close(indexIn);
         try
         {
             // Create blank indexes
             indexArr = new long[BibleInfo.versesInBible()];
         
             // Open the XML RAF
-            dataUri = NetUtil.lengthenURI(uri, FILE_DATA);
             dataRaf = new RandomAccessFile(NetUtil.getAsFile(dataUri), FileUtil.MODE_READ);
 
             // Open the index file
-            indexUri = NetUtil.lengthenURI(uri, FILE_INDEX);
             indexIn = new BufferedReader(new InputStreamReader(NetUtil.getInputStream(indexUri)));
 
             // Load the ascii XML index
@@ -118,6 +122,11 @@
         {
             log.warn("failed to open stream", ex); //$NON-NLS-1$
         }
+        finally
+        {
+            IOUtil.close(dataRaf);
+            IOUtil.close(indexIn);
+        }
     }
 
     /* (non-Javadoc)
@@ -125,14 +134,7 @@
      */
     public final void deactivate(Lock lock)
     {
-        try
-        {
-            indexIn.close();
-        }
-        catch (IOException ex)
-        {
-            log.warn("failed to close stream", ex); //$NON-NLS-1$
-        }
+        IOUtil.close(indexIn);
 
         active = false;
     }




More information about the jsword-svn mailing list