1d71964d5SAndrew Rist// ************************************************************* 2d71964d5SAndrew Rist// 3d71964d5SAndrew Rist// Licensed to the Apache Software Foundation (ASF) under one 4d71964d5SAndrew Rist// or more contributor license agreements. See the NOTICE file 5d71964d5SAndrew Rist// distributed with this work for additional information 6d71964d5SAndrew Rist// regarding copyright ownership. The ASF licenses this file 7d71964d5SAndrew Rist// to you under the Apache License, Version 2.0 (the 8d71964d5SAndrew Rist// "License"); you may not use this file except in compliance 9d71964d5SAndrew Rist// with the License. You may obtain a copy of the License at 10d71964d5SAndrew Rist// 11d71964d5SAndrew Rist// http://www.apache.org/licenses/LICENSE-2.0 12d71964d5SAndrew Rist// 13d71964d5SAndrew Rist// Unless required by applicable law or agreed to in writing, 14d71964d5SAndrew Rist// software distributed under the License is distributed on an 15d71964d5SAndrew Rist// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d71964d5SAndrew Rist// KIND, either express or implied. See the License for the 17d71964d5SAndrew Rist// specific language governing permissions and limitations 18d71964d5SAndrew Rist// under the License. 19d71964d5SAndrew Rist// 20d71964d5SAndrew Rist// ************************************************************* 21cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.UnoRuntime); 22cdf0e10cSrcweirimportClass(Packages.com.sun.star.lang.XMultiComponentFactory); 23cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XDialogProvider); 24cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XDialog); 25cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.Exception); 26cdf0e10cSrcweirimportClass(Packages.com.sun.star.script.provider.XScriptContext); 27cdf0e10cSrcweir 28cdf0e10cSrcweirimportClass(java.lang.Thread); 29cdf0e10cSrcweirimportClass(java.lang.System); 30cdf0e10cSrcweir 31cdf0e10cSrcweirfunction tryLoadingLibrary( xmcf, context, name ) 32cdf0e10cSrcweir{ 33cdf0e10cSrcweir try 34cdf0e10cSrcweir { 35cdf0e10cSrcweir obj = xmcf.createInstanceWithContext( 36cdf0e10cSrcweir "com.sun.star.script.Application" + name + "LibraryContainer", 37cdf0e10cSrcweir context.getComponentContext()); 38cdf0e10cSrcweir 39cdf0e10cSrcweir xLibraryContainer = UnoRuntime.queryInterface(XLibraryContainer, obj); 40cdf0e10cSrcweir 41cdf0e10cSrcweir System.err.println("Got XLibraryContainer"); 42cdf0e10cSrcweir 43cdf0e10cSrcweir serviceObj = context.getComponentContext().getValueByName( 44cdf0e10cSrcweir "/singletons/com.sun.star.util.theMacroExpander"); 45cdf0e10cSrcweir 46cdf0e10cSrcweir xme = AnyConverter.toObject(new Type(XMacroExpander), serviceObj); 47cdf0e10cSrcweir 48cdf0e10cSrcweir bootstrapName = "bootstraprc"; 49cdf0e10cSrcweir if (System.getProperty("os.name").startsWith("Windows")) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir bootstrapName = "bootstrap.ini"; 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir libURL = xme.expandMacros( 55*910823aeSJürgen Schmidt "${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" + 56cdf0e10cSrcweir "/share/basic/ScriptBindingLibrary/" + 57cdf0e10cSrcweir name.toLowerCase() + ".xlb/"); 58cdf0e10cSrcweir 59cdf0e10cSrcweir System.err.println("libURL is: " + libURL); 60cdf0e10cSrcweir 61cdf0e10cSrcweir xLibraryContainer.createLibraryLink( 62cdf0e10cSrcweir "ScriptBindingLibrary", libURL, false); 63cdf0e10cSrcweir 64cdf0e10cSrcweir System.err.println("liblink created"); 65cdf0e10cSrcweir 66cdf0e10cSrcweir } 67cdf0e10cSrcweir catch (e) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir System.err.println("Got an exception loading lib: " + e.getMessage()); 70cdf0e10cSrcweir return false; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir return true; 73cdf0e10cSrcweir} 74cdf0e10cSrcweir 75cdf0e10cSrcweirfunction getDialogProvider() 76cdf0e10cSrcweir{ 77cdf0e10cSrcweir // UNO awt components of the Highlight dialog 78cdf0e10cSrcweir //get the XMultiServiceFactory 79cdf0e10cSrcweir xmcf = XSCRIPTCONTEXT.getComponentContext().getServiceManager(); 80cdf0e10cSrcweir 81cdf0e10cSrcweir args = new Array; 82cdf0e10cSrcweir //get the XDocument from the context 83cdf0e10cSrcweir args[0] = XSCRIPTCONTEXT.getDocument(); 84cdf0e10cSrcweir 85cdf0e10cSrcweir //try to create the DialogProvider 86cdf0e10cSrcweir try { 87cdf0e10cSrcweir obj = xmcf.createInstanceWithArgumentsAndContext( 88cdf0e10cSrcweir "com.sun.star.awt.DialogProvider", args, 89cdf0e10cSrcweir XSCRIPTCONTEXT.getComponentContext()); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir catch (e) { 92cdf0e10cSrcweir System.err.println("Error getting DialogProvider object"); 93cdf0e10cSrcweir return null; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir return UnoRuntime.queryInterface(XDialogProvider, obj); 97cdf0e10cSrcweir} 98cdf0e10cSrcweir 99cdf0e10cSrcweir//get the DialogProvider 100cdf0e10cSrcweirxDialogProvider = getDialogProvider(); 101cdf0e10cSrcweir 102cdf0e10cSrcweirif (xDialogProvider != null) 103cdf0e10cSrcweir{ 104cdf0e10cSrcweir //try to create the Highlight dialog (found in the ScriptBinding library) 105cdf0e10cSrcweir try 106cdf0e10cSrcweir { 107cdf0e10cSrcweir findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + 108cdf0e10cSrcweir "ScriptBindingLibrary.Highlight?location=application"); 109cdf0e10cSrcweir if( findDialog == null ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false || 112cdf0e10cSrcweir tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir System.err.println("Error loading ScriptBindingLibrary"); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir else 117cdf0e10cSrcweir { 118cdf0e10cSrcweir // try to create the Highlight dialog (found in the 119cdf0e10cSrcweir // ScriptBindingLibrary) 120cdf0e10cSrcweir findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + 121cdf0e10cSrcweir "ScriptBindingLibrary.Highlight?location=application"); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir //launch the dialog 126cdf0e10cSrcweir if ( findDialog != null ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir findDialog.execute(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131cdf0e10cSrcweir catch (e) { 132cdf0e10cSrcweir System.err.println("Got exception on first creating dialog: " + 133cdf0e10cSrcweir e.getMessage()); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir} 136