1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski package installer; 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski import java.io.*; 25*b1cdbd2cSJim Jagielski import javax.swing.JLabel; 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski public class FileUpdater { 28*b1cdbd2cSJim Jagielski updateProtocolHandler( String installPath, JLabel statusLabel )29*b1cdbd2cSJim Jagielski public static boolean updateProtocolHandler( String installPath, JLabel statusLabel ) { 30*b1cdbd2cSJim Jagielski File in_file = null; 31*b1cdbd2cSJim Jagielski FileInputStream in = null; 32*b1cdbd2cSJim Jagielski File out_file = null; 33*b1cdbd2cSJim Jagielski FileWriter out = null; 34*b1cdbd2cSJim Jagielski int count = 0; 35*b1cdbd2cSJim Jagielski 36*b1cdbd2cSJim Jagielski try { 37*b1cdbd2cSJim Jagielski 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" ); 38*b1cdbd2cSJim Jagielski 39*b1cdbd2cSJim Jagielski String[] xmlArray = new String[50]; 40*b1cdbd2cSJim Jagielski try { 41*b1cdbd2cSJim Jagielski BufferedReader reader = new BufferedReader(new FileReader(in_file)); 42*b1cdbd2cSJim Jagielski count = -1; 43*b1cdbd2cSJim Jagielski for (String s = reader.readLine(); s != null; s = reader.readLine()) { //</oor:node> 44*b1cdbd2cSJim Jagielski count = count + 1; 45*b1cdbd2cSJim Jagielski if(s != null) { 46*b1cdbd2cSJim Jagielski s.trim(); 47*b1cdbd2cSJim Jagielski xmlArray[count] = s; 48*b1cdbd2cSJim Jagielski } 49*b1cdbd2cSJim Jagielski else 50*b1cdbd2cSJim Jagielski break; 51*b1cdbd2cSJim Jagielski } 52*b1cdbd2cSJim Jagielski } 53*b1cdbd2cSJim Jagielski catch( IOException ioe ) { 54*b1cdbd2cSJim Jagielski String message = "\nError reading ProtocolHandler.xcu, please view SFrameworkInstall.log."; 55*b1cdbd2cSJim Jagielski System.out.println(message); 56*b1cdbd2cSJim Jagielski ioe.printStackTrace(); 57*b1cdbd2cSJim Jagielski statusLabel.setText(message); 58*b1cdbd2cSJim Jagielski return false; 59*b1cdbd2cSJim Jagielski } 60*b1cdbd2cSJim Jagielski 61*b1cdbd2cSJim Jagielski in_file.delete(); 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski 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" ); 64*b1cdbd2cSJim Jagielski out_file.createNewFile(); 65*b1cdbd2cSJim Jagielski out = new FileWriter( out_file ); 66*b1cdbd2cSJim Jagielski 67*b1cdbd2cSJim Jagielski for(int i=0; i<count + 1; i++) { 68*b1cdbd2cSJim Jagielski out.write(xmlArray[i]+"\n"); 69*b1cdbd2cSJim Jagielski if( ( xmlArray[i].indexOf( "<node oor:name=\"HandlerSet\">" ) != -1 ) && ( xmlArray[i+1].indexOf( "ScriptProtocolHandler" ) == -1 ) ) { 70*b1cdbd2cSJim Jagielski out.write( " <node oor:name=\"com.sun.star.comp.ScriptProtocolHandler\" oor:op=\"replace\">\n" ); 71*b1cdbd2cSJim Jagielski out.write( " <prop oor:name=\"Protocols\">\n" ); 72*b1cdbd2cSJim Jagielski out.write( " <value>script:*</value>\n" ); 73*b1cdbd2cSJim Jagielski out.write( " </prop>\n" ); 74*b1cdbd2cSJim Jagielski out.write( " </node>\n" ); 75*b1cdbd2cSJim Jagielski } 76*b1cdbd2cSJim Jagielski } 77*b1cdbd2cSJim Jagielski } 78*b1cdbd2cSJim Jagielski catch( Exception e ) { 79*b1cdbd2cSJim Jagielski String message = "\nError updating ProtocolHandler.xcu, please view SFrameworkInstall.log."; 80*b1cdbd2cSJim Jagielski System.out.println(message); 81*b1cdbd2cSJim Jagielski e.printStackTrace(); 82*b1cdbd2cSJim Jagielski statusLabel.setText(message); 83*b1cdbd2cSJim Jagielski return false; 84*b1cdbd2cSJim Jagielski } 85*b1cdbd2cSJim Jagielski finally { 86*b1cdbd2cSJim Jagielski try { 87*b1cdbd2cSJim Jagielski out.close(); 88*b1cdbd2cSJim Jagielski System.out.println("File closed"); 89*b1cdbd2cSJim Jagielski } 90*b1cdbd2cSJim Jagielski catch(Exception e) { 91*b1cdbd2cSJim Jagielski System.out.println("Update ProtocolHandler Failed, please view SFrameworkInstall.log."); 92*b1cdbd2cSJim Jagielski System.err.println(e); 93*b1cdbd2cSJim Jagielski e.printStackTrace(); 94*b1cdbd2cSJim Jagielski } 95*b1cdbd2cSJim Jagielski } 96*b1cdbd2cSJim Jagielski return true; 97*b1cdbd2cSJim Jagielski 98*b1cdbd2cSJim Jagielski }// updateProtocolHandler 99*b1cdbd2cSJim Jagielski 100*b1cdbd2cSJim Jagielski updateScriptXLC( String installPath, JLabel statusLabel )101*b1cdbd2cSJim Jagielski public static boolean updateScriptXLC( String installPath, JLabel statusLabel ) { 102*b1cdbd2cSJim Jagielski 103*b1cdbd2cSJim Jagielski File in_file = null; 104*b1cdbd2cSJim Jagielski FileInputStream in = null; 105*b1cdbd2cSJim Jagielski File out_file = null; 106*b1cdbd2cSJim Jagielski FileWriter out = null; 107*b1cdbd2cSJim Jagielski int count = 0; 108*b1cdbd2cSJim Jagielski 109*b1cdbd2cSJim Jagielski //System.out.println("updateScriptXLC"); 110*b1cdbd2cSJim Jagielski try { 111*b1cdbd2cSJim Jagielski in_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"script.xlc" ); 112*b1cdbd2cSJim Jagielski 113*b1cdbd2cSJim Jagielski String[] xmlArray = new String[50]; 114*b1cdbd2cSJim Jagielski try { 115*b1cdbd2cSJim Jagielski BufferedReader reader = new BufferedReader(new FileReader(in_file)); 116*b1cdbd2cSJim Jagielski count = -1; 117*b1cdbd2cSJim Jagielski for (String s = reader.readLine(); s != null; s = reader.readLine()) { //</oor:node> 118*b1cdbd2cSJim Jagielski count = count + 1; 119*b1cdbd2cSJim Jagielski if(s != null) { 120*b1cdbd2cSJim Jagielski s.trim(); 121*b1cdbd2cSJim Jagielski xmlArray[count] = s; 122*b1cdbd2cSJim Jagielski } 123*b1cdbd2cSJim Jagielski else 124*b1cdbd2cSJim Jagielski break; 125*b1cdbd2cSJim Jagielski } 126*b1cdbd2cSJim Jagielski } 127*b1cdbd2cSJim Jagielski catch( IOException ioe ) { 128*b1cdbd2cSJim Jagielski String message = "Error reading script.xlc, please view SFrameworkInstall.log."; 129*b1cdbd2cSJim Jagielski System.out.println(message); 130*b1cdbd2cSJim Jagielski ioe.printStackTrace(); 131*b1cdbd2cSJim Jagielski statusLabel.setText(message); 132*b1cdbd2cSJim Jagielski return false; 133*b1cdbd2cSJim Jagielski } 134*b1cdbd2cSJim Jagielski 135*b1cdbd2cSJim Jagielski in_file.delete(); 136*b1cdbd2cSJim Jagielski 137*b1cdbd2cSJim Jagielski out_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"script.xlc" ); 138*b1cdbd2cSJim Jagielski out_file.createNewFile(); 139*b1cdbd2cSJim Jagielski out = new FileWriter( out_file ); 140*b1cdbd2cSJim Jagielski 141*b1cdbd2cSJim Jagielski //split the string into a string array with one line of xml in each element 142*b1cdbd2cSJim Jagielski //String[] xmlArray = xmlLine.split("\n"); 143*b1cdbd2cSJim Jagielski for(int i=0; i<count + 1; i++) { 144*b1cdbd2cSJim Jagielski out.write(xmlArray[i]+"\n"); 145*b1cdbd2cSJim Jagielski if( ( xmlArray[i].indexOf( "<library:libraries xmlns:library" ) != -1 ) && ( xmlArray[i+1].indexOf( "ScriptBindingLibrary" ) == -1 ) ) { 146*b1cdbd2cSJim Jagielski String opSys = System.getProperty("os.name"); 147*b1cdbd2cSJim Jagielski if (opSys.indexOf("Windows") != -1) { 148*b1cdbd2cSJim Jagielski out.write(" <library:library library:name=\"ScriptBindingLibrary\" library:link=\"true\"/>\n" ); 149*b1cdbd2cSJim Jagielski } 150*b1cdbd2cSJim Jagielski else { 151*b1cdbd2cSJim Jagielski out.write(" <library:library library:name=\"ScriptBindingLibrary\" xlink:href=\"file://"+installPath+"/share/basic/ScriptBindingLibrary/script.xlb/\" xlink:type=\"simple\" library:link=\"true\"/>\n" ); 152*b1cdbd2cSJim Jagielski } 153*b1cdbd2cSJim Jagielski } 154*b1cdbd2cSJim Jagielski } 155*b1cdbd2cSJim Jagielski } 156*b1cdbd2cSJim Jagielski catch( Exception e ) { 157*b1cdbd2cSJim Jagielski String message = "\nError updating script.xlc, please view SFrameworkInstall.log."; 158*b1cdbd2cSJim Jagielski System.out.println(message); 159*b1cdbd2cSJim Jagielski e.printStackTrace(); 160*b1cdbd2cSJim Jagielski statusLabel.setText(message); 161*b1cdbd2cSJim Jagielski return false; 162*b1cdbd2cSJim Jagielski } 163*b1cdbd2cSJim Jagielski finally { 164*b1cdbd2cSJim Jagielski try { 165*b1cdbd2cSJim Jagielski out.close(); 166*b1cdbd2cSJim Jagielski } 167*b1cdbd2cSJim Jagielski catch(Exception e) { 168*b1cdbd2cSJim Jagielski System.out.println("Update Script.xlc Failed, please view SFrameworkInstall.log."); 169*b1cdbd2cSJim Jagielski e.printStackTrace(); 170*b1cdbd2cSJim Jagielski System.err.println(e); 171*b1cdbd2cSJim Jagielski } 172*b1cdbd2cSJim Jagielski } 173*b1cdbd2cSJim Jagielski return true; 174*b1cdbd2cSJim Jagielski }// updateScriptXLC 175*b1cdbd2cSJim Jagielski 176*b1cdbd2cSJim Jagielski updateDialogXLC( String installPath, JLabel statusLabel )177*b1cdbd2cSJim Jagielski public static boolean updateDialogXLC( String installPath, JLabel statusLabel ) { 178*b1cdbd2cSJim Jagielski File in_file = null; 179*b1cdbd2cSJim Jagielski FileInputStream in = null; 180*b1cdbd2cSJim Jagielski File out_file = null; 181*b1cdbd2cSJim Jagielski FileWriter out = null; 182*b1cdbd2cSJim Jagielski int count = 0; 183*b1cdbd2cSJim Jagielski 184*b1cdbd2cSJim Jagielski //System.out.println( "updateDialogXLC" ); 185*b1cdbd2cSJim Jagielski try { 186*b1cdbd2cSJim Jagielski in_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"dialog.xlc" ); 187*b1cdbd2cSJim Jagielski String xmlLine = ""; 188*b1cdbd2cSJim Jagielski 189*b1cdbd2cSJim Jagielski String[] xmlArray = new String[50]; 190*b1cdbd2cSJim Jagielski try { 191*b1cdbd2cSJim Jagielski BufferedReader reader = new BufferedReader(new FileReader(in_file)); 192*b1cdbd2cSJim Jagielski count = -1; 193*b1cdbd2cSJim Jagielski for (String s = reader.readLine(); s != null; s = reader.readLine()) { 194*b1cdbd2cSJim Jagielski count = count + 1; 195*b1cdbd2cSJim Jagielski if(s != null) { 196*b1cdbd2cSJim Jagielski s.trim(); 197*b1cdbd2cSJim Jagielski xmlArray[count] = s; 198*b1cdbd2cSJim Jagielski } 199*b1cdbd2cSJim Jagielski else 200*b1cdbd2cSJim Jagielski break; 201*b1cdbd2cSJim Jagielski } 202*b1cdbd2cSJim Jagielski } 203*b1cdbd2cSJim Jagielski catch( IOException ioe ) { 204*b1cdbd2cSJim Jagielski 205*b1cdbd2cSJim Jagielski String message = "\nError reading dialog.xlc, please view SFrameworkInstall.log."; 206*b1cdbd2cSJim Jagielski System.out.println(message); 207*b1cdbd2cSJim Jagielski statusLabel.setText(message); 208*b1cdbd2cSJim Jagielski return false; 209*b1cdbd2cSJim Jagielski } 210*b1cdbd2cSJim Jagielski in_file.delete(); 211*b1cdbd2cSJim Jagielski 212*b1cdbd2cSJim Jagielski out_file = new File( installPath+File.separator+"user"+File.separator+"basic"+File.separator+"dialog.xlc" ); 213*b1cdbd2cSJim Jagielski out_file.createNewFile(); 214*b1cdbd2cSJim Jagielski 215*b1cdbd2cSJim Jagielski out = new FileWriter( out_file ); 216*b1cdbd2cSJim Jagielski 217*b1cdbd2cSJim Jagielski //split the string into a string array with one line of xml in each element 218*b1cdbd2cSJim Jagielski // String[] xmlArray = xmlLine.split("\n"); 219*b1cdbd2cSJim Jagielski for(int i=0; i<count + 1; i++) { 220*b1cdbd2cSJim Jagielski out.write(xmlArray[i]+"\n"); 221*b1cdbd2cSJim Jagielski if( ( xmlArray[i].indexOf( "<library:libraries xmlns:library" ) != -1 ) && ( xmlArray[i+1].indexOf( "ScriptBindingLibrary" ) == -1 ) ) { 222*b1cdbd2cSJim Jagielski String opSys = System.getProperty("os.name"); 223*b1cdbd2cSJim Jagielski if (opSys.indexOf("Windows") != -1) { 224*b1cdbd2cSJim Jagielski out.write(" <library:library library:name=\"ScriptBindingLibrary\" library:link=\"true\"/>\n" ); 225*b1cdbd2cSJim Jagielski } 226*b1cdbd2cSJim Jagielski else { 227*b1cdbd2cSJim Jagielski out.write(" <library:library library:name=\"ScriptBindingLibrary\" xlink:href=\"file://"+installPath+"/share/basic/ScriptBindingLibrary/dialog.xlb/\" xlink:type=\"simple\" library:link=\"true\"/>\n" ); 228*b1cdbd2cSJim Jagielski } 229*b1cdbd2cSJim Jagielski } 230*b1cdbd2cSJim Jagielski } 231*b1cdbd2cSJim Jagielski } 232*b1cdbd2cSJim Jagielski catch( Exception e ) { 233*b1cdbd2cSJim Jagielski String message = "\nError updating dialog.xlc, please view SFrameworkInstall.log."; 234*b1cdbd2cSJim Jagielski System.out.println(message); 235*b1cdbd2cSJim Jagielski e.printStackTrace(); 236*b1cdbd2cSJim Jagielski statusLabel.setText(message); 237*b1cdbd2cSJim Jagielski return false; 238*b1cdbd2cSJim Jagielski } 239*b1cdbd2cSJim Jagielski finally { 240*b1cdbd2cSJim Jagielski try { 241*b1cdbd2cSJim Jagielski out.close(); 242*b1cdbd2cSJim Jagielski } 243*b1cdbd2cSJim Jagielski catch(Exception e) { 244*b1cdbd2cSJim Jagielski System.out.println("Update dialog.xlc Failed, please view SFrameworkInstall.log."); 245*b1cdbd2cSJim Jagielski e.printStackTrace(); 246*b1cdbd2cSJim Jagielski System.err.println(e); 247*b1cdbd2cSJim Jagielski } 248*b1cdbd2cSJim Jagielski } 249*b1cdbd2cSJim Jagielski return true; 250*b1cdbd2cSJim Jagielski }// updateScriptXLC 251*b1cdbd2cSJim Jagielski 252*b1cdbd2cSJim Jagielski 253*b1cdbd2cSJim Jagielski } 254