1*cdf0e10cSrcweir package installer;
2*cdf0e10cSrcweir 
3*cdf0e10cSrcweir import java.io.*;
4*cdf0e10cSrcweir import java.util.*;
5*cdf0e10cSrcweir import java.util.jar.*;
6*cdf0e10cSrcweir //import org.xml.sax.*;
7*cdf0e10cSrcweir //import org.w3c.dom.*;
8*cdf0e10cSrcweir //import javax.xml.parsers.*;
9*cdf0e10cSrcweir import java.net.URL;
10*cdf0e10cSrcweir import java.net.JarURLConnection;
11*cdf0e10cSrcweir //import javax.xml.parsers.*;
12*cdf0e10cSrcweir import javax.swing.*;
13*cdf0e10cSrcweir 
14*cdf0e10cSrcweir /**
15*cdf0e10cSrcweir  *  The <code>XmlUpdater</code> pulls a META-INF/converter.xml
16*cdf0e10cSrcweir  *  file out of a jar file and parses it, providing access to this
17*cdf0e10cSrcweir  *  information in a <code>Vector</code> of <code>ConverterInfo</code>
18*cdf0e10cSrcweir  *  objects.
19*cdf0e10cSrcweir  *
20*cdf0e10cSrcweir  *  @author  Aidan Butler
21*cdf0e10cSrcweir  */
22*cdf0e10cSrcweir public class IdeUpdater extends Thread {
23*cdf0e10cSrcweir 
24*cdf0e10cSrcweir     private String classesPath = null;
25*cdf0e10cSrcweir     private String jarfilename;
26*cdf0e10cSrcweir     private String installPath;
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir     private JLabel statusLabel;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir     private Vector listeners;
31*cdf0e10cSrcweir     private Thread internalThread;
32*cdf0e10cSrcweir     private boolean threadSuspended;
33*cdf0e10cSrcweir     private JProgressBar progressBar;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir     private boolean isNetbeansPath = false;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir     public IdeUpdater(String installPath, JLabel statusLabel, JProgressBar pBar) {
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir         if (installPath.endsWith(File.separator) == false)
41*cdf0e10cSrcweir             installPath += File.separator;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 	//File jeditLauncher = new File( installPath + "jedit.jar" );
44*cdf0e10cSrcweir 	File netbeansLauncher = new File( installPath + "bin" );
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 	if( netbeansLauncher.isDirectory() ) {
47*cdf0e10cSrcweir 		isNetbeansPath = true;
48*cdf0e10cSrcweir 		installPath = installPath +"modules" + File.separator;
49*cdf0e10cSrcweir 	}
50*cdf0e10cSrcweir 	/*
51*cdf0e10cSrcweir 	else if( jeditLauncher.isFile() ){
52*cdf0e10cSrcweir 		isNetbeansPath =  false;
53*cdf0e10cSrcweir 		installPath = installPath + "jars" + File.separator;
54*cdf0e10cSrcweir 	}
55*cdf0e10cSrcweir 	*/
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 	System.out.println( "IdeUpdater installPath is " + installPath + " isNetbeansPath is " + isNetbeansPath );
58*cdf0e10cSrcweir         this.installPath = installPath;
59*cdf0e10cSrcweir         this.statusLabel = statusLabel;
60*cdf0e10cSrcweir 	listeners = new Vector();
61*cdf0e10cSrcweir 	threadSuspended = false;
62*cdf0e10cSrcweir 	progressBar=pBar;
63*cdf0e10cSrcweir 	progressBar.setStringPainted(true);
64*cdf0e10cSrcweir     }// XmlUpdater
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	public boolean checkStop()
68*cdf0e10cSrcweir 	{
69*cdf0e10cSrcweir             if (internalThread == Thread.currentThread())
70*cdf0e10cSrcweir                 return false;
71*cdf0e10cSrcweir             return true;
72*cdf0e10cSrcweir 	}// checkStop
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 	public void checkSuspend()
76*cdf0e10cSrcweir 	{
77*cdf0e10cSrcweir             if (threadSuspended)
78*cdf0e10cSrcweir             {
79*cdf0e10cSrcweir 		synchronized(this)
80*cdf0e10cSrcweir 		{
81*cdf0e10cSrcweir                     while (threadSuspended)
82*cdf0e10cSrcweir                     {
83*cdf0e10cSrcweir                         try	{
84*cdf0e10cSrcweir                             wait();
85*cdf0e10cSrcweir                         } catch (InterruptedException eInt) {
86*cdf0e10cSrcweir                             //...
87*cdf0e10cSrcweir                         }
88*cdf0e10cSrcweir                     }
89*cdf0e10cSrcweir 		}
90*cdf0e10cSrcweir             }
91*cdf0e10cSrcweir 	}// checkSuspend
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	public void setSuspend()
95*cdf0e10cSrcweir 	{
96*cdf0e10cSrcweir             threadSuspended = true;
97*cdf0e10cSrcweir 	}// setSuspend
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	public void setResume()
101*cdf0e10cSrcweir 	{
102*cdf0e10cSrcweir             threadSuspended = false;
103*cdf0e10cSrcweir             notify();
104*cdf0e10cSrcweir 	}// setResume
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	public void setStop()
108*cdf0e10cSrcweir 	{
109*cdf0e10cSrcweir             internalThread = null;
110*cdf0e10cSrcweir 	}// setStop
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     public void run() {
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         //InputStream istream;
116*cdf0e10cSrcweir         //URL url;
117*cdf0e10cSrcweir         //String fileName = null;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	internalThread = Thread.currentThread();
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	progressBar.setString("Unzipping Required Files");
122*cdf0e10cSrcweir         ZipData zd = new ZipData("SFrameworkInstall.jar");
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	// Adding IDE support
125*cdf0e10cSrcweir 	if( isNetbeansPath ) {
126*cdf0e10cSrcweir 		if (!zd.extractEntry("ide/office.jar",installPath, statusLabel))
127*cdf0e10cSrcweir         	{
128*cdf0e10cSrcweir 			onInstallComplete();
129*cdf0e10cSrcweir 			return;
130*cdf0e10cSrcweir 		}
131*cdf0e10cSrcweir 	}
132*cdf0e10cSrcweir 	else {
133*cdf0e10cSrcweir 		if (!zd.extractEntry("ide/idesupport.jar",installPath, statusLabel))
134*cdf0e10cSrcweir         	{
135*cdf0e10cSrcweir 			onInstallComplete();
136*cdf0e10cSrcweir 			return;
137*cdf0e10cSrcweir 		}
138*cdf0e10cSrcweir 		if (!zd.extractEntry("ide/OfficeScripting.jar",installPath, statusLabel))
139*cdf0e10cSrcweir         	{
140*cdf0e10cSrcweir 			onInstallComplete();
141*cdf0e10cSrcweir 			return;
142*cdf0e10cSrcweir 		}
143*cdf0e10cSrcweir 	}
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir         //System.out.println("About to call register");
146*cdf0e10cSrcweir 	//Register.register(installPath+File.separator, statusLabel, progressBar);
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	statusLabel.setText("Installation Complete");
149*cdf0e10cSrcweir 	progressBar.setString("Installation Complete");
150*cdf0e10cSrcweir 	progressBar.setValue(10);
151*cdf0e10cSrcweir 	onInstallComplete();
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     }// run
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     public void addInstallListener(InstallListener listener)
157*cdf0e10cSrcweir     {
158*cdf0e10cSrcweir         listeners.addElement(listener);
159*cdf0e10cSrcweir     }// addInstallListener
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     private void onInstallComplete()
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         Enumeration e = listeners.elements();
165*cdf0e10cSrcweir         while (e.hasMoreElements())
166*cdf0e10cSrcweir         {
167*cdf0e10cSrcweir             InstallListener listener = (InstallListener)e.nextElement();
168*cdf0e10cSrcweir             listener.installationComplete(null);
169*cdf0e10cSrcweir         }
170*cdf0e10cSrcweir     }// onInstallComplete
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir }// XmlUpdater class
173