1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package installer; 23 24 import java.lang.String; 25 import java.io.*; 26 import javax.swing.*; 27 public class Register{ 28 private static String[] singletonDefParams = { "drafts.com.sun.star.script.framework.theScriptRuntimeForJava=drafts.com.sun.star.script.framework.ScriptRuntimeForJava", 29 "drafts.com.sun.star.script.framework.storage.theScriptStorageManager=drafts.com.sun.star.script.framework.storage.ScriptStorageManager", 30 "drafts.com.sun.star.script.framework.theScriptRuntimeManager=drafts.com.sun.star.script.framework.ScriptRuntimeManager"}; 31 32 quotedString( String stringToQuote )33 private static String quotedString ( String stringToQuote ) { 34 String doubleQuote = "\""; 35 String result = new String ( doubleQuote + stringToQuote + doubleQuote ); 36 return result; 37 } regSingletons( String path, String progPath, String opSys, JLabel statusLabel )38 private static boolean regSingletons( String path, String progPath, String opSys, JLabel statusLabel ) { 39 try{ 40 boolean goodResult = false; 41 String[] env = new String[1]; 42 String regCmd = null; 43 ExecCmd command = new ExecCmd(); 44 for ( int i=0; i<singletonDefParams.length; i++){ 45 if ( opSys.indexOf( "Windows" ) == -1 ){ 46 // Not windows 47 env[0] = "LD_LIBRARY_PATH=" + progPath; 48 command.exec( "chmod a+x " + progPath + "regsingleton", null ); 49 regCmd = progPath + "regsingleton " + path + "user" + File.separator + "uno_packages" + File.separator + "cache" + File.separator + "services.rdb " + singletonDefParams[i]; 50 goodResult = command.exec( regCmd, env ); 51 } 52 else { 53 // Windows 54 regCmd = quotedString( progPath + "regsingleton.exe" ) + " " + quotedString( path + "user" + File.separator + "uno_packages" + File.separator + "cache" + File.separator + "services.rdb" ) + " " + quotedString( singletonDefParams[i] ); 55 goodResult = command.exec( regCmd,null ); 56 } 57 if ( !goodResult ){ 58 System.out.println("Regsingleton cmd failed, cmd: " + regCmd ); 59 statusLabel.setText("Regsingleton ScriptRuntimeForJava Failed, please view SFrameworkInstall.log"); 60 return false; 61 } 62 } 63 } 64 catch ( Exception e ) { 65 String message = "\nError installing scripting package, please view SFrameworkInstall.log."; 66 System.out.println(message); 67 e.printStackTrace(); 68 statusLabel.setText(message); 69 return false; 70 } 71 return true; 72 73 74 } register(String path, JLabel statusLabel)75 public static boolean register(String path, JLabel statusLabel) { 76 String[] packages = {"ooscriptframe.zip", "bshruntime.zip", "jsruntime.zip"}; 77 78 try { 79 String s=null; 80 boolean goodResult = false; 81 String env[] = new String[1]; 82 ExecCmd command = new ExecCmd(); 83 boolean isWindows = 84 (System.getProperty("os.name").indexOf("Windows") != -1); 85 86 String progpath = path.concat("program" + File.separator); 87 88 statusLabel.setText("Registering Scripting Framework..."); 89 90 // pkgchk Scripting Framework Components 91 statusLabel.setText("Registering Scripting Framework Components..."); 92 System.out.println("Registering Scripting Framework Components..."); 93 94 for (int i = 0; i < packages.length; i++) { 95 String cmd = ""; 96 97 if (!isWindows) { 98 env[0]="LD_LIBRARY_PATH=" + progpath; 99 100 goodResult = command.exec("chmod a+x " + progpath + "pkgchk", null ); 101 102 if ( goodResult ){ 103 cmd = progpath + "pkgchk -s -f " + progpath + packages[i]; 104 105 System.err.println(cmd); 106 goodResult = command.exec(cmd, env); 107 } 108 } 109 else { 110 cmd = "\"" + progpath + "pkgchk.exe\" -s -f \"" + progpath + 111 packages[i] + "\""; 112 113 System.err.println(cmd); 114 goodResult =command.exec(cmd,null); 115 116 } 117 if (!goodResult) { 118 System.err.println("\nPkgChk Failed"); 119 120 if(!isWindows) 121 System.err.println("Command: " + cmd + "\n" + env[0]); 122 else 123 System.err.println("Command: \"" + cmd + "\""); 124 125 statusLabel.setText( 126 "PkgChk Failed, please view SFrameworkInstall.log"); 127 128 return false; 129 } 130 } 131 132 // if ( !regSingletons( path, progpath, opSys, statusLabel ) ) 133 // { 134 // return false; 135 // } 136 // updating ProtocolHandler 137 /* statusLabel.setText("Updating ProtocolHandler..."); 138 if(!FileUpdater.updateProtocolHandler(path, statusLabel)) { 139 statusLabel.setText("Updating ProtocolHandler failed, please view SFrameworkInstall.log"); 140 return false; 141 } */ 142 143 // updating StarBasic libraries 144 statusLabel.setText("Updating StarBasic libraries..."); 145 if(!FileUpdater.updateScriptXLC(path, statusLabel)) { 146 statusLabel.setText("Updating user/basic/script.xlc failed, please view SFrameworkInstall.log"); 147 return false; 148 } 149 if(!FileUpdater.updateDialogXLC(path, statusLabel)) { 150 statusLabel.setText("Updating user/basic/dialog.xlc failed, please view SFrameworkInstall.log"); 151 return false; 152 } 153 154 } 155 catch(Exception e){ 156 String message = "\nError installing scripting package, please view SFrameworkInstall.log."; 157 System.out.println(message); 158 e.printStackTrace(); 159 statusLabel.setText(message); 160 return false; 161 } 162 return true; 163 }// register 164 165 }//Register 166