| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 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/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 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 . |
| 17 |
*/ |
| 18 |
importClass(Packages.com.sun.star.uno.UnoRuntime); |
| 19 |
importClass(Packages.com.sun.star.lang.XMultiComponentFactory); |
| 20 |
importClass(Packages.com.sun.star.awt.XDialogProvider); |
| 21 |
importClass(Packages.com.sun.star.awt.XDialog); |
| 22 |
importClass(Packages.com.sun.star.uno.Exception); |
| 23 |
importClass(Packages.com.sun.star.script.provider.XScriptContext); |
| 24 |
|
| 25 |
importClass(java.lang.Thread); |
| 26 |
importClass(java.lang.System); |
| 27 |
|
| 28 |
function tryLoadingLibrary( xmcf, context, name ) |
| 29 |
{ |
| 30 |
try |
| 31 |
{ |
| 32 |
obj = xmcf.createInstanceWithContext( |
| 33 |
"com.sun.star.script.Application" + name + "LibraryContainer", |
| 34 |
context.getComponentContext()); |
| 35 |
|
| 36 |
xLibraryContainer = UnoRuntime.queryInterface(XLibraryContainer, obj); |
| 37 |
|
| 38 |
System.err.println("Got XLibraryContainer"); |
| 39 |
|
| 40 |
serviceObj = context.getComponentContext().getValueByName( |
| 41 |
"/singletons/com.sun.star.util.theMacroExpander"); |
| 42 |
|
| 43 |
xme = AnyConverter.toObject(new Type(XMacroExpander), serviceObj); |
| 44 |
|
| 45 |
bootstrapName = "bootstraprc"; |
| 46 |
if (System.getProperty("os.name").startsWith("Windows")) |
| 47 |
{ |
| 48 |
bootstrapName = "bootstrap.ini"; |
| 49 |
} |
| 50 |
|
| 51 |
libURL = xme.expandMacros( |
| 52 |
"$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/basic/ScriptBindingLibrary/" + |
| 53 |
name.toLowerCase() + ".xlb/"); |
| 54 |
|
| 55 |
System.err.println("libURL is: " + libURL); |
| 56 |
|
| 57 |
xLibraryContainer.createLibraryLink( |
| 58 |
"ScriptBindingLibrary", libURL, false); |
| 59 |
|
| 60 |
System.err.println("liblink created"); |
| 61 |
|
| 62 |
} |
| 63 |
catch (e) |
| 64 |
{ |
| 65 |
System.err.println("Got an exception loading lib: " + e.getMessage()); |
| 66 |
return false; |
| 67 |
} |
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
function getDialogProvider() |
| 72 |
{ |
| 73 |
// UNO awt components of the Highlight dialog |
| 74 |
//get the XMultiServiceFactory |
| 75 |
xmcf = XSCRIPTCONTEXT.getComponentContext().getServiceManager(); |
| 76 |
|
| 77 |
args = new Array; |
| 78 |
//get the XDocument from the context |
| 79 |
args[0] = XSCRIPTCONTEXT.getDocument(); |
| 80 |
|
| 81 |
//try to create the DialogProvider |
| 82 |
try { |
| 83 |
obj = xmcf.createInstanceWithArgumentsAndContext( |
| 84 |
"com.sun.star.awt.DialogProvider", args, |
| 85 |
XSCRIPTCONTEXT.getComponentContext()); |
| 86 |
} |
| 87 |
catch (e) { |
| 88 |
System.err.println("Error getting DialogProvider object"); |
| 89 |
return null; |
| 90 |
} |
| 91 |
|
| 92 |
return UnoRuntime.queryInterface(XDialogProvider, obj); |
| 93 |
} |
| 94 |
|
| 95 |
//get the DialogProvider |
| 96 |
xDialogProvider = getDialogProvider(); |
| 97 |
|
| 98 |
if (xDialogProvider != null) |
| 99 |
{ |
| 100 |
//try to create the Highlight dialog (found in the ScriptBinding library) |
| 101 |
try |
| 102 |
{ |
| 103 |
findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + |
| 104 |
"ScriptBindingLibrary.Highlight?location=application"); |
| 105 |
if( findDialog == null ) |
| 106 |
{ |
| 107 |
if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false || |
| 108 |
tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false) |
| 109 |
{ |
| 110 |
System.err.println("Error loading ScriptBindingLibrary"); |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
// try to create the Highlight dialog (found in the |
| 115 |
// ScriptBindingLibrary) |
| 116 |
findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" + |
| 117 |
"ScriptBindingLibrary.Highlight?location=application"); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
//launch the dialog |
| 122 |
if ( findDialog != null ) |
| 123 |
{ |
| 124 |
findDialog.execute(); |
| 125 |
} |
| 126 |
} |
| 127 |
catch (e) { |
| 128 |
System.err.println("Got exception on first creating dialog: " + |
| 129 |
e.getMessage()); |
| 130 |
} |
| 131 |
} |