forked from amazingfate/loongoffice
...they contained no class files anymore, due to missing gb_Jar_set_packageroot calls. However, those calls only work for subdirectories, i.e., the example .java files need to be put into a package (I chose org.libreoffice.example.java_scripts) for all of them). This in turn required adaption of the parcel-descriptor.xml files; not sure what the logicalname entries there are good for if anything -- the macro names at "Tools - Macros - Run Macro..." now unfortunately(?) contain the fully qualified paths for the HelloWorld, HighlightText, and MemoryUpdate examples. There are additional examples at scripting/examples/java/ that apparently do not get packaged (but I adapted them anyway).
25 lines
670 B
Java
25 lines
670 B
Java
package org.libreoffice.example.java_scripts;
|
|
|
|
import com.sun.star.script.provider.XScriptContext;
|
|
import com.sun.star.uno.UnoRuntime;
|
|
import com.sun.star.text.XTextDocument;
|
|
import com.sun.star.text.XTextRange;
|
|
import com.sun.star.text.XText;
|
|
/**
|
|
* HelloWorld class
|
|
*
|
|
*/
|
|
public class HelloWorld {
|
|
public static void printHW(XScriptContext xSc) {
|
|
|
|
// getting the text document object
|
|
XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(
|
|
XTextDocument.class, xSc.getDocument());
|
|
XText xText = xtextdocument.getText();
|
|
XTextRange xTextRange = xText.getEnd();
|
|
xTextRange.setString( "Hello World (in Java)" );
|
|
|
|
}// printHW
|
|
|
|
}
|