update dev300-m58
[ooovba.git] / scripting / workben / installer / FileUpdater.java
blobfb1ae6188dbe65a7a24cd60554285c465bced2d3
1 package installer;
3 import java.io.*;
4 import javax.swing.JLabel;
6 public class FileUpdater {
8 public static boolean updateProtocolHandler( String installPath, JLabel statusLabel ) {
9 File in_file = null;
10 FileInputStream in = null;
11 File out_file = null;
12 FileWriter out = null;
13 int count = 0;
15 try {
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];
19 try {
20 BufferedReader reader = new BufferedReader(new FileReader(in_file));
21 count = -1;
22 for (String s = reader.readLine(); s != null; s = reader.readLine()) { //</oor:node>
23 count = count + 1;
24 if(s != null) {
25 s.trim();
26 xmlArray[count] = s;
28 else
29 break;
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);
37 return false;
40 in_file.delete();
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);
60 e.printStackTrace();
61 statusLabel.setText(message);
62 return false;
64 finally {
65 try {
66 out.close();
67 System.out.println("File closed");
69 catch(Exception e) {
70 System.out.println("Update ProtocolHandler Failed, please view SFrameworkInstall.log.");
71 System.err.println(e);
72 e.printStackTrace();
75 return true;
77 }// updateProtocolHandler
80 public static boolean updateScriptXLC( String installPath, JLabel statusLabel ) {
82 File in_file = null;
83 FileInputStream in = null;
84 File out_file = null;
85 FileWriter out = null;
86 int count = 0;
88 //System.out.println("updateScriptXLC");
89 try {
90 in_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"script.xlc" );
92 String[] xmlArray = new String[50];
93 try {
94 BufferedReader reader = new BufferedReader(new FileReader(in_file));
95 count = -1;
96 for (String s = reader.readLine(); s != null; s = reader.readLine()) { //</oor:node>
97 count = count + 1;
98 if(s != null) {
99 s.trim();
100 xmlArray[count] = s;
102 else
103 break;
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);
111 return false;
114 in_file.delete();
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" );
129 else {
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);
138 e.printStackTrace();
139 statusLabel.setText(message);
140 return false;
142 finally {
143 try {
144 out.close();
146 catch(Exception e) {
147 System.out.println("Update Script.xlc Failed, please view SFrameworkInstall.log.");
148 e.printStackTrace();
149 System.err.println(e);
152 return true;
153 }// updateScriptXLC
156 public static boolean updateDialogXLC( String installPath, JLabel statusLabel ) {
157 File in_file = null;
158 FileInputStream in = null;
159 File out_file = null;
160 FileWriter out = null;
161 int count = 0;
163 //System.out.println( "updateDialogXLC" );
164 try {
165 in_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"dialog.xlc" );
166 String xmlLine = "";
168 String[] xmlArray = new String[50];
169 try {
170 BufferedReader reader = new BufferedReader(new FileReader(in_file));
171 count = -1;
172 for (String s = reader.readLine(); s != null; s = reader.readLine()) {
173 count = count + 1;
174 if(s != null) {
175 s.trim();
176 xmlArray[count] = s;
178 else
179 break;
182 catch( IOException ioe ) {
184 String message = "\nError reading dialog.xlc, please view SFrameworkInstall.log.";
185 System.out.println(message);
186 statusLabel.setText(message);
187 return false;
189 in_file.delete();
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" );
205 else {
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);
214 e.printStackTrace();
215 statusLabel.setText(message);
216 return false;
218 finally {
219 try {
220 out.close();
222 catch(Exception e) {
223 System.out.println("Update dialog.xlc Failed, please view SFrameworkInstall.log.");
224 e.printStackTrace();
225 System.err.println(e);
228 return true;
229 }// updateScriptXLC