| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 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 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 0 | public class HttpSwordInstallerFactory implements InstallerFactory { |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public Installer createInstaller() { |
| 43 | 0 | return new HttpSwordInstaller(); |
| 44 | |
} |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 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 | |
|
| 100 | |
|
| 101 | |
protected static final String PACKAGE_DIR = "packages/rawzip"; |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
private static final String LIST_DIR = "raw"; |
| 107 | |
|
| 108 | 0 | private Pattern commaPattern = Pattern.compile(","); |
| 109 | |
} |