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