1// Hello World in JavaScript
2// Import standard OpenOffice.org API classes. For more information on
3// these classes and the OpenOffice.org API, see the OpenOffice.org
4// Developers Guide at:
5// http://api.openoffice.org/
6
7importClass(Packages.com.sun.star.uno.UnoRuntime);
8importClass(Packages.com.sun.star.text.XTextDocument);
9importClass(Packages.com.sun.star.text.XText);
10importClass(Packages.com.sun.star.text.XTextRange);
11importClass(Packages.com.sun.star.frame.XModel);
12
13// Import XScriptContext class. An instance of this class is available
14// to all JavaScript scripts in the global variable "XSCRIPTCONTEXT". This
15// variable can be used to access the document for which this script
16// was invoked.
17//
18// Methods available are:
19//
20//   XSCRIPTCONTEXT.getDocument() returns XModel
21//   XSCRIPTCONTEXT.getInvocationContext() returns XScriptInvocationContext or NULL
22//   XSCRIPTCONTEXT.getDesktop() returns XDesktop
23//   XSCRIPTCONTEXT.getComponentContext() returns XComponentContext
24//
25// For more information on using this class see the scripting
26// developer guides at:
27//
28//   http://api.openoffice.org/docs/DevelopersGuide/ScriptingFramework/ScriptingFramework.xhtml
29//
30
31oDoc = UnoRuntime.queryInterface(XModel,XSCRIPTCONTEXT.getInvocationContext());
32if ( !oDoc )
33  oDoc = XSCRIPTCONTEXT.getDocument();
34xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
35xText = xTextDoc.getText();
36xTextRange = xText.getEnd();
37xTextRange.setString( "Hello World (in JavaScript)" );
38