| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 4 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 10 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
* contributor license agreements. See the NOTICE file distributed |
| 12 |
* with this work for additional information regarding copyright |
| 13 |
* ownership. The ASF licenses this file to you under the Apache |
| 14 |
* License, Version 2.0 (the "License"); you may not use this file |
| 15 |
* except in compliance with the License. You may obtain a copy of |
| 16 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
*/ |
| 18 |
/* |
| 19 |
Import standard OpenOffice.org API classes. For more information on |
| 20 |
these classes and the OpenOffice.org API, see the OpenOffice.org |
| 21 |
Developers Guide at: |
| 22 |
|
| 23 |
https://api.libreoffice.org/ |
| 24 |
*/ |
| 25 |
|
| 26 |
import com.sun.star.uno.UnoRuntime; |
| 27 |
import com.sun.star.uno.XComponentContext; |
| 28 |
import com.sun.star.frame.XDesktop; |
| 29 |
import com.sun.star.frame.XModel; |
| 30 |
|
| 31 |
/* |
| 32 |
Import XScriptContext class. An instance of this class is available |
| 33 |
to all BeanShell scripts in the global variable "XSCRIPTCONTEXT". This |
| 34 |
variable can be used to access the document for which this script |
| 35 |
was invoked. |
| 36 |
|
| 37 |
Methods available are: |
| 38 |
|
| 39 |
XSCRIPTCONTEXT.getDocument() returns XModel |
| 40 |
XSCRIPTCONTEXT.getInvocationContext() returns XScriptInvocationContext or NULL |
| 41 |
XSCRIPTCONTEXT.getDesktop() returns XDesktop |
| 42 |
XSCRIPTCONTEXT.getComponentContext() returns XComponentContext |
| 43 |
|
| 44 |
For more information on using this class see the scripting |
| 45 |
developer guides at: |
| 46 |
|
| 47 |
https://api.libreoffice.org/docs/DevelopersGuide/ScriptingFramework/ScriptingFramework.xhtml |
| 48 |
*/ |
| 49 |
|
| 50 |
// Hello World in BeanShell |
| 51 |
import com.sun.star.text.XTextDocument; |
| 52 |
import com.sun.star.text.XText; |
| 53 |
import com.sun.star.text.XTextRange; |
| 54 |
|
| 55 |
oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext()); |
| 56 |
if ( oDoc == null ) |
| 57 |
oDoc = XSCRIPTCONTEXT.getDocument(); |
| 58 |
|
| 59 |
xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc); |
| 60 |
xText = xTextDoc.getText(); |
| 61 |
xTextRange = xText.getEnd(); |
| 62 |
xTextRange.setString( "Hello World (in BeanShell)" ); |
| 63 |
|
| 64 |
// BeanShell scripts in LibreOffice should always return 0 |
| 65 |
return 0; |