このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


令状ing Scripts in BeanShell and Java
Language

The 解放する/自由な and Open 生産性 控訴
解放(する)d: Apache OpenOffice 4.1.15

令状ing Scripts in BeanShell and Java

Contents

Hello World in BeanShell

Here's a BeanShell script that 挿入するs Hello World at the start of an OpenOffice.org Writer 文書:

    輸入する com.sun.星/主役にする.でっちあげる,人を罪に陥れる.XModel;
    輸入する com.sun.星/主役にする.text.*;
    輸入する com.sun.星/主役にする.uno.UnoRuntime;
    輸入する 草案s.com.sun.星/主役にする.script.枠組み.XScriptContext;

    model = 状況.getDocument(); 
    textdoc = (XTextDocument)
        UnoRuntime.queryInterface(XTextDocument.class, model);

    oText = textdoc.getText(); 
    oCursor = oText.createTextCursor(); 
    oText.insertString(oCursor, "Hello World", 誤った)
最高の,を越す

Trying out your BeanShell script

Trying out your Hello World BeanShell script is 平易な:

You can 修正する the code 直接/まっすぐに in the evaluation window and click eval again to 実験(する) it. If you are new to the OpenOffice.org API this is a 広大な/多数の/重要な way to 実験 with it.

公式文書,認める: The Interactive BeanShell window does not 報告(する)/憶測 when an error occurs while 評価するing your code, so it may fail silently. The best way to trace the 死刑執行 of your code is to 令状 debug 声明s into your 文書 from your script, for example:

model = 状況.getDocument();
textdoc = (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, model);
oText = textdoc.getText();
oCursor = oText.createTextCursor();

oText.insertString(oCursor, "DEBUG: start", 誤った);

// do something with the API

oText.insertString(oCursor, "DEBUG: did something", 誤った);

When you are happy with your BeanShell script, you can create a Script 小包 which can be (軍隊を)展開する,配備するd to OpenOffice.org 取り付け・設備s or 文書s for use by others. This can be done using NetBeans or from the 命令(する) line.

最高の,を越す

Hello World in Java

Here's the Hello World script in Java:

    輸入する 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", 誤った);
        }
    }

Office scripts in Java need to be 収集するd ーするために 遂行する/発効させる them. See the Developing Scripts in NetBeans and Developing Scripts on the 命令(する) line guides for 指示/教授/教育s on how to 収集する and (軍隊を)展開する,配備する Office scripts in Java.

最高の,を越す

令状ing Office scripts and the XScriptContext type

The XScriptContext type is used to 得る the the 文書 状況, desktop and 構成要素 factory from an Office script. Any public Java method which 受託するs XScriptContext as it's first parameter can be 遂行する/発効させるd as an Office script. For BeanShell scripts, an instance of XScriptContext is 利用できる in a 全世界の variable called "状況" which can be used by the script.

The に引き続いて accessor methods are 利用できる on the XScriptContext type:

The Java or BeanShell script must 輸入する the XScriptContext interface, using the に引き続いて 輸入する 指示的な:
    輸入する 草案s.com.sun.星/主役にする.script.枠組み.XScriptContext;

最高の,を越す

Tips on 令状ing Office scripts

最高の,を越す

小包 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
>
<!ATTLIST 小包
	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">
<小包 language="Java">
	<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>
</小包>
最高の,を越す
Last 修正するd: Tue 損なう 12 11:40:28 GMT 2003

Apache Software Foundation

Copyright & License | Privacy | 接触する Us | 寄付する | Thanks

Apache, OpenOffice, OpenOffice.org and the seagull logo are 登録(する)d trademarks of The Apache ソフトウェア 創立/基礎. The Apache feather logo is a trademark of The Apache ソフトウェア 創立/基礎. Other 指名するs appearing on the 場所/位置 may be trademarks of their 各々の owners.