summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello')
-rw-r--r--odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java46
-rw-r--r--odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/parcel-descriptor.xml17
2 files changed, 63 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java
new file mode 100644
index 000000000000..b120c4cfa9f9
--- /dev/null
+++ b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java
@@ -0,0 +1,46 @@
+import com.sun.star.script.provider.XScriptContext;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.lang.XComponent;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextRange;
+import com.sun.star.text.XText;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.awt.ActionEvent;
+
+public class SayHello
+{
+ public static void start(XScriptContext ctxt, ActionEvent e)
+ throws Exception
+ {
+ SayHello.start(ctxt);
+ }
+
+ public static void start(XScriptContext ctxt)
+ throws Exception
+ {
+ // getting the text document object
+ XTextDocument xTextDocument = createDocument(ctxt);
+
+ XText xText = xTextDocument.getText();
+ XTextRange xTextRange = xText.getEnd();
+ xTextRange.setString("Hello");
+ }
+
+ private static XTextDocument createDocument(XScriptContext ctxt)
+ throws Exception
+ {
+ XComponentLoader loader = (XComponentLoader)
+ UnoRuntime.queryInterface(
+ XComponentLoader.class, ctxt.getDesktop());
+
+ XComponent comp = loader.loadComponentFromURL(
+ "private:factory/swriter", "_blank", 4, new PropertyValue[0]);
+
+ XTextDocument doc = (XTextDocument)
+ UnoRuntime.queryInterface( XTextDocument.class, comp);
+
+ return doc;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/parcel-descriptor.xml b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/parcel-descriptor.xml
new file mode 100644
index 000000000000..3f317a3495a2
--- /dev/null
+++ b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/parcel-descriptor.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<parcel language="Java" xmlns:parcel="scripting.dtd">
+ <script language="Java">
+ <locale lang="en">
+ <displayname value="SayHello"/>
+ <description>
+ Prints Hello in a Writer document
+ </description>
+ </locale>
+ <functionname value="SayHello.start"/>
+ <logicalname value="SayHello.start"/>
+ <languagedepprops>
+ <prop name="classpath" value="SayHello.jar"/>
+ </languagedepprops>
+ </script>
+</parcel>