[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/install/sword s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sun Oct 10 15:12:04 MST 2004


Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword
In directory www.crosswire.org:/tmp/cvs-serv25203/java/jsword/org/crosswire/jsword/book/install/sword

Modified Files:
	HttpSwordInstaller.java FtpSwordInstaller.java 
Log Message:
basics of downloadable indexers

Index: HttpSwordInstaller.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** HttpSwordInstaller.java	5 Oct 2004 22:03:09 -0000	1.10
--- HttpSwordInstaller.java	10 Oct 2004 22:12:02 -0000	1.11
***************
*** 14,27 ****
  import java.util.ArrayList;
  import java.util.Collections;
- import java.util.Enumeration;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.zip.GZIPInputStream;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipFile;
  
  import org.crosswire.common.progress.Job;
  import org.crosswire.common.progress.JobManager;
  import org.crosswire.common.util.Logger;
  import org.crosswire.common.util.NetUtil;
--- 14,25 ----
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.zip.GZIPInputStream;
  
  import org.crosswire.common.progress.Job;
  import org.crosswire.common.progress.JobManager;
+ import org.crosswire.common.util.IOUtil;
  import org.crosswire.common.util.Logger;
  import org.crosswire.common.util.NetUtil;
***************
*** 103,107 ****
       * @see org.crosswire.jsword.book.install.Installer#reloadIndex()
       */
!     public void reloadIndex() throws InstallException
      {
          URL scratchfile = getCachedIndexFile();
--- 101,105 ----
       * @see org.crosswire.jsword.book.install.Installer#reloadIndex()
       */
!     public void reloadBookList() throws InstallException
      {
          URL scratchfile = getCachedIndexFile();
***************
*** 144,171 ****
          finally
          {
!             if (null != in)
!             {
!                 try
!                 {
!                     in.close();
!                 }
!                 catch (IOException e)
!                 {
!                     e.printStackTrace();
!                 }
!             }
  
!             if (null != out)
!             {
!                 try
!                 {
!                     out.close();
!                 }
!                 catch (IOException e1)
!                 {
!                     e1.printStackTrace();
!                 }
!             }
          }
      }
  
--- 142,171 ----
          finally
          {
!             IOUtil.close(in);
!             IOUtil.close(out);
!         }
!     }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.install.Installer#downloadSearchIndex(org.crosswire.jsword.book.BookMetaData, java.net.URL)
!      */
!     public void downloadSearchIndex(BookMetaData bmd, URL localDest) throws InstallException
!     {
!         Job job = JobManager.createJob(Msg.JOB_DOWNLOADING.toString(), Thread.currentThread(), false);
! 
!         try
!         {
!             String dir = directory + '/' + SEARCH_DIR  + '/' + bmd.getInitials() + ZIP_SUFFIX;
!             downloadZip(job, host, dir, localDest);
          }
+         catch (Exception ex)
+         {
+             job.ignoreTimings();
+             throw new InstallException(Msg.UNKNOWN_ERROR, ex);
+         }
+         finally
+         {
+             job.done();
+         }                
      }
  
***************
*** 186,194 ****
--- 186,197 ----
          {
              job.setProgress(Msg.JOB_DOWNLOADING.toString());
+ 
              URL zipurl = new URL("http://" + site + dir); //$NON-NLS-1$
              File f = File.createTempFile("swd", "zip"); //$NON-NLS-1$ //$NON-NLS-2$
              out = new FileOutputStream(f);
+ 
              URLConnection urlConnection = zipurl.openConnection();
              in = urlConnection.getInputStream();
+ 
              byte[] buf = new byte[4096];
              for (int count = 0; -1 != (count = in.read(buf)); )
***************
*** 196,216 ****
                  out.write(buf, 0, count);
              }
!             // unpack the zip.
!             ZipFile zf = new ZipFile(f);
!             Enumeration entries = zf.entries();
!             while (entries.hasMoreElements())
!             {
!                 ZipEntry entry = (ZipEntry) entries.nextElement();
!                 String entrypath = entry.getName();
!                 String filename = entrypath.substring(entrypath.lastIndexOf('/') + 1);
!                 URL child = NetUtil.lengthenURL(destdir, filename);
!                 OutputStream dataOut = NetUtil.getOutputStream(child);
!                 InputStream dataIn = zf.getInputStream(entry);
!                 for (int count = 0; -1 != (count = dataIn.read(buf)); )
!                 {
!                     dataOut.write(buf, 0, count);
!                 }
!                 dataOut.close();
!             }
          }
          catch (IOException ex)
--- 199,204 ----
                  out.write(buf, 0, count);
              }
! 
!             IOUtil.unpackZip(f, destdir);
          }
          catch (IOException ex)
