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/*
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
26    http://api.openoffice.org/
27*/
28
29import com.sun.star.uno.UnoRuntime;
30import com.sun.star.uno.XComponentContext;
31import com.sun.star.frame.XDesktop;
32import com.sun.star.frame.XModel;
33
34/*
35    Import XScriptContext class. An instance of this class is available
36    to all BeanShell scripts in the global variable "XSCRIPTCONTEXT". This
37    variable can be used to access the document for which this script
38    was invoked.
39
40    Methods available are:
41
42        XSCRIPTCONTEXT.getDocument() returns XModel
43        XSCRIPTCONTEXT.getInvocationContext() returns XScriptInvocationContext or NULL
44        XSCRIPTCONTEXT.getDesktop() returns XDesktop
45        XSCRIPTCONTEXT.getComponentContext() returns XComponentContext
46
47    For more information on using this class see the scripting
48    developer guides at:
49
50        http://api.openoffice.org/docs/DevelopersGuide/ScriptingFramework/ScriptingFramework.xhtml
51*/
52
53// Hello World in BeanShell
54import com.sun.star.text.XTextDocument;
55import com.sun.star.text.XText;
56import com.sun.star.text.XTextRange;
57
58oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
59if ( oDoc == null )
60  oDoc = XSCRIPTCONTEXT.getDocument();
61
62xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
63xText = xTextDoc.getText();
64xTextRange = xText.getEnd();
65xTextRange.setString( "Hello World (in BeanShell)" );
66
67// BeanShell OpenOffice.org scripts should always return 0
68return 0;
69