summaryrefslogtreecommitdiff
path: root/scripting/java/org/openoffice/netbeans/modules/office/resources/templates/HelloWorld.java_
blob: 36e66aeeb20e3d16e18f57c63c77b1950c4bf138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// If using XMultiServiceFactory need to uncomment import directive below:
//import com.sun.star.lang.XMultiServiceFactory;

// If using XDesktop need to uncomment import directive below:
//import com.sun.star.frame.XDesktop;

import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.*;
import com.sun.star.text.*;

import drafts.com.sun.star.script.framework.runtime.XScriptContext;


public class HelloWorld {

  public void printHello(XScriptContext xSc) {
      
      /* Methods available from XScriptContext: 
            xSc.getDocument() returns XModel
            xSc.getDesktop() returns XDesktop
            xSc.getMultiComponentFactory() returns XMultiComponentFactory
        */
        
        // Getting the current document as a component
        XComponent xcomponent = xSc.getDocument();
        
        // Getting the text document object
        XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(
XTextDocument.class, xcomponent);

        //Getting the text object
        XText oText = xtextdocument.getText();

        //Create a cursor object
        XTextCursor oCursor = oText.createTextCursor();

        // Print out Hello World
        oText.insertString( oCursor, "**** HELLO ****", false );
  }

}