1*cd519653SAndrew Rist /************************************************************** 2*cd519653SAndrew Rist * 3*cd519653SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cd519653SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cd519653SAndrew Rist * distributed with this work for additional information 6*cd519653SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cd519653SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cd519653SAndrew Rist * "License"); you may not use this file except in compliance 9*cd519653SAndrew Rist * with the License. You may obtain a copy of the License at 10*cd519653SAndrew Rist * 11*cd519653SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*cd519653SAndrew Rist * 13*cd519653SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cd519653SAndrew Rist * software distributed under the License is distributed on an 15*cd519653SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cd519653SAndrew Rist * KIND, either express or implied. See the License for the 17*cd519653SAndrew Rist * specific language governing permissions and limitations 18*cd519653SAndrew Rist * under the License. 19*cd519653SAndrew Rist * 20*cd519653SAndrew Rist *************************************************************/ 21*cd519653SAndrew Rist 22cdf0e10cSrcweir package installer; 23cdf0e10cSrcweir 24cdf0e10cSrcweir import java.io.*; 25cdf0e10cSrcweir import java.util.*; 26cdf0e10cSrcweir import java.util.jar.*; 27cdf0e10cSrcweir //import org.xml.sax.*; 28cdf0e10cSrcweir //import org.w3c.dom.*; 29cdf0e10cSrcweir //import javax.xml.parsers.*; 30cdf0e10cSrcweir import java.net.URL; 31cdf0e10cSrcweir import java.net.JarURLConnection; 32cdf0e10cSrcweir //import javax.xml.parsers.*; 33cdf0e10cSrcweir import javax.swing.*; 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** 36cdf0e10cSrcweir * The <code>XmlUpdater</code> pulls a META-INF/converter.xml 37cdf0e10cSrcweir * file out of a jar file and parses it, providing access to this 38cdf0e10cSrcweir * information in a <code>Vector</code> of <code>ConverterInfo</code> 39cdf0e10cSrcweir * objects. 40cdf0e10cSrcweir * 41cdf0e10cSrcweir * @author Aidan Butler 42cdf0e10cSrcweir */ 43cdf0e10cSrcweir public class IdeUpdater extends Thread { 44cdf0e10cSrcweir 45cdf0e10cSrcweir private String classesPath = null; 46cdf0e10cSrcweir private String jarfilename; 47cdf0e10cSrcweir private String installPath; 48cdf0e10cSrcweir 49cdf0e10cSrcweir private JLabel statusLabel; 50cdf0e10cSrcweir 51cdf0e10cSrcweir private Vector listeners; 52cdf0e10cSrcweir private Thread internalThread; 53cdf0e10cSrcweir private boolean threadSuspended; 54cdf0e10cSrcweir private JProgressBar progressBar; 55cdf0e10cSrcweir 56cdf0e10cSrcweir private boolean isNetbeansPath = false; 57cdf0e10cSrcweir 58cdf0e10cSrcweir IdeUpdater(String installPath, JLabel statusLabel, JProgressBar pBar)59cdf0e10cSrcweir public IdeUpdater(String installPath, JLabel statusLabel, JProgressBar pBar) { 60cdf0e10cSrcweir 61cdf0e10cSrcweir if (installPath.endsWith(File.separator) == false) 62cdf0e10cSrcweir installPath += File.separator; 63cdf0e10cSrcweir 64cdf0e10cSrcweir //File jeditLauncher = new File( installPath + "jedit.jar" ); 65cdf0e10cSrcweir File netbeansLauncher = new File( installPath + "bin" ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir if( netbeansLauncher.isDirectory() ) { 68cdf0e10cSrcweir isNetbeansPath = true; 69cdf0e10cSrcweir installPath = installPath +"modules" + File.separator; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir /* 72cdf0e10cSrcweir else if( jeditLauncher.isFile() ){ 73cdf0e10cSrcweir isNetbeansPath = false; 74cdf0e10cSrcweir installPath = installPath + "jars" + File.separator; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir */ 77cdf0e10cSrcweir 78cdf0e10cSrcweir System.out.println( "IdeUpdater installPath is " + installPath + " isNetbeansPath is " + isNetbeansPath ); 79cdf0e10cSrcweir this.installPath = installPath; 80cdf0e10cSrcweir this.statusLabel = statusLabel; 81cdf0e10cSrcweir listeners = new Vector(); 82cdf0e10cSrcweir threadSuspended = false; 83cdf0e10cSrcweir progressBar=pBar; 84cdf0e10cSrcweir progressBar.setStringPainted(true); 85cdf0e10cSrcweir }// XmlUpdater 86cdf0e10cSrcweir 87cdf0e10cSrcweir checkStop()88cdf0e10cSrcweir public boolean checkStop() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir if (internalThread == Thread.currentThread()) 91cdf0e10cSrcweir return false; 92cdf0e10cSrcweir return true; 93cdf0e10cSrcweir }// checkStop 94cdf0e10cSrcweir 95cdf0e10cSrcweir checkSuspend()96cdf0e10cSrcweir public void checkSuspend() 97cdf0e10cSrcweir { 98cdf0e10cSrcweir if (threadSuspended) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir synchronized(this) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir while (threadSuspended) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir try { 105cdf0e10cSrcweir wait(); 106cdf0e10cSrcweir } catch (InterruptedException eInt) { 107cdf0e10cSrcweir //... 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir }// checkSuspend 113cdf0e10cSrcweir 114cdf0e10cSrcweir setSuspend()115cdf0e10cSrcweir public void setSuspend() 116cdf0e10cSrcweir { 117cdf0e10cSrcweir threadSuspended = true; 118cdf0e10cSrcweir }// setSuspend 119cdf0e10cSrcweir 120cdf0e10cSrcweir setResume()121cdf0e10cSrcweir public void setResume() 122cdf0e10cSrcweir { 123cdf0e10cSrcweir threadSuspended = false; 124cdf0e10cSrcweir notify(); 125cdf0e10cSrcweir }// setResume 126cdf0e10cSrcweir 127cdf0e10cSrcweir setStop()128cdf0e10cSrcweir public void setStop() 129cdf0e10cSrcweir { 130cdf0e10cSrcweir internalThread = null; 131cdf0e10cSrcweir }// setStop 132cdf0e10cSrcweir 133cdf0e10cSrcweir run()134cdf0e10cSrcweir public void run() { 135cdf0e10cSrcweir 136cdf0e10cSrcweir //InputStream istream; 137cdf0e10cSrcweir //URL url; 138cdf0e10cSrcweir //String fileName = null; 139cdf0e10cSrcweir 140cdf0e10cSrcweir internalThread = Thread.currentThread(); 141cdf0e10cSrcweir 142cdf0e10cSrcweir progressBar.setString("Unzipping Required Files"); 143cdf0e10cSrcweir ZipData zd = new ZipData("SFrameworkInstall.jar"); 144cdf0e10cSrcweir 145cdf0e10cSrcweir // Adding IDE support 146cdf0e10cSrcweir if( isNetbeansPath ) { 147cdf0e10cSrcweir if (!zd.extractEntry("ide/office.jar",installPath, statusLabel)) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir onInstallComplete(); 150cdf0e10cSrcweir return; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir else { 154cdf0e10cSrcweir if (!zd.extractEntry("ide/idesupport.jar",installPath, statusLabel)) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir onInstallComplete(); 157cdf0e10cSrcweir return; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir if (!zd.extractEntry("ide/OfficeScripting.jar",installPath, statusLabel)) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir onInstallComplete(); 162cdf0e10cSrcweir return; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir //System.out.println("About to call register"); 167cdf0e10cSrcweir //Register.register(installPath+File.separator, statusLabel, progressBar); 168cdf0e10cSrcweir 169cdf0e10cSrcweir statusLabel.setText("Installation Complete"); 170cdf0e10cSrcweir progressBar.setString("Installation Complete"); 171cdf0e10cSrcweir progressBar.setValue(10); 172cdf0e10cSrcweir onInstallComplete(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir }// run 175cdf0e10cSrcweir 176cdf0e10cSrcweir addInstallListener(InstallListener listener)177cdf0e10cSrcweir public void addInstallListener(InstallListener listener) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir listeners.addElement(listener); 180cdf0e10cSrcweir }// addInstallListener 181cdf0e10cSrcweir 182cdf0e10cSrcweir onInstallComplete()183cdf0e10cSrcweir private void onInstallComplete() 184cdf0e10cSrcweir { 185cdf0e10cSrcweir Enumeration e = listeners.elements(); 186cdf0e10cSrcweir while (e.hasMoreElements()) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir InstallListener listener = (InstallListener)e.nextElement(); 189cdf0e10cSrcweir listener.installationComplete(null); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir }// onInstallComplete 192cdf0e10cSrcweir 193cdf0e10cSrcweir }// XmlUpdater class 194