bump product version to 4.1.6.2
[LibreOffice.git] / scripting / workben / installer / XmlUpdater.java
blob884c0e323ece1aafcdaec54a18ffb587cdb9de7c
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer;
21 import java.io.*;
22 import java.util.*;
23 import java.net.URL;
24 import javax.swing.*;
26 public class XmlUpdater extends Thread {
28 private String classesPath = null;
29 private String jarfilename;
30 private String installPath;
31 private boolean netInstall;
32 private boolean bindingsInstall;
34 private JLabel statusLabel;
36 private ArrayList<InstallListener> listeners;
37 private Thread internalThread;
38 private boolean threadSuspended;
39 private JProgressBar progressBar;
41 private final String[] bakFiles =
43 "writermenubar.xml",
44 "writerkeybinding.xml",
45 "calcmenubar.xml",
46 "calckeybinding.xml",
47 "impressmenubar.xml",
48 "impresskeybinding.xml",
49 "drawmenubar.xml",
50 "drawkeybinding.xml",
51 "eventbindings.xml",
52 "META-INF" + File.separator + "manifest.xml"
55 private final String[] dirs =
57 "java" + File.separator + "Highlight",
58 "java" + File.separator + "MemoryUsage",
59 "java" + File.separator + "ScriptFrmwrkHelper",
60 "java" + File.separator + "debugger",
61 "java" + File.separator + "debugger" + File.separator + "rhino",
62 "beanshell" + File.separator + "InteractiveBeanShell",
63 "beanshell" + File.separator + "Highlight",
64 "beanshell" + File.separator + "MemoryUsage",
65 "javascript" + File.separator + "ExportSheetsToHTML"
68 private final String[] names =
70 "java/Highlight/HighlightUtil.java",
71 "java/Highlight/HighlightText.java",
72 "java/Highlight/Highlight.jar",
73 "java/Highlight/parcel-descriptor.xml",
74 "java/MemoryUsage/MemoryUsage.java",
75 "java/MemoryUsage/MemoryUsage.class",
76 "java/MemoryUsage/parcel-descriptor.xml",
77 "java/MemoryUsage/ExampleSpreadSheet.sxc",
78 "java/ScriptFrmwrkHelper/parcel-descriptor.xml",
79 "java/ScriptFrmwrkHelper/ScriptFrmwrkHelper.java",
80 "java/ScriptFrmwrkHelper/ScriptFrmwrkHelper.class",
81 "java/ScriptFrmwrkHelper/ScriptFrmwrkHelper.jar",
82 "java/debugger/debugger.jar",
83 "java/debugger/OOBeanShellDebugger.java",
84 "java/debugger/OOScriptDebugger.java",
85 "java/debugger/DebugRunner.java",
86 "java/debugger/OORhinoDebugger.java",
87 "java/debugger/parcel-descriptor.xml",
88 "java/debugger/rhino/Main.java",
89 "beanshell/InteractiveBeanShell/parcel-descriptor.xml",
90 "beanshell/InteractiveBeanShell/interactive.bsh",
91 "beanshell/Highlight/parcel-descriptor.xml",
92 "beanshell/Highlight/highlighter.bsh",
93 "beanshell/MemoryUsage/parcel-descriptor.xml",
94 "beanshell/MemoryUsage/memusage.bsh",
95 "javascript/ExportSheetsToHTML/parcel-descriptor.xml",
96 "javascript/ExportSheetsToHTML/exportsheetstohtml.js"
100 public XmlUpdater(String installPath, JLabel statusLabel,JProgressBar pBar, boolean netInstall, boolean bindingsInstall) {
101 this.installPath = installPath;
102 this.statusLabel = statusLabel;
103 this.netInstall = netInstall;
104 this.bindingsInstall = bindingsInstall;
105 listeners = new ArrayList<InstallListener>();
106 threadSuspended = false;
107 progressBar=pBar;
108 progressBar.setStringPainted(true);
109 }// XmlUpdater
112 public boolean checkStop()
114 if (internalThread == Thread.currentThread())
115 return false;
116 return true;
117 }// checkStop
120 public void checkSuspend()
122 if (threadSuspended) {
123 synchronized(this) {
124 while (threadSuspended) {
125 try {
126 wait();
127 } catch (InterruptedException eInt) {
128 //...
133 }// checkSuspend
136 public void setSuspend()
138 threadSuspended = true;
139 }// setSuspend
142 public void setResume()
144 threadSuspended = false;
145 notify();
146 }// setResume
149 public void setStop()
151 internalThread = null;
152 }// setStop
155 public void run() {
157 InputStream istream;
158 //InputSource isource;
159 //DocumentBuilderFactory builderFactory;
160 //DocumentBuilder builder = null;
161 URL url;
162 String fileName = null;
164 internalThread = Thread.currentThread();
166 //System.out.println("\n\n\n\nFileName: "+installPath);
167 classesPath= installPath.concat(File.separator+"program"+File.separator+"classes"+File.separator);
168 String opSys =System.getProperty("os.name");
169 //System.out.println("\n System "+opSys);
171 String progpath=installPath;
172 progpath= progpath.concat(File.separator+"program"+File.separator);
173 //System.out.println("Office progpath" + progpath );
174 //System.out.println("\nModifying Installation "+installPath);
176 String starBasicPath=installPath;
177 starBasicPath= starBasicPath.concat(File.separator+"share"+File.separator+"basic"+File.separator+"ScriptBindingLibrary"+File.separator);
178 //System.out.println( "Office StarBasic path: " + starBasicPath );
180 String regSchemaOfficePath=installPath;
181 regSchemaOfficePath= regSchemaOfficePath.concat(File.separator+"share"+File.separator+"registry"+File.separator+"schema"+File.separator+"org"+File.separator+"openoffice"+File.separator+"Office"+File.separator);
182 //System.out.println( "Office schema path: " + regSchemaOfficePath );
184 // Get the NetBeans installation
185 //String netbeansPath=
187 progressBar.setString("Unzipping Required Files");
188 ZipData zd = new ZipData("SFrameworkInstall.jar");
191 if( (!netInstall) || bindingsInstall) {
192 String configPath=installPath;
193 configPath= configPath.concat(File.separator+"user"+File.separator+"config"+File.separator+"soffice.cfg"+File.separator);
194 //System.out.println( "Office configuration path: " + configPath );
195 String manifestPath=configPath + "META-INF" + File.separator;
197 //Adding <Office>/user/config/soffice.cfg/
198 File configDir = new File( configPath );
199 if( !configDir.isDirectory() ) {
200 if( !configDir.mkdir() ) {
201 System.out.println( "creating " + configDir + "directory failed");
203 else {
204 System.out.println( configDir + "directory created");
207 else
208 System.out.println( "soffice.cfg exists" );
210 File manifestDir = new File( manifestPath );
211 if( !manifestDir.isDirectory() ) {
212 if( !manifestDir.mkdir() ) {
213 System.out.println( "creating " + manifestPath + "directory failed");
215 else {
216 System.out.println( manifestPath + " directory created");
219 else
220 System.out.println( manifestPath + " exists" );
222 // Backup the confguration files in
223 // <office>/user/config/soffice.cfg/
224 // If they already exist.
226 for( int i=0; i < bakFiles.length; i++ )
228 String pathNameBak = configPath + bakFiles[i];
229 File origFile = new File( pathNameBak );
230 if( origFile.exists() )
232 System.out.println( "Attempting to backup " + pathNameBak + " to " + pathNameBak + ".bak" );
233 if(! origFile.renameTo( new File( pathNameBak + ".bak" ) ) )
235 System.out.println( "Failed to backup " + pathNameBak + " to " + pathNameBak + ".bak" );
240 // Adding Office configuration files
241 if (!zd.extractEntry("bindingdialog/writermenubar.xml",configPath, statusLabel))
243 onInstallComplete();
244 return;
246 if (!zd.extractEntry("bindingdialog/writerkeybinding.xml",configPath, statusLabel))
248 onInstallComplete();
249 return;
251 if (!zd.extractEntry("bindingdialog/calcmenubar.xml",configPath, statusLabel))
253 onInstallComplete();
254 return;
256 if (!zd.extractEntry("bindingdialog/calckeybinding.xml",configPath, statusLabel))
258 onInstallComplete();
259 return;
261 if (!zd.extractEntry("bindingdialog/impressmenubar.xml",configPath, statusLabel))
263 onInstallComplete();
264 return;
266 if (!zd.extractEntry("bindingdialog/impresskeybinding.xml",configPath, statusLabel))
268 onInstallComplete();
269 return;
271 if (!zd.extractEntry("bindingdialog/drawmenubar.xml",configPath, statusLabel))
273 onInstallComplete();
274 return;
276 if (!zd.extractEntry("bindingdialog/drawkeybinding.xml",configPath, statusLabel))
278 onInstallComplete();
279 return;
281 if (!zd.extractEntry("bindingdialog/eventbindings.xml",configPath, statusLabel))
283 onInstallComplete();
284 return;
286 if (!zd.extractEntry("bindingdialog/manifest.xml",manifestPath, statusLabel))
288 onInstallComplete();
289 return;
293 if(!bindingsInstall) {
294 // Adding new directories to Office
295 // Adding <Office>/user/basic/ScriptBindingLibrary/
296 File scriptBindingLib = new File( starBasicPath );
297 if( !scriptBindingLib.isDirectory() ) {
298 if( !scriptBindingLib.mkdir() ) {
299 System.out.println( "ScriptBindingLibrary failed");
301 else {
302 System.out.println( "ScriptBindingLibrary directory created");
305 else
306 System.out.println( "ScriptBindingLibrary exists" );
308 // Adding Scripting Framework and tools
309 if (!zd.extractEntry("sframework/ooscriptframe.zip",progpath, statusLabel))
311 onInstallComplete();
312 return;
315 if (!zd.extractEntry("sframework/bshruntime.zip",progpath, statusLabel))
317 onInstallComplete();
318 return;
321 if (!zd.extractEntry("sframework/jsruntime.zip",progpath, statusLabel))
323 onInstallComplete();
324 return;
327 if (!zd.extractEntry("schema/Scripting.xcs",regSchemaOfficePath, statusLabel))
329 onInstallComplete();
330 return;
333 //--------------------------------
335 progressBar.setString("Registering Scripting Framework");
336 progressBar.setValue(3);
337 if(!Register.register(installPath+File.separator, statusLabel) ) {
338 onInstallComplete();
339 return;
341 progressBar.setValue(5);
343 String path = installPath + File.separator +
344 "share" + File.separator + "Scripts" + File.separator;
346 for (int i = 0; i < dirs.length; i++) {
347 File dir = new File(path + dirs[i]);
349 if (!dir.exists()) {
350 if (!dir.mkdirs()) {
351 System.err.println("Error making dir: " +
352 dir.getAbsolutePath());
353 onInstallComplete();
354 return;
359 for (int i = 0; i < names.length; i++) {
360 String source = "/examples/" + names[i];
361 String dest = path + names[i].replace('/', File.separatorChar);
363 if (!zd.extractEntry(source, dest, statusLabel)) {
364 onInstallComplete();
365 return;
370 // Adding binding dialog
371 if (!zd.extractEntry("bindingdialog/ScriptBinding.xba",starBasicPath, statusLabel))
373 onInstallComplete();
374 return;
376 if (!zd.extractEntry("bindingdialog/MenuBinding.xdl",starBasicPath, statusLabel))
378 onInstallComplete();
379 return;
381 if (!zd.extractEntry("bindingdialog/KeyBinding.xdl",starBasicPath, statusLabel))
383 onInstallComplete();
384 return;
386 if (!zd.extractEntry("bindingdialog/EventsBinding.xdl",starBasicPath, statusLabel))
388 onInstallComplete();
389 return;
391 if (!zd.extractEntry("bindingdialog/HelpBinding.xdl",starBasicPath, statusLabel))
393 onInstallComplete();
394 return;
396 if (!zd.extractEntry("bindingdialog/EditDebug.xdl",starBasicPath, statusLabel))
398 onInstallComplete();
399 return;
401 if (!zd.extractEntry("bindingdialog/dialog.xlb",starBasicPath, statusLabel))
403 onInstallComplete();
404 return;
406 if (!zd.extractEntry("bindingdialog/script.xlb",starBasicPath, statusLabel))
408 onInstallComplete();
409 return;
414 statusLabel.setText("Installation Complete");
415 progressBar.setString("Installation Complete");
416 progressBar.setValue(10);
417 onInstallComplete();
419 }// run
422 public void addInstallListener(InstallListener listener)
424 listeners.add(listener);
425 }// addInstallListener
428 private void onInstallComplete()
430 for (InstallListener l : listeners)
432 l.installationComplete(null);
434 }// onInstallComplete
436 }// XmlUpdater class