Hi, maybe I've missed something and but is ooRex a seperate scripting language and if yes should we add it to our snippet collection.
Tom > --- Ursprüngliche Nachricht --- > Von: "Rony G. Flatscher" <[EMAIL PROTECTED]> > An: [email protected] > Betreff: Re: [api-dev] Returnvalues from Macros - ooRexx example > Datum: Mon, 31 Oct 2005 17:53:02 +0100 > > Hi there, > > got a few more minutes, so enclosed you'll find the ooRexx > version/rendering of the C++/Java version of invoking a script in > another language, retrieve its return value and display it in the writer > component: > > ------------------- cut here ------------------ > oDesktop = UNO.createDesktop() -- get the default UNO Desktop > service object > xComponentLoader = oDesktop~XDesktop~XComponentLoader -- get the > componentLoader interface > > -- load an empty writer component > oWriterComponent = > xComponentLoader~loadComponentFromURL("private:factory/swriter", > "_blank", 0, .uno~noProps) > > -- get the script provider from the writer component > oSP=oWriterComponent~XScriptProviderSupplier~getScriptProvider > -- define the script we wish access to > oScript=oSP~getScript("vnd.sun.star.script:Tools.Misc.GetProductname?language=Basic&location=application") > > -- invoke the script: first define arguments, then invoke it > -- create 1-dimensional Java array of type Object > arguments =.bsf~bsf.createArray(.bsf4rexx~Object.class, 1) > -- create 2-dimensional Java array of primitive datatype "short" > indexes =.bsf~bsf.createArray(.bsf4rexx~short, 1, 1) > -- create 2-dimensional Java array of type Object > outparam =.bsf~bsf.createArray(.bsf4rexx~Object.class, 1, 1) > -- invoke script to get product name (includes version information) > pname=oScript~invoke(arguments, indexes, outparam) > > -- get XTextDocument interface, text and set it to "product name" > oWriterComponent~XTextDocument~getText~setString(pname) > > ::requires UNO.CLS -- load ooRexx support for UNO > ------------------- cut here ------------------ > > ---rony > > P.S.: Line comments start with two consecutive dashes: -- > > > Rony G. Flatscher wrote: > > > > >> would you have a Java rendering of that interesting code-snippets > >> handy by any chance? > >> > >> ---rony > > > > > > Well, fulfilling my own request :) here's an example in Java of > > running a macro via the scripting framework: > > > > ------------------- cut here ------------------ > > class Test { > > public static void main (String args[]) { > > // excerpted from "HardFormatting.java" from the OOo > > development package > > com.sun.star.frame.XDesktop xDesktop = null; > > com.sun.star.lang.XMultiComponentFactory xMCF = null; > > try { > > com.sun.star.uno.XComponentContext xContext = null; > > > > // (1) bootstrap the UNO runtime environment > > xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); > > > > // (2) get the service manager > > xMCF = xContext.getServiceManager(); > > if( xMCF != null ) > > { > > System.out.println("Connected to a running office ..."); > > // (3) start up an instance of office > > Object oDesktop = xMCF.createInstanceWithContext( > > "com.sun.star.frame.Desktop", xContext); > > // (4a) get the XDesktop interface object > > xDesktop = (com.sun.star.frame.XDesktop) > > com.sun.star.uno.UnoRuntime.queryInterface( > > com.sun.star.frame.XDesktop.class, oDesktop); > > > > // (4b) get the desktop's component loader interface object > > com.sun.star.frame.XComponentLoader xComponentLoader = > > (com.sun.star.frame.XComponentLoader) > > com.sun.star.uno.UnoRuntime.queryInterface( > > com.sun.star.frame.XComponentLoader.class, > xDesktop); > > > > // create an empty text ("swriter") document > > com.sun.star.beans.PropertyValue xEmptyArgs[] = // empty > > property array > > new com.sun.star.beans.PropertyValue[0]; > > > > // (5) create an empty word processor ("swriter") component > > (document) > > com.sun.star.lang.XComponent xComponent = // text document > > > > xComponentLoader.loadComponentFromURL("private:factory/swriter", > > "_blank", 0, xEmptyArgs); > > > > com.sun.star.script.provider.XScriptProvider oSP= > > (com.sun.star.script.provider.XScriptProvider) > > ( ((com.sun.star.script.provider.XScriptProviderSupplier) > > com.sun.star.uno.UnoRuntime.queryInterface( > > > > com.sun.star.script.provider.XScriptProviderSupplier.class, > > xComponent)).getScriptProvider() > > ); > > > > // load and run script > > com.sun.star.script.provider.XScript > > > oScript=oSP.getScript("vnd.sun.star.script:Tools.Misc.GetProductname?language=Basic&location=application"); > > > > System.out.println("oScript=["+oScript+"]"); > > > > java.lang.Object arguments [] = {null} , // > > single-dimensional array > > outparam [][] = { {null} }; // > > two-dimensional array > > short indexes[][]={ {0} }; // > > two-dimensional array > > > > Object pname= oScript.invoke(arguments, indexes, outparam); > > > > // insert product name into text document > > com.sun.star.text.XTextDocument xTextDoc = > > (com.sun.star.text.XTextDocument) > > com.sun.star.uno.UnoRuntime.queryInterface( > > com.sun.star.text.XTextDocument.class, xComponent); > > > > com.sun.star.text.XText xText = (com.sun.star.text.XText) > > com.sun.star.uno.UnoRuntime.queryInterface( > > com.sun.star.text.XText.class, xTextDoc.getText()); > > > > xText.setString((String) pname); > > > > } > > else > > System.out.println("Not able to create desktop object."); > > } > > catch( Exception e) { > > e.printStackTrace(System.err); > > System.exit(1); > > } > > System.err.println("Successful run."); > > System.exit(0); > > } > > } > > ------------------- cut here ------------------ > > > > ---rony > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- 10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail +++ GMX - die erste Adresse für Mail, Message, More +++ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
