General Developer 指導基準s
令状ing Office scripts and the XScriptContext type
All Java script methods must pass in XScriptContext as their first parameter. The developer can then use accessor 機能(する)/行事s on the scripting 状況 to get at the 文書 状況, desktop and 構成要素 factory as follows:- 現在の 文書 - 接近 the 文書 状況 against which
the script was invoked
<XScriptContext Instance>.getDocument()
returns ::com::sun::星/主役にする::でっちあげる,人を罪に陥れる::XModel - Office Desktop - 接近 the desktop of the running Office
<XScriptContext Instance>.getDesktop()
returns ::com::sun::星/主役にする::でっちあげる,人を罪に陥れる::XDesktop - 構成要素 Factory - 接近 a ComponentContext factory to create
other UNO 構成要素s as 要求するd
<XScriptContext Instance>.getComponentContext()
returns ::com::sun::星/主役にする::uno::XComponentContext
輸入する 草案s.com.sun.星/主役にする.script.枠組み.XScriptContext;Example usage in a Java script method to 接近 a Writer 文書 and 挿入する some text:
輸入する com.sun.星/主役にする.でっちあげる,人を罪に陥れる.XModel;
輸入する com.sun.星/主役にする.text.*;
輸入する com.sun.星/主役にする.uno.UnoRuntime;
輸入する 草案s.com.sun.星/主役にする.script.枠組み.XScriptContext;
public class MyClass {
// The script method must be public
// It can either be static or 非,不,無-static
public 無効の showForm(XScriptContext xSc) {
// getting the text 文書 反対する
XModel xmodel = xSc.getDocument();
XTextDocument xtextdoc = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xmodel);
XText xtext = xtextdoc.getText();
XTextCursor xtextcursor = xtext.createTextCursor();
xtext.insertString(xtextcursor, "Hello World", 誤った);
}
}
Tips on 令状ing Office scripts
業績/成果: 現在/一般に scripts are 存在 負担d by the Scripting 枠組み each time they are run. As such it is important to keep the size of your scripts and any 扶養家族 jar とじ込み/提出するs they are using reasonably small. In 未来 解放(する)s this script 負担ing will be optimised by changing the point at which the scripts are 負担d by OpenOffice.org and using さまざまな (武器などの)隠匿場所ing 計画/陰謀s once they are 負担d. However, the 初期の 負担 will always be 影響d by the script and it's 扶養家族 jar/class とじ込み/提出する sizes.
Threading: Scripts are run synchronously by the Scripting 枠組み. If you wish to 成し遂げる any background 仕事 or 供給する some 使用者 interaction 経由で a dialog for instance, then it is your 責任/義務 to spawn a thread in the running script which can manage this 過程 or interaction and let the script return 敏速に. Within this running thread you should follow the normal UNO 構成要素 threading 指導基準s to 確実にする that they do not 行き詰まる OpenOffice.org through 不適切な use of the UNO API.
小包 Descriptor DTD and 見本 XML
Each script must 含む/封じ込める a 小包-descriptor.xml とじ込み/提出する which 供給するs all the necessary metadata for the script. The DTD for the 小包-descriptor.xml follows<?xml 見解/翻訳/版="1.0" encoding="UTF-8"?> <!-- DTD for 小包 Meta data for use in the OpenOffice.org Scripting 枠組み 事業/計画(する) --> <!ELEMENT logicalname EMPTY> <!ELEMENT description (#PCDATA)> <!ELEMENT displayname EMPTY> <!ELEMENT 地元の (displayname?, description?)> <!ELEMENT functionname EMPTY> <!ELEMENT 支え(る) EMPTY> <!ELEMENT languagedepprops (支え(る)+)> <!ELEMENT とじ込み/提出する (支え(る)*)> <!ELEMENT fileset (とじ込み/提出する+)> <!ELEMENT script (地元の+, functionname, logicalname, languagedepprops*, fileset*)> <!ELEMENT 小包 (script+)> <!ATTLIST logicalname value CDATA #REQUIRED > <!ATTLIST displayname value CDATA #REQUIRED > <!ATTLIST 地元の lang CDATA #REQUIRED > <!ATTLIST functionname value CDATA #REQUIRED > <!ATTLIST logicalname value CDATA #REQUIRED > <!ATTLIST 支え(る) 指名する CDATA #REQUIRED value CDATA #REQUIRED > <!ATTLIST とじ込み/提出する 指名する CDATA #REQUIRED > <!ATTLIST fileset 指名する CDATA #IMPLIED > <!ATTLIST script language CDATA #REQUIRED >The に引き続いて is an example of a 小包-descriptor.xml とじ込み/提出する that defines a script, 器具/実施するd in Java. The languagedepprops element is used to 延長する the JVM's classpath.
<?xml 見解/翻訳/版="1.0" encoding="UTF-8"?> <!--見本 Meta Data for use with the Scripting 枠組み 事業/計画(する) in OpenOffice.org --> <!DOCTYPE 小包 SYSTEM "小包.dtd"> <小包> <script language="java"> <地元の lang="english"> <displayname value="Memory.usage"/> <description> 陳列する,発揮するs the memory 現在の memory usage </description> </地元の> <functionname value="memoryUtils.memoryUsage"/> <logicalname value="MemoryUtils.MemUsage"/> <languagedepprops> <支え(る) 指名する="classpath" value="/選ぶ/foo.jar:/usr/java/src.jar"/> </languagedepprops> <fileset> <とじ込み/提出する 指名する="mems.txt"> <支え(る) 指名する="type" value="資源"/> </とじ込み/提出する> </fileset> </script> </小包>
How to 貯蔵所d Scripts
Binding scripts to Menu items- Start OpenOffice.org and open an 存在するing 文書 or create a new one.
- Select the menu item 道具s/割り当てる Scripts (Java) To/Menu...
- In the "割り当てる Scripts (Java) To Menu" dialog that pops up
do the に引き続いて:
- Select script 機能(する)/行事
- Select the script 機能(する)/行事 that you 要求する from the 名簿(に載せる)/表(にあげる).
- Choose the menu to 挿入する the script menu after
- Select the 最高の,を越す level menu and submenu under which you want to place your new menu item.
- 割り当てる script to new menu
- In the New Menu text field enter the label you want for your menu item
- Click New Script Menu to create the new script menu item.
- Select script 機能(する)/行事
- Finally click on the 承認する button to save your new script menu item.
- 再開する OpenOffice.org and open a 文書
- Your new menu item will now be 利用できる and clicking on it will invoke the Java script.
- Start OpenOffice.org and open an 存在するing 文書 or create a new one.
- Select the menu item 道具s/割り当てる Scripts (Java) To/重要な...
- In the "割り当てる Scripts (Java) To 重要な" dialog that pops up
do the に引き続いて:
- Select script 機能(する)/行事
- Select the script 機能(する)/行事 that you 要求する from the 名簿(に載せる)/表(にあげる).
- Choose the Shortcut 重要な to 貯蔵所d the script to
- Select one of the 重要な Groups (e.g. SHIFT + CONTROL + digits)
- Select a 重要な from the Shortcut 重要なs.
- 割り当てる script to shortcut 重要な:
- Click New Script 重要な to create the new script Shortcut 重要な.
- Select script 機能(する)/行事
- Finally click on the 承認する button to save your new script shortcut 重要な.
- 再開する OpenOffice.org and open a 文書
- 圧力(をかける)ing your new script shortcut 重要な will invoke the Java script.
Last 修正するd: 結婚する Jan 15 16:25:01 GMT 2003