***************
*** 220,245 ****
          finally
          {
!             if (null != in)
!             {
!                 try
!                 {
!                     in.close();
!                 }
!                 catch (IOException ex)
!                 {
!                     ex.printStackTrace();
!                 }
!             }
!             if (null != out)
!             {
!                 try
!                 {
!                     out.close();
!                 }
!                 catch (IOException ex)
!                 {
!                     ex.printStackTrace();
!                 }
!             }
          }
      }
--- 208,213 ----
          finally
          {
!             IOUtil.close(in);
!             IOUtil.close(out);
          }
      }
***************
*** 326,330 ****
              return new URL(NetUtil.PROTOCOL_HTTP, host, directory + '/' + PACKAGE_DIR + '/' + sbmd.getInitials() + ZIP_SUFFIX); //$NON-NLS-1$
          }
!         catch (MalformedURLException e)
          {
              return null;
--- 294,298 ----
              return new URL(NetUtil.PROTOCOL_HTTP, host, directory + '/' + PACKAGE_DIR + '/' + sbmd.getInitials() + ZIP_SUFFIX); //$NON-NLS-1$
          }
!         catch (MalformedURLException ex)
          {
              return null;
***************
*** 342,346 ****
              return new URL(NetUtil.PROTOCOL_FILE, null, fulldir.getAbsolutePath());
          }
!         catch (MalformedURLException e)
          {
              assert false;
--- 310,314 ----
              return new URL(NetUtil.PROTOCOL_FILE, null, fulldir.getAbsolutePath());
          }
!         catch (MalformedURLException ex)
          {
              assert false;
***************
*** 492,497 ****
          if (!NetUtil.isFile(cache))
          {
!             reloadIndex();
          }
          try
          {
--- 460,466 ----
          if (!NetUtil.isFile(cache))
          {
!             reloadBookList();
          }
+ 
          try
          {
***************
*** 521,524 ****
--- 490,494 ----
                              internal = internal.substring(0, internal.length() - 5);
                          }
+ 
                          if (internal.startsWith(SwordConstants.DIR_CONF + '/'))
                          {
***************
*** 541,547 ****
              }
  
!             tin.close();
!             gin.close();
!             in.close();
              loaded = true;
          }
--- 511,518 ----
              }
  
!             IOUtil.close(tin);
!             IOUtil.close(gin);
!             IOUtil.close(in);
! 
              loaded = true;
          }
***************
*** 602,605 ****
--- 573,581 ----
  
      /**
+      * The relative path of the dir holding the search index files
+      */
+     private static final String SEARCH_DIR = "seach/jsword/L1"; //$NON-NLS-1$
+ 
+     /**
       * The suffix of zip modules on this server
       */

Index: FtpSwordInstaller.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/FtpSwordInstaller.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** FtpSwordInstaller.java	5 Oct 2004 22:03:09 -0000	1.7
--- FtpSwordInstaller.java	10 Oct 2004 22:12:02 -0000	1.8
***************
*** 224,230 ****
  
      /* (non-Javadoc)
       * @see org.crosswire.jsword.book.install.Installer#reloadIndex()
       */
!     public void reloadIndex() throws InstallException
      {
          URL scratchfile = getCachedIndexFile();
--- 224,253 ----
  
      /* (non-Javadoc)
+      * @see org.crosswire.jsword.book.install.Installer#downloadSearchIndex(org.crosswire.jsword.book.BookMetaData, java.net.URL)
+      */
+     public void downloadSearchIndex(BookMetaData bmd, URL localDest) throws InstallException
+     {
+         Job job = JobManager.createJob(Msg.JOB_DOWNLOADING.toString(), Thread.currentThread(), false);
+ 
+         try
+         {
+             String dir = directory + '/' + SEARCH_DIR;
+             download(host, USERNAME, PASSWORD, dir, bmd.getInitials() + ZIP_SUFFIX, localDest);
+         }
+         catch (Exception ex)
+         {
+             job.ignoreTimings();
+             throw new InstallException(Msg.UNKNOWN_ERROR, ex);
+         }
+         finally
+         {
+             job.done();
+         }                
+     }
+ 
+     /* (non-Javadoc)
       * @see org.crosswire.jsword.book.install.Installer#reloadIndex()
       */
!     public void reloadBookList() throws InstallException
      {
          URL scratchfile = getCachedIndexFile();
***************
*** 243,247 ****
          if (!NetUtil.isFile(cache))
          {
!             reloadIndex();
          }
          try
--- 266,270 ----
          if (!NetUtil.isFile(cache))
          {
!             reloadBookList();
          }
          try
***************
*** 693,696 ****
--- 716,724 ----
  
      /**
+      * The relative path of the dir holding the search index files
+      */
+     private static final String SEARCH_DIR = "seach/jsword/L1"; //$NON-NLS-1$
+ 
+     /**
       * The default anon password
       */



More information about the jsword-svn mailing list