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 .
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
=
44 "writerkeybinding.xml",
48 "impresskeybinding.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;
108 progressBar
.setStringPainted(true);
112 public boolean checkStop()
114 if (internalThread
== Thread
.currentThread())
120 public void checkSuspend()
122 if (threadSuspended
) {
124 while (threadSuspended
) {
127 } catch (InterruptedException eInt
) {
136 public void setSuspend()
138 threadSuspended
= true;
142 public void setResume()
144 threadSuspended
= false;
149 public void setStop()
151 internalThread
= null;
158 //InputSource isource;
159 //DocumentBuilderFactory builderFactory;
160 //DocumentBuilder builder = null;
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");
204 System
.out
.println( configDir
+ "directory created");
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");
216 System
.out
.println( manifestPath
+ " directory created");
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
))
246 if (!zd
.extractEntry("bindingdialog/writerkeybinding.xml",configPath
, statusLabel
))
251 if (!zd
.extractEntry("bindingdialog/calcmenubar.xml",configPath
, statusLabel
))
256 if (!zd
.extractEntry("bindingdialog/calckeybinding.xml",configPath
, statusLabel
))
261 if (!zd
.extractEntry("bindingdialog/impressmenubar.xml",configPath
, statusLabel
))
266 if (!zd
.extractEntry("bindingdialog/impresskeybinding.xml",configPath
, statusLabel
))
271 if (!zd
.extractEntry("bindingdialog/drawmenubar.xml",configPath
, statusLabel
))
276 if (!zd
.extractEntry("bindingdialog/drawkeybinding.xml",configPath
, statusLabel
))
281 if (!zd
.extractEntry("bindingdialog/eventbindings.xml",configPath
, statusLabel
))
286 if (!zd
.extractEntry("bindingdialog/manifest.xml",manifestPath
, statusLabel
))
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");
302 System
.out
.println( "ScriptBindingLibrary directory created");
306 System
.out
.println( "ScriptBindingLibrary exists" );
308 // Adding Scripting Framework and tools
309 if (!zd
.extractEntry("sframework/ooscriptframe.zip",progpath
, statusLabel
))
315 if (!zd
.extractEntry("sframework/bshruntime.zip",progpath
, statusLabel
))
321 if (!zd
.extractEntry("sframework/jsruntime.zip",progpath
, statusLabel
))
327 if (!zd
.extractEntry("schema/Scripting.xcs",regSchemaOfficePath
, statusLabel
))
333 //--------------------------------
335 progressBar
.setString("Registering Scripting Framework");
336 progressBar
.setValue(3);
337 if(!Register
.register(installPath
+File
.separator
, statusLabel
) ) {
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
]);
351 System
.err
.println("Error making dir: " +
352 dir
.getAbsolutePath());
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
)) {
370 // Adding binding dialog
371 if (!zd
.extractEntry("bindingdialog/ScriptBinding.xba",starBasicPath
, statusLabel
))
376 if (!zd
.extractEntry("bindingdialog/MenuBinding.xdl",starBasicPath
, statusLabel
))
381 if (!zd
.extractEntry("bindingdialog/KeyBinding.xdl",starBasicPath
, statusLabel
))
386 if (!zd
.extractEntry("bindingdialog/EventsBinding.xdl",starBasicPath
, statusLabel
))
391 if (!zd
.extractEntry("bindingdialog/HelpBinding.xdl",starBasicPath
, statusLabel
))
396 if (!zd
.extractEntry("bindingdialog/EditDebug.xdl",starBasicPath
, statusLabel
))
401 if (!zd
.extractEntry("bindingdialog/dialog.xlb",starBasicPath
, statusLabel
))
406 if (!zd
.extractEntry("bindingdialog/script.xlb",starBasicPath
, statusLabel
))
414 statusLabel
.setText("Installation Complete");
415 progressBar
.setString("Installation Complete");
416 progressBar
.setValue(10);
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