4 import javax
.swing
.JLabel
;
6 public class FileUpdater
{
8 public static boolean updateProtocolHandler( String installPath
, JLabel statusLabel
) {
10 FileInputStream in
= null;
12 FileWriter out
= null;
16 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" );
18 String
[] xmlArray
= new String
[50];
20 BufferedReader reader
= new BufferedReader(new FileReader(in_file
));
22 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) { //</oor:node>
32 catch( IOException ioe
) {
33 String message
= "\nError reading ProtocolHandler.xcu, please view SFrameworkInstall.log.";
34 System
.out
.println(message
);
35 ioe
.printStackTrace();
36 statusLabel
.setText(message
);
42 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" );
43 out_file
.createNewFile();
44 out
= new FileWriter( out_file
);
46 for(int i
=0; i
<count
+ 1; i
++) {
47 out
.write(xmlArray
[i
]+"\n");
48 if( ( xmlArray
[i
].indexOf( "<node oor:name=\"HandlerSet\">" ) != -1 ) && ( xmlArray
[i
+1].indexOf( "ScriptProtocolHandler" ) == -1 ) ) {
49 out
.write( " <node oor:name=\"com.sun.star.comp.ScriptProtocolHandler\" oor:op=\"replace\">\n" );
50 out
.write( " <prop oor:name=\"Protocols\">\n" );
51 out
.write( " <value>script:*</value>\n" );
52 out
.write( " </prop>\n" );
53 out
.write( " </node>\n" );
57 catch( Exception e
) {
58 String message
= "\nError updating ProtocolHandler.xcu, please view SFrameworkInstall.log.";
59 System
.out
.println(message
);
61 statusLabel
.setText(message
);
67 System
.out
.println("File closed");
70 System
.out
.println("Update ProtocolHandler Failed, please view SFrameworkInstall.log.");
71 System
.err
.println(e
);
77 }// updateProtocolHandler
80 public static boolean updateScriptXLC( String installPath
, JLabel statusLabel
) {
83 FileInputStream in
= null;
85 FileWriter out
= null;
88 //System.out.println("updateScriptXLC");
90 in_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"script.xlc" );
92 String
[] xmlArray
= new String
[50];
94 BufferedReader reader
= new BufferedReader(new FileReader(in_file
));
96 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) { //</oor:node>
106 catch( IOException ioe
) {
107 String message
= "Error reading script.xlc, please view SFrameworkInstall.log.";
108 System
.out
.println(message
);
109 ioe
.printStackTrace();
110 statusLabel
.setText(message
);
116 out_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"script.xlc" );
117 out_file
.createNewFile();
118 out
= new FileWriter( out_file
);
120 //split the string into a string array with one line of xml in each element
121 //String[] xmlArray = xmlLine.split("\n");
122 for(int i
=0; i
<count
+ 1; i
++) {
123 out
.write(xmlArray
[i
]+"\n");
124 if( ( xmlArray
[i
].indexOf( "<library:libraries xmlns:library" ) != -1 ) && ( xmlArray
[i
+1].indexOf( "ScriptBindingLibrary" ) == -1 ) ) {
125 String opSys
= System
.getProperty("os.name");
126 if (opSys
.indexOf("Windows") != -1) {
127 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" library:link=\"true\"/>\n" );
130 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" xlink:href=\"file://"+installPath
+"/share/basic/ScriptBindingLibrary/script.xlb/\" xlink:type=\"simple\" library:link=\"true\"/>\n" );
135 catch( Exception e
) {
136 String message
= "\nError updating script.xlc, please view SFrameworkInstall.log.";
137 System
.out
.println(message
);
139 statusLabel
.setText(message
);
147 System
.out
.println("Update Script.xlc Failed, please view SFrameworkInstall.log.");
149 System
.err
.println(e
);
156 public static boolean updateDialogXLC( String installPath
, JLabel statusLabel
) {
158 FileInputStream in
= null;
159 File out_file
= null;
160 FileWriter out
= null;
163 //System.out.println( "updateDialogXLC" );
165 in_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"dialog.xlc" );
168 String
[] xmlArray
= new String
[50];
170 BufferedReader reader
= new BufferedReader(new FileReader(in_file
));
172 for (String s
= reader
.readLine(); s
!= null; s
= reader
.readLine()) {
182 catch( IOException ioe
) {
184 String message
= "\nError reading dialog.xlc, please view SFrameworkInstall.log.";
185 System
.out
.println(message
);
186 statusLabel
.setText(message
);
191 out_file
= new File( installPath
+File
.separator
+"user"+File
.separator
+"basic"+File
.separator
+"dialog.xlc" );
192 out_file
.createNewFile();
194 out
= new FileWriter( out_file
);
196 //split the string into a string array with one line of xml in each element
197 // String[] xmlArray = xmlLine.split("\n");
198 for(int i
=0; i
<count
+ 1; i
++) {
199 out
.write(xmlArray
[i
]+"\n");
200 if( ( xmlArray
[i
].indexOf( "<library:libraries xmlns:library" ) != -1 ) && ( xmlArray
[i
+1].indexOf( "ScriptBindingLibrary" ) == -1 ) ) {
201 String opSys
= System
.getProperty("os.name");
202 if (opSys
.indexOf("Windows") != -1) {
203 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" library:link=\"true\"/>\n" );
206 out
.write(" <library:library library:name=\"ScriptBindingLibrary\" xlink:href=\"file://"+installPath
+"/share/basic/ScriptBindingLibrary/dialog.xlb/\" xlink:type=\"simple\" library:link=\"true\"/>\n" );
211 catch( Exception e
) {
212 String message
= "\nError updating dialog.xlc, please view SFrameworkInstall.log.";
213 System
.out
.println(message
);
215 statusLabel
.setText(message
);
223 System
.out
.println("Update dialog.xlc Failed, please view SFrameworkInstall.log.");
225 System
.err
.println(e
);