merge the formfield patch from ooo-build
[ooovba.git] / scripting / workben / installer / XmlUpdater.java
blob4c83828831e13930368e67f5969338606706031a
1 package installer;
3 import java.io.*;
4 import java.util.*;
5 import java.util.jar.*;
6 import java.net.URL;
7 import java.net.JarURLConnection;
8 import javax.swing.*;
10 /**
13 * @author Aidan Butler
15 public class XmlUpdater extends Thread {
17 private String classesPath = null;
18 private String jarfilename;
19 private String installPath;
20 private boolean netInstall;
21 private boolean bindingsInstall;
23 private JLabel statusLabel;
25 private Vector listeners;
26 private Thread internalThread;
27 private boolean threadSuspended;
28 private JProgressBar progressBar;
30 private final String[] bakFiles =
32 "writermenubar.xml",
33 "writerkeybinding.xml",
34 "calcmenubar.xml",
35 "calckeybinding.xml",
36 "impressmenubar.xml",
37 "impresskeybinding.xml",
38 "drawmenubar.xml",
39 "drawkeybinding.xml",
40 "eventbindings.xml",
41 "META-INF" + File.separator + "manifest.xml"
44 private final String[] dirs =
46 "java" + File.separator + "Highlight",
47 "java" + File.separator + "MemoryUsage",
48 "java" + File.separator + "ScriptFrmwrkHelper",
49 "java" + File.separator + "debugger",
50 "java" + File.separator + "debugger" + File.separator + "rhino",
51 "beanshell" + File.separator + "InteractiveBeanShell",
52 "beanshell" + File.separator + "Highlight",
53 "beanshell" + File.separator + "MemoryUsage",
54 "javascript" + File.separator + "ExportSheetsToHTML"
57 private final String[] names =
59 "java/Highlight/HighlightUtil.java",
60 "java/Highlight/HighlightText.java",
61 "java/Highlight/Highlight.jar",
62 "java/Highlight/parcel-descriptor.xml",
63 "java/MemoryUsage/MemoryUsage.java",
64 "java/MemoryUsage/MemoryUsage.class",
65 "java/MemoryUsage/parcel-descriptor.xml",
66 "java/MemoryUsage/ExampleSpreadSheet.sxc",
67 "java/ScriptFrmwrkHelper/parcel-descriptor.xml",
68 "java/ScriptFrmwrkHelper/ScriptFrmwrkHelper.java",
69 "java/ScriptFrmwrkHelper/ScriptFrmwrkHelper.class",
70 "java/ScriptFrmwrkHelper/ScriptFrmwrkHelper.jar",
71 "java/debugger/debugger.jar",
72 "java/debugger/OOBeanShellDebugger.java",
73 "java/debugger/OOScriptDebugger.java",
74 "java/debugger/DebugRunner.java",
75 "java/debugger/OORhinoDebugger.java",
76 "java/debugger/parcel-descriptor.xml",
77 "java/debugger/rhino/Main.java",
78 "beanshell/InteractiveBeanShell/parcel-descriptor.xml",
79 "beanshell/InteractiveBeanShell/interactive.bsh",
80 "beanshell/Highlight/parcel-descriptor.xml",
81 "beanshell/Highlight/highlighter.bsh",
82 "beanshell/MemoryUsage/parcel-descriptor.xml",
83 "beanshell/MemoryUsage/memusage.bsh",
84 "javascript/ExportSheetsToHTML/parcel-descriptor.xml",
85 "javascript/ExportSheetsToHTML/exportsheetstohtml.js"
89 public XmlUpdater(String installPath, JLabel statusLabel,JProgressBar pBar, boolean netInstall, boolean bindingsInstall) {
90 this.installPath = installPath;
91 this.statusLabel = statusLabel;
92 this.netInstall = netInstall;
93 this.bindingsInstall = bindingsInstall;
94 listeners = new Vector();
95 threadSuspended = false;
96 progressBar=pBar;
97 progressBar.setStringPainted(true);
98 }// XmlUpdater
101 public boolean checkStop()
103 if (internalThread == Thread.currentThread())
104 return false;
105 return true;
106 }// checkStop
109 public void checkSuspend()
111 if (threadSuspended) {
112 synchronized(this) {
113 while (threadSuspended) {
114 try {
115 wait();
116 } catch (InterruptedException eInt) {
117 //...
122 }// checkSuspend
125 public void setSuspend()
127 threadSuspended = true;
128 }// setSuspend
131 public void setResume()
133 threadSuspended = false;
134 notify();
135 }// setResume
138 public void setStop()
140 internalThread = null;
141 }// setStop
144 public void run() {
146 InputStream istream;
147 //InputSource isource;
148 //DocumentBuilderFactory builderFactory;
149 //DocumentBuilder builder = null;
150 URL url;
151 String fileName = null;
153 internalThread = Thread.currentThread();
155 //System.out.println("\n\n\n\nFileName: "+installPath);
156 classesPath= installPath.concat(File.separator+"program"+File.separator+"classes"+File.separator);
157 String opSys =System.getProperty("os.name");
158 //System.out.println("\n System "+opSys);
160 String progpath=installPath;
161 progpath= progpath.concat(File.separator+"program"+File.separator);
162 //System.out.println("Office progpath" + progpath );
163 //System.out.println("\nModifying Installation "+installPath);
165 String starBasicPath=installPath;
166 starBasicPath= starBasicPath.concat(File.separator+"share"+File.separator+"basic"+File.separator+"ScriptBindingLibrary"+File.separator);
167 //System.out.println( "Office StarBasic path: " + starBasicPath );
169 String regSchemaOfficePath=installPath;
170 regSchemaOfficePath= regSchemaOfficePath.concat(File.separator+"share"+File.separator+"registry"+File.separator+"schema"+File.separator+"org"+File.separator+"openoffice"+File.separator+"Office"+File.separator);
171 //System.out.println( "Office schema path: " + regSchemaOfficePath );
173 // Get the NetBeans installation
174 //String netbeansPath=
176 progressBar.setString("Unzipping Required Files");
177 ZipData zd = new ZipData("SFrameworkInstall.jar");
180 if( (!netInstall) || bindingsInstall) {
181 String configPath=installPath;
182 configPath= configPath.concat(File.separator+"user"+File.separator+"config"+File.separator+"soffice.cfg"+File.separator);
183 //System.out.println( "Office configuration path: " + configPath );
184 String manifestPath=configPath + "META-INF" + File.separator;
186 //Adding <Office>/user/config/soffice.cfg/
187 File configDir = new File( configPath );
188 if( !configDir.isDirectory() ) {
189 if( !configDir.mkdir() ) {
190 System.out.println( "creating " + configDir + "directory failed");
192 else {
193 System.out.println( configDir + "directory created");
196 else
197 System.out.println( "soffice.cfg exists" );
199 File manifestDir = new File( manifestPath );
200 if( !manifestDir.isDirectory() ) {
201 if( !manifestDir.mkdir() ) {
202 System.out.println( "creating " + manifestPath + "directory failed");
204 else {
205 System.out.println( manifestPath + " directory created");
208 else
209 System.out.println( manifestPath + " exists" );
211 // Backup the confguration files in
212 // <office>/user/config/soffice.cfg/
213 // If they already exist.
215 for( int i=0; i < bakFiles.length; i++ )
217 String pathNameBak = configPath + bakFiles[i];
218 File origFile = new File( pathNameBak );
219 if( origFile.exists() )
221 System.out.println( "Attempting to backup " + pathNameBak + " to " + pathNameBak + ".bak" );
222 if(! origFile.renameTo( new File( pathNameBak + ".bak" ) ) )
224 System.out.println( "Failed to backup " + pathNameBak + " to " + pathNameBak + ".bak" );
229 // Adding Office configuration files
230 if (!zd.extractEntry("bindingdialog/writermenubar.xml",configPath, statusLabel))
232 onInstallComplete();
233 return;
235 if (!zd.extractEntry("bindingdialog/writerkeybinding.xml",configPath, statusLabel))
237 onInstallComplete();
238 return;
240 if (!zd.extractEntry("bindingdialog/calcmenubar.xml",configPath, statusLabel))
242 onInstallComplete();
243 return;
245 if (!zd.extractEntry("bindingdialog/calckeybinding.xml",configPath, statusLabel))
247 onInstallComplete();
248 return;
250 if (!zd.extractEntry("bindingdialog/impressmenubar.xml",configPath, statusLabel))
252 onInstallComplete();
253 return;
255 if (!zd.extractEntry("bindingdialog/impresskeybinding.xml",configPath, statusLabel))
257 onInstallComplete();
258 return;
260 if (!zd.extractEntry("bindingdialog/drawmenubar.xml",configPath, statusLabel))
262 onInstallComplete();
263 return;
265 if (!zd.extractEntry("bindingdialog/drawkeybinding.xml",configPath, statusLabel))
267 onInstallComplete();
268 return;
270 if (!zd.extractEntry("bindingdialog/eventbindings.xml",configPath, statusLabel))
272 onInstallComplete();
273 return;
275 if (!zd.extractEntry("bindingdialog/manifest.xml",manifestPath, statusLabel))
277 onInstallComplete();
278 return;
282 if(!bindingsInstall) {
283 // Adding new directories to Office
284 // Adding <Office>/user/basic/ScriptBindingLibrary/
285 File scriptBindingLib = new File( starBasicPath );
286 if( !scriptBindingLib.isDirectory() ) {
287 if( !scriptBindingLib.mkdir() ) {
288 System.out.println( "ScriptBindingLibrary failed");
290 else {
291 System.out.println( "ScriptBindingLibrary directory created");
294 else
295 System.out.println( "ScriptBindingLibrary exists" );
297 // Adding Scripting Framework and tools
298 if (!zd.extractEntry("sframework/ooscriptframe.zip",progpath, statusLabel))
300 onInstallComplete();
301 return;
304 if (!zd.extractEntry("sframework/bshruntime.zip",progpath, statusLabel))
306 onInstallComplete();
307 return;
310 if (!zd.extractEntry("sframework/jsruntime.zip",progpath, statusLabel))
312 onInstallComplete();
313 return;
316 if (!zd.extractEntry("schema/Scripting.xcs",regSchemaOfficePath, statusLabel))
318 onInstallComplete();
319 return;
322 //--------------------------------
324 progressBar.setString("Registering Scripting Framework");
325 progressBar.setValue(3);
326 if(!Register.register(installPath+File.separator, statusLabel) ) {
327 onInstallComplete();
328 return;
330 progressBar.setValue(5);
332 String path = installPath + File.separator +
333 "share" + File.separator + "Scripts" + File.separator;
335 for (int i = 0; i < dirs.length; i++) {
336 File dir = new File(path + dirs[i]);
338 if (!dir.exists()) {
339 if (!dir.mkdirs()) {
340 System.err.println("Error making dir: " +
341 dir.getAbsolutePath());
342 onInstallComplete();
343 return;
348 for (int i = 0; i < names.length; i++) {
349 String source = "/examples/" + names[i];
350 String dest = path + names[i].replace('/', File.separatorChar);
352 if (!zd.extractEntry(source, dest, statusLabel)) {
353 onInstallComplete();
354 return;
359 // Adding binding dialog
360 if (!zd.extractEntry("bindingdialog/ScriptBinding.xba",starBasicPath, statusLabel))
362 onInstallComplete();
363 return;
365 if (!zd.extractEntry("bindingdialog/MenuBinding.xdl",starBasicPath, statusLabel))
367 onInstallComplete();
368 return;
370 if (!zd.extractEntry("bindingdialog/KeyBinding.xdl",starBasicPath, statusLabel))
372 onInstallComplete();
373 return;
375 if (!zd.extractEntry("bindingdialog/EventsBinding.xdl",starBasicPath, statusLabel))
377 onInstallComplete();
378 return;
380 if (!zd.extractEntry("bindingdialog/HelpBinding.xdl",starBasicPath, statusLabel))
382 onInstallComplete();
383 return;
385 if (!zd.extractEntry("bindingdialog/EditDebug.xdl",starBasicPath, statusLabel))
387 onInstallComplete();
388 return;
390 if (!zd.extractEntry("bindingdialog/dialog.xlb",starBasicPath, statusLabel))
392 onInstallComplete();
393 return;
395 if (!zd.extractEntry("bindingdialog/script.xlb",starBasicPath, statusLabel))
397 onInstallComplete();
398 return;
403 statusLabel.setText("Installation Complete");
404 progressBar.setString("Installation Complete");
405 progressBar.setValue(10);
406 onInstallComplete();
408 }// run
411 public void addInstallListener(InstallListener listener)
413 listeners.addElement(listener);
414 }// addInstallListener
417 private void onInstallComplete()
419 Enumeration e = listeners.elements();
420 while (e.hasMoreElements())
422 InstallListener listener = (InstallListener)e.nextElement();
423 listener.installationComplete(null);
425 }// onInstallComplete
427 }// XmlUpdater class