Some known limitations of the JavaScript Runtime are:
pkgchk <path to your downloaded jsruntime.zip>
importClass(Packages.com.sun.star.uno.UnoRuntime); importClass(Packages.com.sun.star.text.XTextDocument); var oModel = ScriptContext.getDocument(); var oTextdoc = UnoRuntime.queryInterface(XTextDocument, oModel); var oText = oTextdoc.getText(); var oCursor = oText.createTextCursor(); oText.insertString(oCursor, "Hello World", false);
The ScriptContext variable above is a global instance of the XScriptContext type
which is available to all JavaScript scripts executed by the Scripting
Framework. See Writing Office Scripts
and the XScriptContext type for the methods available for the XScriptContext type.
Invoking a JavaScript script in OpenOffice.org
You have two choices for making your Hello World script available for
execution within OpenOffice.org:
You can use the CommandLineTools class available with the Scripting Framework to generate and deploy a Script Parcel. To do this with the Hello World script:
java CommandLineTools -g -l Rhino=.js
java CommandLineTools -d <path to helloworld.sxp> <path to your OpenOffice.org>/user/Scripts
<?xml version="1.0" encoding="UTF-8"?> <parcel language="Rhino" xmlns:parcel="scripting.dtd"> <script language="Rhino"> <locale lang="en"> <displayname value="HelloWorld"/> <description>Insert Hello World in a document</description> </locale> <functionname value="helloworld.js"/> <logicalname value="HelloWorld.Rhino"/> </script> </parcel>
Once you have the JavaScript ScriptRuntime installed and the Hello World script deployed restart OpenOffice.org. See the Scripting Framework User Guide for instructions on how to bind your script to a menu item, key binding or event. To see your script set the Location to User and the Language to Rhino in the Assign dialogs.
If you want to change your Hello World script, just edit the helloworld.js file in a text editor, save it and rerun the script using your menu, key or event binding. You don't need to restart OpenOffice.org or rebind to the script as the Scripting Framework reloads the script each time it runs it.