bump product version to 4.1.6.2
[LibreOffice.git] / scripting / workben / installer / FileUpdater.java
blob21c3d34dd36784c368d50c59200f0b82b77b7f49
1 /*
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 .
19 package installer;
21 import java.io.*;
22 import javax.swing.JLabel;
24 public class FileUpdater {
26 public static boolean updateProtocolHandler( String installPath, JLabel statusLabel ) {
27 File in_file = null;
28 FileInputStream in = null;
29 File out_file = null;
30 FileWriter out = null;
31 int count = 0;
33 try {
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];
37 try {
38 BufferedReader reader = new BufferedReader(new FileReader(in_file));
39 count = -1;
40 for (String s = reader.readLine(); s != null; s = reader.readLine()) { //</oor:node>
41 count = count + 1;
42 s.trim();
43 xmlArray[count] = s;
45 reader.close();
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);
52 return false;
55 in_file.delete();
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);
75 e.printStackTrace();
76 statusLabel.setText(message);
77 return false;
79 finally {
80 try {
81 out.close();
82 System.out.println("File closed");
84 catch(Exception e) {
85 System.out.println("Update ProtocolHandler Failed, please view SFrameworkInstall.log.");
86 System.err.println(e);
87 e.printStackTrace();
90 return true;
92 }// updateProtocolHandler
95 public static boolean updateScriptXLC( String installPath, JLabel statusLabel ) {
97 File in_file = null;
98 FileInputStream in = null;
99 File out_file = null;
100 FileWriter out = null;
101 int count = 0;
103 //System.out.println("updateScriptXLC");
104 try {
105 in_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"script.xlc" );
107 String[] xmlArray = new String[50];
108 try {
109 BufferedReader reader = new BufferedReader(new FileReader(in_file));
110 count = -1;
111 for (String s = reader.readLine(); s != null; s = reader.readLine()) { //</oor:node>
112 count = count + 1;
113 s.trim();
114 xmlArray[count] = s;
116 reader.close();
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);
123 return false;
126 in_file.delete();
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" );
141 else {
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);
150 e.printStackTrace();
151 statusLabel.setText(message);
152 return false;
154 finally {
155 try {
156 out.close();
158 catch(Exception e) {
159 System.out.println("Update Script.xlc Failed, please view SFrameworkInstall.log.");
160 e.printStackTrace();
161 System.err.println(e);
164 return true;
165 }// updateScriptXLC
168 public static boolean updateDialogXLC( String installPath, JLabel statusLabel ) {
169 File in_file = null;
170 FileInputStream in = null;
171 File out_file = null;
172 FileWriter out = null;
173 int count = 0;
175 //System.out.println( "updateDialogXLC" );
176 try {
177 in_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"dialog.xlc" );
178 String xmlLine = "";
180 String[] xmlArray = new String[50];
181 try {
182 BufferedReader reader = new BufferedReader(new FileReader(in_file));
183 count = -1;
184 for (String s = reader.readLine(); s != null; s = reader.readLine()) {
185 count = count + 1;
186 s.trim();
187 xmlArray[count] = s;
189 reader.close();
191 catch( IOException ioe ) {
193 String message = "\nError reading dialog.xlc, please view SFrameworkInstall.log.";
194 System.out.println(message);
195 statusLabel.setText(message);
196 return false;
198 in_file.delete();
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" );
214 else {
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);
223 e.printStackTrace();
224 statusLabel.setText(message);
225 return false;
227 finally {
228 try {
229 out.close();
231 catch(Exception e) {
232 System.out.println("Update dialog.xlc Failed, please view SFrameworkInstall.log.");
233 e.printStackTrace();
234 System.err.println(e);
237 return true;
238 }// updateScriptXLC