1// *************************************************************
2//
3//  Licensed to the Apache Software Foundation (ASF) under one
4//  or more contributor license agreements.  See the NOTICE file
5//  distributed with this work for additional information
6//  regarding copyright ownership.  The ASF licenses this file
7//  to you under the Apache License, Version 2.0 (the
8//  "License"); you may not use this file except in compliance
9//  with the License.  You may obtain a copy of the License at
10//
11//    http://www.apache.org/licenses/LICENSE-2.0
12//
13//  Unless required by applicable law or agreed to in writing,
14//  software distributed under the License is distributed on an
15//  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16//  KIND, either express or implied.  See the License for the
17//  specific language governing permissions and limitations
18//  under the License.
19//
20// *************************************************************
21// Hello World in JavaScript
22// Import standard OpenOffice.org API classes. For more information on
23// these classes and the OpenOffice.org API, see the OpenOffice.org
24// Developers Guide at:
25// http://api.openoffice.org/
26
27importClass(Packages.com.sun.star.uno.UnoRuntime);
28importClass(Packages.com.sun.star.text.XTextDocument);
29importClass(Packages.com.sun.star.text.XText);
30importClass(Packages.com.sun.star.text.XTextRange);
31importClass(Packages.com.sun.star.frame.XModel);
32
33// Import XScriptContext class. An instance of this class is available
34// to all JavaScript scripts in the global variable "XSCRIPTCONTEXT". This
35// variable can be used to access the document for which this script
36// was invoked.
37//
38// Methods available are:
39//
40//   XSCRIPTCONTEXT.getDocument() returns XModel
41//   XSCRIPTCONTEXT.getInvocationContext() returns XScriptInvocationContext or NULL
42//   XSCRIPTCONTEXT.getDesktop() returns XDesktop
43//   XSCRIPTCONTEXT.getComponentContext() returns XComponentContext
44//
45// For more information on using this class see the scripting
46// developer guides at:
47//
48//   http://api.openoffice.org/docs/DevelopersGuide/ScriptingFramework/ScriptingFramework.xhtml
49//
50
51oDoc = UnoRuntime.queryInterface(XModel,XSCRIPTCONTEXT.getInvocationContext());
52if ( !oDoc )
53  oDoc = XSCRIPTCONTEXT.getDocument();
54xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
55xText = xTextDoc.getText();
56xTextRange = xText.getEnd();
57xTextRange.setString( "Hello World (in JavaScript)" );
58