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;
57import bsh.Interpreter;
58
59oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
60if ( oDoc == null )
61  oDoc = XSCRIPTCONTEXT.getDocument();
62
63xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
64xText = xTextDoc.getText();
65xTextRange = xText.getEnd();
66
67sb = new StringBuilder();
68sb.append("Hello World (in BeanShell v" + Interpreter.VERSION + ") \n\n");
69
70//
71import java.util.Map;
72import java.util.TreeMap;
73
74env=new TreeMap(System.getenv());
75
76ks=env.keySet();  // get keys
77ksit=ks.iterator(); // get iterator
78
79sb.append( "ENV Dump:\n" );
80while ( ksit.hasNext() )
81{
82      envName=ksit.next();
83      sb .append("\n[") .append(envName) .append("]=[") .append(env.get(envName)) .append("] ");
84}
85
86xText.getEnd().setString( sb.toString() );
87
88// BeanShell OpenOffice.org scripts should always return 0
89return 0;
90