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