5 import java
.util
.jar
.*;
7 import java
.net
.JarURLConnection
;
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
=
33 "writerkeybinding.xml",
37 "impresskeybinding.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;
97 progressBar
.setStringPainted(true);
101 public boolean checkStop()
103 if (internalThread
== Thread
.currentThread())
109 public void checkSuspend()
111 if (threadSuspended
) {
113 while (threadSuspended
) {
116 } catch (InterruptedException eInt
) {
125 public void setSuspend()
127 threadSuspended
= true;
131 public void setResume()
133 threadSuspended
= false;
138 public void setStop()
140 internalThread
= null;
147 //InputSource isource;
148 //DocumentBuilderFactory builderFactory;
149 //DocumentBuilder builder = null;
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");
193 System
.out
.println( configDir
+ "directory created");
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");
205 System
.out
.println( manifestPath
+ " directory created");
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
))
235 if (!zd
.extractEntry("bindingdialog/writerkeybinding.xml",configPath
, statusLabel
))
240 if (!zd
.extractEntry("bindingdialog/calcmenubar.xml",configPath
, statusLabel
))
245 if (!zd
.extractEntry("bindingdialog/calckeybinding.xml",configPath
, statusLabel
))
250 if (!zd
.extractEntry("bindingdialog/impressmenubar.xml",configPath
, statusLabel
))
255 if (!zd
.extractEntry("bindingdialog/impresskeybinding.xml",configPath
, statusLabel
))
260 if (!zd
.extractEntry("bindingdialog/drawmenubar.xml",configPath
, statusLabel
))
265 if (!zd
.extractEntry("bindingdialog/drawkeybinding.xml",configPath
, statusLabel
))
270 if (!zd
.extractEntry("bindingdialog/eventbindings.xml",configPath
, statusLabel
))
275 if (!zd
.extractEntry("bindingdialog/manifest.xml",manifestPath
, statusLabel
))
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");
291 System
.out
.println( "ScriptBindingLibrary directory created");
295 System
.out
.println( "ScriptBindingLibrary exists" );
297 // Adding Scripting Framework and tools
298 if (!zd
.extractEntry("sframework/ooscriptframe.zip",progpath
, statusLabel
))
304 if (!zd
.extractEntry("sframework/bshruntime.zip",progpath
, statusLabel
))
310 if (!zd
.extractEntry("sframework/jsruntime.zip",progpath
, statusLabel
))
316 if (!zd
.extractEntry("schema/Scripting.xcs",regSchemaOfficePath
, statusLabel
))
322 //--------------------------------
324 progressBar
.setString("Registering Scripting Framework");
325 progressBar
.setValue(3);
326 if(!Register
.register(installPath
+File
.separator
, statusLabel
) ) {
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
]);
340 System
.err
.println("Error making dir: " +
341 dir
.getAbsolutePath());
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
)) {
359 // Adding binding dialog
360 if (!zd
.extractEntry("bindingdialog/ScriptBinding.xba",starBasicPath
, statusLabel
))
365 if (!zd
.extractEntry("bindingdialog/MenuBinding.xdl",starBasicPath
, statusLabel
))
370 if (!zd
.extractEntry("bindingdialog/KeyBinding.xdl",starBasicPath
, statusLabel
))
375 if (!zd
.extractEntry("bindingdialog/EventsBinding.xdl",starBasicPath
, statusLabel
))
380 if (!zd
.extractEntry("bindingdialog/HelpBinding.xdl",starBasicPath
, statusLabel
))
385 if (!zd
.extractEntry("bindingdialog/EditDebug.xdl",starBasicPath
, statusLabel
))
390 if (!zd
.extractEntry("bindingdialog/dialog.xlb",starBasicPath
, statusLabel
))
395 if (!zd
.extractEntry("bindingdialog/script.xlb",starBasicPath
, statusLabel
))
403 statusLabel
.setText("Installation Complete");
404 progressBar
.setString("Installation Complete");
405 progressBar
.setValue(10);
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