00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.openmobileis.bundle.update.terminal;
00027
00028 import java.io.File;
00029 import java.io.IOException;
00030 import java.util.Iterator;
00031 import java.util.jar.Attributes;
00032 import java.util.jar.JarFile;
00033 import java.util.jar.Attributes.Name;
00034
00035 import org.openmobileis.common.util.PersistentPropertiesManager;
00036 import org.openmobileis.common.util.file.FileUtilities;
00037
00045 public final class ApplicationUpdateJarUtil {
00046 public static String FULL_APP_UPDATE_NAME = "FWKFullAppUpdate";
00047 public static final Name VERSIONNAME = new Name("OpenMIS-AppUpdate-Version");
00048 public static final Name POSTINSTALLCLASS = new Name("OpenMIS-PostInstall-Class");
00049
00050 public static String APPLICATION_JAR_FILENAME ="fullapplication.jar";
00051 public static String jarDirectory = System.getProperty("user.dir") + File.separator + "temp/";
00052 public static String jarPath = ApplicationUpdateJarUtil.jarDirectory + File.separator + ApplicationUpdateJarUtil.APPLICATION_JAR_FILENAME;
00053
00054 private String version = "";
00055 private String installclass = "";
00056
00057 public static boolean updateStarted = false;
00058
00062 public ApplicationUpdateJarUtil() {
00063 File dir = new File(jarDirectory);
00064 if (!dir.exists()) {
00065 dir.mkdirs();
00066 }
00067 }
00068
00069 public static String getTerminalUpdateJarPath() {
00070 return ApplicationUpdateJarUtil.jarPath;
00071 }
00072
00073 public void readJarMetainf() throws IOException {
00074 String path = ApplicationUpdateJarUtil.getTerminalUpdateJarPath();
00075 File file = new File(path);
00076 if (file.exists()) {
00077 JarFile jarFile = new JarFile(path);
00078 try {
00079 if (jarFile.getManifest() != null) {
00080 Iterator iter = jarFile.getManifest().getMainAttributes().keySet().iterator();
00081 while (iter.hasNext()) {
00082 Attributes.Name attribute = (Attributes.Name) iter.next();
00083 if (attribute.equals(VERSIONNAME)) {
00084 this.version = jarFile.getManifest().getMainAttributes().getValue(attribute);
00085 PersistentPropertiesManager.getManager().saveProperty(ApplicationUpdateJarUtil.FULL_APP_UPDATE_NAME, "org.openmobileis.synchro.bundle.fullupdate.version", this.version);
00086 } else if (attribute.equals(POSTINSTALLCLASS)) {
00087 this.installclass = jarFile.getManifest().getMainAttributes().getValue(attribute);
00088 }
00089 }
00090 }
00091 } finally {
00092 if (jarFile != null) {
00093 try {
00094 jarFile.close();
00095 } catch (IOException ioe) {
00096 }
00097 }
00098 }
00099 }
00100 }
00101
00102 public String getJarVersion() throws IOException {
00103 if (this.version.length()==0) {
00104 this.readJarMetainf();
00105 }
00106 if (this.version.length()==0){
00107 this.version = PersistentPropertiesManager.getManager().getProperty(ApplicationUpdateJarUtil.FULL_APP_UPDATE_NAME, "org.openmobileis.synchro.bundle.fullupdate.version");
00108 if (this.version == null) {
00109 this.version = "";
00110 PersistentPropertiesManager.getManager().saveProperty(ApplicationUpdateJarUtil.FULL_APP_UPDATE_NAME, "org.openmobileis.synchro.bundle.fullupdate.version", this.version);
00111 }
00112 }
00113 return this.version;
00114 }
00115
00116 public void updateInstallClass() {
00117 if (this.installclass.length() > 0) {
00118 try {
00119 FullUpdatePostInstallInterface cl = (FullUpdatePostInstallInterface) Class.forName(this.installclass).newInstance();
00120 cl.updateInstall();
00121 } catch (Throwable ex) {
00122 ex.printStackTrace();
00123 }
00124 }
00125 }
00126
00127 public void deleteUpdateJar() {
00128 String path = System.getProperty("user.dir") + File.separator + "temp/" + ApplicationUpdateJarUtil.APPLICATION_JAR_FILENAME;
00129 File file = new File(path);
00130 if (file.exists()) {
00131 file.delete();
00132
00133 File metadir = new File(System.getProperty("user.dir")+"/"+"META-INF");
00134 if (metadir.exists()) {
00135 FileUtilities.deleteDir(metadir);
00136 }
00137 }
00138 }
00139
00140 public String getVersion() {
00141 return version;
00142 }
00143
00144 public void setVersion(String version) {
00145 this.version = version;
00146 }
00147
00148 public String getInstallclass() {
00149 return installclass;
00150 }
00151
00152 public void setInstallclass(String installclass) {
00153 this.installclass = installclass;
00154 }
00155
00156 }