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 .
22 import javax
.swing
.JLabel
;
24 public class FileUpdater
{
26 public static boolean updateProtocolHandler( String installPath
, JLabel statusLabel
) {
28 FileInputStream in
= null;
30 FileWriter out
= null;
34 in_file
= new File( installPath
+File
.separator
+"share"+File
.separator
+"registry"+File
.separator
+"data"+File
.separator
+"org"+File
.separator
+"openoffice"+File
.separator
+"Office"+File
.separator
+"ProtocolHandler.xcu" );
36 String
[] xmlArray
= new String
[50];
38 BufferedReader reader
= new BufferedReader(new FileReader(in_file
));
40 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) { //</oor:node>
47 catch( IOException ioe
) {
48 String message
= "\nError reading ProtocolHandler.xcu, please view SFrameworkInstall.log.";
49 System
.out
.println(message
);
50 ioe
.printStackTrace();
51 statusLabel
.setText(message
);
57 out_file
= new File( installPath
+File
.separator
+"share"+File
.separator
+"registry"+File
.separator
+"data"+File
.separator
+"org"+File
.separator
+"openoffice"+File
.separator
+"Office"+File
.separator
+"ProtocolHandler.xcu" );
58 out_file
.createNewFile();
59 out
= new FileWriter( out_file
);
61 for(int i
=0; i
<count
+ 1; i
++) {
62 out
.write(xmlArray
[i
]+"\n");
63 if( ( xmlArray
[i
].indexOf( "<node oor:name=\"HandlerSet\">" ) != -1 ) && ( xmlArray
[i
+1].indexOf( "ScriptProtocolHandler" ) == -1 ) ) {
64 out
.write( " <node oor:name=\"com.sun.star.comp.ScriptProtocolHandler\" oor:op=\"replace\">\n" );
65 out
.write( " <prop oor:name=\"Protocols\">\n" );
66 out
.write( " <value>script:*</value>\n" );
67 out
.write( " </prop>\n" );
68 out
.write( " </node>\n" );
72 catch( Exception e
) {
73 String message
= "\nError updating ProtocolHandler.xcu, please view SFrameworkInstall.log.";
74 System
.out
.println(message
);
76 statusLabel
.setText(message
);
82 System
.out
.println("File closed");
85 System
.out
.println("Update ProtocolHandler Failed, please view SFrameworkInstall.log.");
86 System
.err
.println(e
);
92 }// updateProtocolHandler
95 public static boolean updateScriptXLC( String installPath
, JLabel statusLabel
) {
98 FileInputStream in
= null;
100 FileWriter out
= null;
103 //System.out.println("updateScriptXLC");
105 in_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"script.xlc" );
107 String
[] xmlArray
= new String
[50];
109 BufferedReader reader
= new BufferedReader(new FileReader(in_file
));
111 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) { //</oor:node>
118 catch( IOException ioe
) {
119 String message
= "Error reading script.xlc, please view SFrameworkInstall.log.";
120 System
.out
.println(message
);
121 ioe
.printStackTrace();
122 statusLabel
.setText(message
);
128 out_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"script.xlc" );
129 out_file
.createNewFile();
130 out
= new FileWriter( out_file
);
132 //split the string into a string array with one line of xml in each element
133 //String[] xmlArray = xmlLine.split("\n");
134 for(int i
=0; i
<count
+ 1; i
++) {
135 out
.write(xmlArray
[i
]+"\n");
136 if( ( xmlArray
[i
].indexOf( "<library:libraries xmlns:library" ) != -1 ) && ( xmlArray
[i
+1].indexOf( "ScriptBindingLibrary" ) == -1 ) ) {
137 String opSys
= System
.getProperty("os.name");
138 if (opSys
.indexOf("Windows") != -1) {
139 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" library:link=\"true\"/>\n" );
142 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" xlink:href=\"file://"+installPath
+"/share/basic/ScriptBindingLibrary/script.xlb/\" xlink:type=\"simple\" library:link=\"true\"/>\n" );
147 catch( Exception e
) {
148 String message
= "\nError updating script.xlc, please view SFrameworkInstall.log.";
149 System
.out
.println(message
);
151 statusLabel
.setText(message
);
159 System
.out
.println("Update Script.xlc Failed, please view SFrameworkInstall.log.");
161 System
.err
.println(e
);
168 public static boolean updateDialogXLC( String installPath
, JLabel statusLabel
) {
170 FileInputStream in
= null;
171 File out_file
= null;
172 FileWriter out
= null;
175 //System.out.println( "updateDialogXLC" );
177 in_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"dialog.xlc" );
180 String
[] xmlArray
= new String
[50];
182 BufferedReader reader
= new BufferedReader(new FileReader(in_file
));
184 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) {
191 catch( IOException ioe
) {
193 String message
= "\nError reading dialog.xlc, please view SFrameworkInstall.log.";
194 System
.out
.println(message
);
195 statusLabel
.setText(message
);
200 out_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"dialog.xlc" );
201 out_file
.createNewFile();
203 out
= new FileWriter( out_file
);
205 //split the string into a string array with one line of xml in each element
206 // String[] xmlArray = xmlLine.split("\n");
207 for(int i
=0; i
<count
+ 1; i
++) {
208 out
.write(xmlArray
[i
]+"\n");
209 if( ( xmlArray
[i
].indexOf( "<library:libraries xmlns:library" ) != -1 ) && ( xmlArray
[i
+1].indexOf( "ScriptBindingLibrary" ) == -1 ) ) {
210 String opSys
= System
.getProperty("os.name");
211 if (opSys
.indexOf("Windows") != -1) {
212 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" library:link=\"true\"/>\n" );
215 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" xlink:href=\"file://"+installPath
+"/share/basic/ScriptBindingLibrary/dialog.xlb/\" xlink:type=\"simple\" library:link=\"true\"/>\n" );
220 catch( Exception e
) {
221 String message
= "\nError updating dialog.xlc, please view SFrameworkInstall.log.";
222 System
.out
.println(message
);
224 statusLabel
.setText(message
);
232 System
.out
.println("Update dialog.xlc Failed, please view SFrameworkInstall.log.");
234 System
.err
.println(e
);