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]