Coverage Report - org.crosswire.jsword.book.install.sword.HttpSwordInstallerFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpSwordInstallerFactory
0%
0/26
0%
0/11
3.25
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2005 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.book.install.sword;
 21  
 
 22  
 import java.util.regex.Pattern;
 23  
 
 24  
 import org.crosswire.jsword.JSOtherMsg;
 25  
 import org.crosswire.jsword.book.install.Installer;
 26  
 import org.crosswire.jsword.book.install.InstallerFactory;
 27  
 
 28  
 /**
 29  
  * A Factory for instances of HttpSwordInstaller.
 30  
  * 
 31  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 32  
  * @author Mark Goodwin
 33  
  * @author Joe Walker
 34  
  * @author DM Smith
 35  
  */
 36  0
 public class HttpSwordInstallerFactory implements InstallerFactory {
 37  
     /*
 38  
      * (non-Javadoc)
 39  
      * 
 40  
      * @see org.crosswire.jsword.book.install.InstallerFactory#createInstaller()
 41  
      */
 42  
     public Installer createInstaller() {
 43  0
         return new HttpSwordInstaller();
 44  
     }
 45  
 
 46  
     /*
 47  
      * (non-Javadoc)
 48  
      * 
 49  
      * @see
 50  
      * org.crosswire.jsword.book.install.InstallerFactory#createInstaller(java
 51  
      * .lang.String)
 52  
      */
 53  
     public Installer createInstaller(String installerDefinition) {
 54  0
         String[] parts = commaPattern.split(installerDefinition, 6);
 55  0
         switch (parts.length) {
 56  
         case 4:
 57  0
             return createOldInstaller(parts);
 58  
         case 6:
 59  0
             return createInstaller(parts);
 60  
         default:
 61  0
             throw new IllegalArgumentException(JSOtherMsg.lookupText("Not enough / symbols in url: {0}", installerDefinition));
 62  
         }
 63  
 
 64  
     }
 65  
 
 66  
     private Installer createInstaller(String[] parts) {
 67  0
         AbstractSwordInstaller reply = new HttpSwordInstaller();
 68  
 
 69  0
         reply.setHost(parts[0]);
 70  0
         reply.setPackageDirectory(parts[1]);
 71  0
         reply.setCatalogDirectory(parts[2]);
 72  0
         if (parts[3].length() > 0) {
 73  0
             reply.setProxyHost(parts[3]);
 74  0
             if (parts[4].length() > 0) {
 75  0
                 reply.setProxyPort(Integer.valueOf(parts[4]));
 76  
             }
 77  
         }
 78  
 
 79  0
         return reply;
 80  
     }
 81  
 
 82  
     private Installer createOldInstaller(String[] parts) {
 83  0
         AbstractSwordInstaller reply = new HttpSwordInstaller();
 84  
 
 85  0
         reply.setHost(parts[0]);
 86  0
         reply.setPackageDirectory(parts[1] + '/' + PACKAGE_DIR);
 87  0
         reply.setCatalogDirectory(parts[1] + '/' + LIST_DIR);
 88  0
         if (parts[2].length() > 0) {
 89  0
             reply.setProxyHost(parts[2]);
 90  0
             if (parts[3].length() > 0) {
 91  0
                 reply.setProxyPort(Integer.valueOf(parts[3]));
 92  
             }
 93  
         }
 94  
 
 95  0
         return reply;
 96  
     }
 97  
 
 98  
     /**
 99  
      * The relative path of the dir holding the zip files
 100  
      */
 101  
     protected static final String PACKAGE_DIR = "packages/rawzip";
 102  
 
 103  
     /**
 104  
      * The relative path of the dir holding the index file
 105  
      */
 106  
     private static final String LIST_DIR = "raw";
 107  
 
 108  0
     private Pattern commaPattern = Pattern.compile(",");
 109  
 }