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 .
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);
25 importClass(java.lang.Thread);
26 importClass(java.lang.System);
28 function tryLoadingLibrary( xmcf, context, name )
32 obj = xmcf.createInstanceWithContext(
33 "com.sun.star.script.Application" + name + "LibraryContainer",
34 context.getComponentContext());
36 xLibraryContainer = UnoRuntime.queryInterface(XLibraryContainer, obj);
38 System.err.println("Got XLibraryContainer");
40 serviceObj = context.getComponentContext().getValueByName(
41 "/singletons/com.sun.star.util.theMacroExpander");
43 xme = AnyConverter.toObject(new Type(XMacroExpander), serviceObj);
45 bootstrapName = "bootstraprc";
46 if (System.getProperty("os.name").startsWith("Windows"))
48 bootstrapName = "bootstrap.ini";
51 libURL = xme.expandMacros(
52 "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/basic/ScriptBindingLibrary/" +
53 name.toLowerCase() + ".xlb/");
55 System.err.println("libURL is: " + libURL);
57 xLibraryContainer.createLibraryLink(
58 "ScriptBindingLibrary", libURL, false);
60 System.err.println("liblink created");
65 System.err.println("Got an exception loading lib: " + e.getMessage());
71 function getDialogProvider()
73 // UNO awt components of the Highlight dialog
74 //get the XMultiServiceFactory
75 xmcf = XSCRIPTCONTEXT.getComponentContext().getServiceManager();
78 //get the XDocument from the context
79 args[0] = XSCRIPTCONTEXT.getDocument();
81 //try to create the DialogProvider
83 obj = xmcf.createInstanceWithArgumentsAndContext(
84 "com.sun.star.awt.DialogProvider", args,
85 XSCRIPTCONTEXT.getComponentContext());
88 System.err.println("Error getting DialogProvider object");
92 return UnoRuntime.queryInterface(XDialogProvider, obj);
95 //get the DialogProvider
96 xDialogProvider = getDialogProvider();
98 if (xDialogProvider != null)
100 //try to create the Highlight dialog (found in the ScriptBinding library)
103 findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
104 "ScriptBindingLibrary.Highlight?location=application");
105 if( findDialog == null )
107 if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false ||
108 tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false)
110 System.err.println("Error loading ScriptBindingLibrary");
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");
122 if ( findDialog != null )
124 findDialog.execute();
128 System.err.println("Got exception on first creating dialog: " +