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

翻訳前ページへ


Language

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

How to build a Scripting Runtime?

Contents

How to build a Scripting Runtime?

言及/関連

Introduction

What the Scripting 枠組み 供給するs

What a new Runtime needs to 供給する:

The Runtime

ScriptURI

InvocationCtx

InvocationCtx 所有物/資産/財産 始める,決める

負担ing and running the script

Runtime Invocation

Passing Useful data to the Script

負担ing Scripts

Parameters passed to the Script

Java Runtime

BeanShell Runtime

現在の Runtimes invocation Parameter support

枠組み invocation Parameter support

Input Params

生産(高) Params

Returns

Errors

Runtime Singleton

BeanShell Example

Configuration Changes

一括ing

Creating Scripts

Binding to Scripts

虫垂 I

Scripting 枠組み 決意/決議

Runtime 明確な/細部 決意/決議

虫垂 II

小包 Descriptor DTD and 見本 XML

言及/関連

Developer's Guide:

http://api.openoffice.org/unbranded-source/browse/~checkout~/api/odk/pack/copying/DevelopersGuide.pdf?rev=1.4.2.4

Scripting 枠組み Online API documentation:

http://枠組み.openoffice.org/scripting/EDR-IDLDocs/草案s/com/sun/星/主役にする/script/枠組み

Scripting 枠組み Website:

http://枠組み.openoffice.org/scripting

Introduction

By creating a new Scripting Runtime a developer can 追加する support for the scripting language of their choice to OpenOffice.org. The Scripting 枠組み 供給するs all the 要求するd plumbing needed to 容易にする the (軍隊などの)展開,配備, binding and invocation of scripts for an runtime. The runtime just has to 供給する the language 明確な/細部 死刑執行 環境 for the script and 遂行する/発効させる it. The 枠組み takes care of the 残り/休憩(する).

What the Scripting 枠組み 供給するs

What a new Runtime needs to 供給する:

部類

指名する

Origin

Description

Comment

Interface

com.sun.星/主役にする.lang.XTypeProvider

器具/実施するd by Runtime

Runtime is an UNO 構成要素

要求するd by UNO when creating an UNO 構成要素.

Interface

com.sun.星/主役にする.lang.XServiceInfo

器具/実施するd by Runtime

Runtime is an UNO 構成要素

要求するd by UNO when creating an UNO 構成要素.

Singleton


器具/実施するd by Runtime

Runtime must be a Singleton

Need to 修正する the _writeRegistryServiceInfo() of the XServiceInfo service to 登録(する) the Runtime programatically as a Singleton [言及する to Singleton Support]

Interface

草案s.com.sun.星/主役にする.script.枠組み.runtime.XScriptInvocation

器具/実施するd by Runtime

XScriptInvocation interface supports the invoke() method that is called when invoking scripts for a language.

重要な interface which 許すs the Scripting 枠組み to invoke scripts in a language 独立した・無所属 manner

Invoke()

Method

XscriptInvocation:
Invoke()

器具/実施するd by Runtime

Returns an Any

Invoke method of the XscriptInvocation interface

Runtime 器具/実施するs this method in it's own language. It must 体制/機構 the script runtime 環境, 負担 up the script, pass any 要求するd parameters to it and 遂行する/発効させる the script.

Parameter

Invoke():
scriptURI

供給するd by 報知係 – Used by SF

Is an OUString

初めの script URI passed to the Scripting 枠組み 経由で a call to Xdispatch or Xfunction:

Consists of:
script://<論理(学)の 指名する>
[?[機能(する)/行事=<機能(する)/行事 指名する>]&
[language=[Supported language]]&
[場所=[使用者 | 株 | 文書]]]

(警察などへの)密告,告訴(状) only – Runtime does not need to do anything with it. SF will have already 解決するd the scriptURI to an actual script and 負担d up all the 関連した script (警察などへの)密告,告訴(状) the Runtime needs to invoke the script in the invocationCtx parameter passed to invoke(). The script URI can be used by the Runtime for logging or as a 重要な to (武器などの)隠匿場所 script 関係のある (警察などへの)密告,告訴(状).

Parameter

Invoke():
invocationCtx

供給するd by SF – Used by Runtime

Is a XPropertySet

供給するs Runtime with (警察などへの)密告,告訴(状) on the invocation 状況 of the script as a 始める,決める of 所有物/資産/財産 指名する/value pairs. The 重要な ones are 述べるd below.

重要な InvocationCtx 所有物/資産/財産s

所有物/資産/財産

InvocationCtx:
DOC_REF

供給するd by SF – Used by Runtime

Is a XModel

XModel of the 現在の 文書 against which the script was invoked. Must be passed to the Script by the Runtime so the script can interact with the 現在の 文書.

所有物/資産/財産

InvocationCtx:
SCRIPT_INFO

供給するd by SF – Used by Runtime

Is a XScriptInfo

含む/封じ込めるs all of the (警察などへの)密告,告訴(状) the Runtime needs to 体制/機構 the script runtime 環境 and to 負担 the script to 遂行する/発効させる it.




重要な XscriptInfo methods

Method

XScriptInfo:
getFunctionName()

供給するd by SF – Used by Runtime

Returns OUString

[公式文書,認める: the 機能(する)/行事 指名する is the actual 指名する of the script 機能(する)/行事 to invoke, the 論理(学)の 指名する is the 指名する 陳列する,発揮するd in the 割り当てる dialogs and can be the same as the 機能(する)/行事 指名する or not – use the 機能(する)/行事 指名する when 負担ing a script from it's physical 貯蔵].

供給するs the 機能(する)/行事 指名する of the script you are trying to invoke.

Method

XScriptInfo:
getParcelURI()

供給するd by SF – Used by Runtime

Returns OUString

要求するs some 過程ing before a Runtime can use it to 負担 up the script from the とじ込み/提出する system or a 文書 [ 言及する to 負担ing Scripts below]

供給するs the Path to the script the Runtime needs to invoke.
The form of this Path is an encoded URI which can point to the とじ込み/提出する system for 使用/適用 scripts [とじ込み/提出する:///...] or to a 文書 for 文書 scripts [vnd.sun.星/主役にする.pkg://とじ込み/提出する:...]

Method

XScriptInfo:
getLanguageProperties()

供給するd by SF – Used by Runtime

Returns XpropertySet

For example in the Java and BeanShell Runtimes there is a language 所有物/資産/財産 体制/機構 for the Classpath:
CLASSPATH=<value>

Use this 所有物/資産/財産 始める,決める to 接近 language 明確な/細部 指名する/ value pairs 体制/機構 for the 明確な/細部 language Runtime during script (軍隊などの)展開,配備.
Supported 指名する/value language 所有物/資産/財産s are published by the Runtime Developer.

Invoke Parameters

Input Parameter

Invoke():
inputParams

供給するd by 報知係 - Optional

Is a Sequence of Any

Supported by Java Runtime.

[公式文書,認める: input parameters are not supported from the 割り当てる dialogs, must use the XDispatch or XDunction interfaces 直接/まっすぐに from another script or 構成要素 to 供給する a script with input parameters]

Up to the Runtime to pass the input parameter sequence の上に the script if input parameters are supported.

生産(高) Parameter

Invoke():
outputParamIndex

供給するd by 報知係 - Optional

Is a Sequence of short

Not supported by Java or BeanShell Runtimes.

Up to the Runtime to pass this 生産(高) parameter 索引 (警察などへの)密告,告訴(状) 支援する to the 報知係 from the script.

生産(高) Parameter

Invoke():
outputParams

供給するd by 報知係 - Optional

Is a Sequence of Any

Not supported by Java or BeanShell Runtimes.

Up to the Runtime to pass the 生産(高) parameter sequence 支援する to the 報知係 from the script.

Return

Invoke():
return

供給するd by Script, passed 支援する by Runtime - Optional

Is an Any

A Runtime can ignore all script returns and just return an Any 含む/封じ込めるing a 無効の Type if script returns are of no 利益/興味 to it.

無効の Any:
new Any(new Type(),null);

A script can return whatever it likes to the Runtime, but it is up to the Runtime to 一括 this script return up into a type that is supported by the UNO language 橋(渡しをする) that is 存在 used by the Runtime [must be a 原始の type or an UNO type]
It is this 橋(渡しをする) 両立できる Any that is then returned to the 報知係.





The Runtime

要求するd Interfaces

The Runtime is a normal UNO 構成要素, so it needs to support the に引き続いて interfaces [言及する to the Developer's Guide for 詳細(に述べる)s on creating UNO 構成要素s].

Interface: com.sun.星/主役にする.lang.XTypeProvider

Interface: com.sun.星/主役にする.lang.XServiceInfo

In 新規加入 to the normal 構成要素 interfaces above the Runtime must support the に引き続いて interface to 許す the 枠組み to invoke the scripts in a language 独立した・無所属 fashion:

Interface: 草案s.com.sun.星/主役にする.script.枠組み.XScriptInvocation

This interface supports one method, invoke( ), whose parameters and types are 述べるd below.

Invoke ( )

Returns: Any

Throws: IllegalArgumentException, CannotConvertException,

Parameter Types

Parameters

Description

[in] string

scriptURI

初めの URI passed to the 枠組み

[in] any

invocationCtx

(警察などへの)密告,告訴(状) on where the script was run from

[in] sequence< any >

aParams

Input parameters

[out] sequence< short >

aOutParamIndex

生産(高) parameter 索引

[out] sequence< any >

aOutParam

生産(高) parameters

The に引き続いて sections 述べる the parameters to the invoke ( ) method call and how they can be used by a Runtime to 体制/機構 an 死刑執行 環境 for a script and then 負担 and run the script.

ScriptURI

The scriptURI is the 初めの script URI that was passed during the invoke.


This (警察などへの)密告,告訴(状) should not be 要求するd by a runtime as the 枠組み will have already 解決するd the script to a 明確な/細部 script and 負担d up the 詳細(に述べる)d script (警察などへの)密告,告訴(状) by the time the Runtime's invoke method is called [ 言及する to 虫垂 I for 詳細(に述べる)s on the 枠組み's 現在の 決意/決議 戦略].

If a runtime needs to parse the script URI, to 成し遂げる it's own 過程ing the scriptURI is 供給するd to 許す it to do so. The syntax of the script URI is:


script://<logical_name>['?'<query_element>('&'<query_element>)*]]

where : query_element = <word>'='<指名する>

Script URI Parameter

Description

logical_name

論理(学)の 指名する of the script – this is the 指名する 陳列する,発揮するd to the 使用者 in the 割り当てる dialogs. It 許すs the script writer to 明示する a more 使用者 friendly 指名する for the script, rather than 陳列する,発揮するing the actual 機能(する)/行事 指名する to the 使用者.
The script writer does not have to 明示する a different 論理(学)の 指名する to the 機能(する)/行事 指名する, they can both be the same.
[公式文書,認める: the use of a 論理(学)の 指名する also enables 決意/決議 at invocation, which is not 現在/一般に exposed in the 割り当てる dialogs. All scripts bound in the 割り当てる dialogs are fully 明示するd with logical_name, 機能(する)/行事 指名する, language and 場所 – 言及する to Scripting 枠組み 決意/決議]

language

Language the script is written in, must be a supported runtime.

現在/一般に supported languages: Java and BeanShell

機能(する)/行事

Actual language 明確な/細部 機能(する)/行事 指名する.

場所

場所 where script is 蓄える/店d – 使用/適用 area [使用者 or 株] or 文書.
Permitted 指名するs: 使用者, 株 or 文書


Example of Script URI:

script://道具s.変える.ToEuro?

language=Java&

機能(する)/行事=com.sun.星/主役にする.beans.道具s.基準.変える.toEuro&

場所=使用者
Maybe better above/below if we use an example from the 枠組み 取り付け・設備.

In the 割り当てる dialogs the 使用者 will see the 道具s.変える.ToEuro script 指名する in the 名簿(に載せる)/表(にあげる) of 利用できる scripts when Java is the selected language and 使用者 the selected 場所. Selecting this script will 割り当てる the above script URI to the menu, 重要な or event binding as appropriate for the 割り当てる dialog invoked. It will be 蓄える/店d in the matching configuration とじ込み/提出する for later retrieval when the binding is invoked.


InvocationCtx

The invocationCtx is an 実施 of XPropertySet 体制/機構 by the 枠組み to give a Runtime 接近 both to the 状況 from which the script was invoked (the 現在の 文書) and the 詳細(に述べる)d (警察などへの)密告,告訴(状) on the script itself which a Runtime will need to 負担 and run the script (SCRIPT_INFO).

InvocationCtx 所有物/資産/財産 始める,決める

所有物/資産/財産 重要な

Type

Description

DOC_REF

XModel

The XModel of the 現在の 文書

DOC_URI

OUString

The 文書 URI of the 現在の 文書

SCRIPT_INFO

XScriptInfo

XScriptInfo for the 解決するd script, 含む/封じ込めるing all of the data in the scripts 小包-descriptor.xml and the physical path of the script directory.

DOC_STORAGE_ID

sal_Int32

Used by the 枠組み - The 内部の 貯蔵 id of the script 貯蔵 created for this 文書

RESOLVED_STORAGE_ID

sal_Int32

Used by the 枠組み - The 解決するd script 貯蔵 for this script, will be the same as the DOC_STORAGE_ID if the script is in the 文書, さもなければ it will point to the 使用者 or 株 貯蔵 areas.


Accesing 所有物/資産/財産s from the invocationCtx 所有物/資産/財産 始める,決める [examples in Java]:


First get the 所有物/資産/財産 始める,決める from the invocationCtx:

XPropertySet invocationCtxPropSet =

( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, invocationCtx );


Then get the 要求するd 所有物/資産/財産 [use one of the 所有物/資産/財産 重要なs above]:

反対する propObject = invocationCtxPropSet.getPropertyValue( <所有物/資産/財産 重要な> );


Query the returned 反対する for the 要求するd 反対する type:

typedPropObject = ( <所有物/資産/財産 Type> ) UnoRuntime.queryInterface( <所有物/資産/財産 Type>.class,

propObject );


For example to 接近 the SCRIPT_INFO 所有物/資産/財産:

反対する propObject = invocationCtxPropSet.getPropertyValue( “SCRIPT_INFO” );

scriptInfoPropObject = ( XScriptInfo ) UnoRuntime.queryInterface( XScriptInfo.class, propObject );


負担ing and running the script

The 枠組み will 解決する the script URI to a 明確な/細部 script and 負担 up the script (警察などへの)密告,告訴(状) into a XScriptInfo 反対する. This is then 始める,決める as a 所有物/資産/財産 of the invocationCtx which is passed の上に the Runtime in the Runtime's invoke ( ) method call.

This 含む/封じ込めるs the 重要な (警察などへの)密告,告訴(状) 要求するd by the Runtime to 遂行する/発効させる the script, it gives the Runtime 接近 to all of the (警察などへの)密告,告訴(状) about this 明確な/細部 script, 含むing physical 場所 and any language 明確な/細部 (警察などへの)密告,告訴(状) that the Runtime 要求するs to run the script, such as Classpath in the 事例/患者 of the Java and BeanShell runtimes.

The Runtime can 接近 the SCRIPT_INFO 所有物/資産/財産 of the invocationCtx as 述べるd above. Once it has the XScriptInfo it can use methods to get all the (警察などへの)密告,告訴(状) it needs to 負担 and run the script.

得る the XScriptInfo as 述べるd above and use the に引き続いて XScriptInfo interface methods to 接近 the 要求するd data:

XscriptInfo Method

Return

Description

getLogicalName()

OUString

論理(学)の 指名する – 陳列する,発揮するd in the 割り当てる dialogs

getDescription()

OUString

Description of the script, 供給するd during (軍隊などの)展開,配備 of the script – not 現在/一般に 陳列する,発揮するd in the 割り当てる dialogs.

getLanguage()

OUString

Language script is written in.

getFunctionName()

OUString

機能(する)/行事 指名する of the script [only 陳列する,発揮するd in the 割り当てる dialogs if t the 詳細(に述べる)s checkbox is selected].

getParcelURI()

OUString

Path to the script 小包 – needed to 負担 in the script source to the runtime.

Scripts 蓄える/店d in the 使用/適用 are とじ込み/提出する based URI's [とじ込み/提出する://]. 文書 scripts have their own 議定書 [vnd.sun.星/主役にする.pkg]
Special 扱うing of the parcelURI is 要求するd before the Runtime can 負担 scripts [言及する to 負担ing Scripts below]

getLanguageProperties()

XPropertySet

Language 明確な/細部 所有物/資産/財産s of the Script:

接近 指名する value pairs of this 所有物/資産/財産 始める,決める using the appropriate 所有物/資産/財産 重要なs for the script language [明示するd by the Runtime developer and 体制/機構 during (軍隊などの)展開,配備 of a script].

For Java and BeanShell classpath is the only 利用できる 所有物/資産/財産 重要な.

getFileSetNames()

Sequence of OUString

Get a sequence of とじ込み/提出する 始める,決める 指名するs from the script 小包. The とじ込み/提出する 始める,決める 許すs the script developer to group a 始める,決める of 関係のある とじ込み/提出するs together which either the Runtime or the script can use. For instance this may be useful in 明示するing a 始める,決める of 関係のある 資源s for a script.

現在/一般に these methods are not used by the Java or BeanShell runtimes [関係のある とじ込み/提出するs/ 資源s are 一般に in jar とじ込み/提出するs that can be 明示するd on the language 所有物/資産/財産 - Classpath]

getFilesInFileSet( const ::rtl::OUString & fileSetName )

Sequence of OUString

Get a 名簿(に載せる)/表(にあげる) of the とじ込み/提出するs for the given fileset.




Typically the (警察などへの)密告,告訴(状) in the invocationCtx and ScriptInfo (警察などへの)密告,告訴(状) is used as follows by a Runtime [公式文書,認める: though 明確な/細部 to the Java and BeanShell Runtimes, the general 論理(学)の flow will be the same for most Runtimes]

Runtime Invocation



Passing Useful data to the Script

It is up to the Runtime to decide what (警察などへの)密告,告訴(状) to pass to a running script. It makes sense to pass (警察などへの)密告,告訴(状) to the script which makes the script writer's 職業 easier, such as a 言及/関連 to the 現在の 文書 (利用できる from the invocationCtx), 言及/関連 to the service 経営者/支配人 (利用できる from the 構成要素 状況 passed into the Runtime 構成要素's 建設者 by UNO) and a 言及/関連 to the desktop (利用できる from UNO using this service 経営者/支配人).

In both the Java Runtime and the BeanShell runtime this 状況 (警察などへの)密告,告訴(状) is made 利用できる to the running script in the form of a XScriptContext. This 供給するs accessor methods to get the 現在の 文書, the 現在の desktop and the 構成要素 状況. In the Java Runtime it's passed as the first parameter to the script and in the Beanshell Runtime it's 体制/機構 in the runtime 環境 variable, “状況”.


Interface: 草案s.com.sun.星/主役にする.script.枠組み.runtime.XScriptContext


XscriptContext Method

Returns

Description

getDocument

XModel

接近 to the 現在の 文書.

getDesktop

XDesktop

接近 to the 現在の desktop.

getComponentContext

XComponentContext

Can be used by the script to get the default multi 構成要素 factory to create other UNO services.



負担ing Scripts

Scripts can be 負担d from the 使用者 or 株 使用/適用 directories or from a 文書. The parcelURI which 供給するs the path to the script to 負担 is in the form of an encoded URI. When the Runtime is using the parcelURI to 負担 a script the Runtime needs to take account of this fact and 過程 the parcelURI 適切な before it it is used.

If you use the UNO UCB API, such as the XSimpleFileAccess, then you do not need to alter the encoded URI at all. If you want to use it to 負担 the script just append a 今後 削除する before appending the appropriate script filename and pass it to the appropriate XSimpleFileAccess methods.

The Java and BeanShell Runtimes use XSimpleFileAccess [openFileRead(), getSize()] and XInputStream [readBytes() and closeInput()] to read in the script and 体制/機構 a byte array input stream to the 文書 script. This in turn is used to create a custom stream handler that can then be used with both the ClassLoader and URL classes, to 許す the Runtimes to 負担 up classes and scripts from the 文書. Any Java based Runtime can use the helper classes in UCBStreamHandler.java and PathUtils.java.


The parcelURI is in an encoded URL 判型.. The specification for URLs, RFC 1738 : http://www.rfc-editor.org/rfc/rfc1738.txt, 限界s the use of 許すd characters in URLs to a subset of the US-ASCII character 始める,決める. For a URL to be a 井戸/弁護士席 formed URL conformant with the URL specification it must encode any characters in the URL which 落ちる outside this 限られた/立憲的な 始める,決める. URL encoding of a character consists of a "%" symbol, followed by the two-digit hexadecimal 代表 (事例/患者-insensitive) of the ISO-Latin code point for the character. Characters which need to be encoded 含む; ASCII 支配(する)/統制する characters, 非,不,無 ASCII characters, reserved characters [明確な/細部 to URL syntax 含むing Backslash (%5C) ] and 危険な characters [optional but may 原因(となる) problems in a URL, 含むing Space (%20) and 今後 削除する (%2F)].

The に引き続いて (米)棚上げする/(英)提議する 輪郭(を描く)s what is passed to the Runtime for a given 使用/適用 or 文書 script. It shows the type of 過程ing that needs to be carried out before using the parcelURI to create a 十分な path to 接近 the 使用/適用 script from the とじ込み/提出する system or the 文書 script from the 文書 [The example uses the BeanShell Runtime, but the 主要な/長/主犯's are the same for any Runtime].

ParcelURI: 使用/適用 Script

ScriptURI – 過程d by the SF

script://MemoryUsage.BeanShell?language=BeanShell&機能(する)/行事=memusage.bsh&場所=使用者

ParcelURI – passed into the Runtime

Unix: とじ込み/提出する:///apps%20and%20utilities/staroffice/使用者/Scripts/java/MemoryUsage

Windows: とじ込み/提出する:///C:/apps%20and%20utilities/staroffice/使用者/Scripts/java/MemoryUsageThe ParcelURI is passed into the Runtime in the invocationCtx's SCRIPT_INFO 所有物/資産/財産 始める,決める and 接近d using the XScriptInfo getParcelURI() method.

十分な path of Script to 負担 – using UCB XSimpleFileAccess

Unix: とじ込み/提出する:///apps%20and%20utilities/staroffice/使用者/Scripts/java/MemoryUsage/memusage.bsh

Windows: とじ込み/提出する:///C:/apps%20and%20utilities/staroffice/使用者/Scripts/java/MemoryUsage/memusage.bsh

< ParcelURI>/< 機能(する)/行事 指名する>

建設するd by the Runtime from the 過程d ParcelURI and the 機能(する)/行事 指名する [公式文書,認める: the 機能(する)/行事 指名する is passed into Runtime in the invocationCtx's SCRIPT_INFO 所有物/資産/財産 始める,決める and 接近d using the XScriptInfo getFunctionName() method.]


ParcelURI: 文書 Script

ScriptURI

script://MemoryUsage.BeanShell?language=BeanShell&機能(する)/行事=memusage.bsh&場所=文書

ParcelURI – passed into the Runtime

Unix: vnd.sun.星/主役にする.pkg://とじ込み/提出する:%2F%2F%2Fscriptdev%2Fjohnr%2Fstaroffice644m5%2F使用者%2FScripts%2Fjava%2FMemoryUsage%2FExampleSpreadSheet.sxc/Scripts/java/MemoryUsage

Windows: vnd.sun.星/主役にする.pkg://とじ込み/提出する:%2F%2F%2FC:%2Fscriptdev%2Fjohnr%2Fstaroffice644m5%2F
使用者%2FScripts%2Fjava%2FMemoryUsage%2FExampleSpreadSheet.sxc/Scripts/java/MemoryUsage


文書 URI 議定書 is vnd.sun.星/主役にする.pkg The Runtime should check for this string to see if it should be 扱うd as an embedded 文書 script.

The path to the 文書 script consists of:
<文書 議定書>:<とじ込み/提出する 議定書>/<encoded 文書 path>/<親族 script path>

公式文書,認める: only Unix/ Windows difference is in the encoded 文書 path, which is not 関連した to the 過程ing carried out below to create the UCB Script Path.

十分な UCB path of Script to 負担 – created by the Runtime

vnd.sun.星/主役にする.pkg://とじ込み/提出する:%2F%2F%2Fscriptdev%2Fjohnr%2Fstaroffice644m5%2F使用者%2FScripts%2Fjava%2FMemoryUsage%2FExampleSpreadSheet.sxc/Scripts/java/MemoryUsage/memusage.bsh

<過程d ParcelURI>/< 機能(する)/行事 指名する>
Can now be used by the Runtime to 負担 the script from the 文書 using the UNO XSimpleFileAccess.



Parameters passed to the Script

Java Runtime

To run a Java script in OpenOffice.org, you must create a public Java class with at least one public Java method that takes an XScriptContext as it's first parameter. If no such method 存在するs the Runtime will throw an exception.

BeanShell Runtime

BeanShell scripts are 選び出す/独身 .bsh とじ込み/提出するs, there are no parameter 必要物/必要条件s when running BeanShell scripts. The Runtime does make the XScriptContext 利用できる in the BeanShell 環境, but the script can use or ignore it as it sees fit.

現在の Runtimes invocation Parameter support

Runtime

Input Parameters

生産(高) Parameters

Return

Java

Supported

Ignored

Supported

BeanShell

Ignored

Ignored

Supported



枠組み invocation Parameter support

The 枠組み scripts can be invoked either 直接/まっすぐに using a call to XFunction, 得るd from a 都合よく 建設するd XFunctionProvider or 間接に using one of the XFispatch methods.

Interface: com::sun::星/主役にする::でっちあげる,人を罪に陥れる::XDispatch

Interface: 草案s::com::sun::星/主役にする::script::枠組み::provider::XFunctionProvider

The appropriate 派遣(する) handler will be invoked for the 枠組み, based on the 議定書 of the scriptURI passed in [The Script 枠組み 議定書 handler, com.sun.星/主役にする.comp.ScriptProtocolHandler, is 登録(する)d in the ProtocolHandler.xcu configuration とじ込み/提出する when the 枠組み is 任命する/導入するd and 扱うs URI's for the “script://” 議定書].

Interface / Method

Input Parameters

生産(高) Parameters

Return

XDispatch:

派遣(する)( )

Supported

Ignored

Ignored

XDispatch: dispatchWithNotification( )

Supported

Ignored

Supported 経由で XDispatchResultListener

XFunction:

invoke( )

Supported

Supported

Supported



Input Params

If a script is invoked from a menu, 重要な or event binding 体制/機構 using the 割り当てる dialogs, there is no way to pass an input parameter to the script . However, it is possible to pass input parameters to a script if you invoke it from another script using either the XDispatch [asynchronous] or XFunction [synchronous] interfaces as shown below:

Example using XFunction to Invoke a Script. with several input parameters

Sub DisplayEuroConversionRates ( conversionRatesRile as String, numConversions as integer)

薄暗い args(0)

args(0) = ThisComponent



' Create your FunctionProvider and 得る a Script 機能(する)/行事 from it.

FuncProvider = createUnoService(“草案s.com.sun.星/主役にする.script.枠組み.provider.FunctionProvider”)

FuncProvider.initialize( args() )

Func = FuncProvider.getFunction( “script://道具s.変える.DisplayEuroRates?_

language=Java&機能(する)/行事=com.sun.星/主役にする.beans.道具s.基準.変える.displayEuro&場所=使用者”)



薄暗い inArgs(1)

薄暗い outArgs()

薄暗い outIndex()



' 体制/機構 Input Param arguments

inArgs(0) = conversionRatesFile

inArgs(1) = numConversions



result = Func.invoke( inArgs(), outIndex(), outArgs() ) // Out params not 扱うd by Java or BeanShell

End Sub





Example using XDispatch to Invoke a Script with several input parameters



sub DisplayEuroConversionRates( conversionRatesFile as String, numConversions as integer)

薄暗い url as new com.sun.星/主役にする.util.URL

文書 = ThisComponent.CurrentController.でっちあげる,人を罪に陥れる

parser = createUnoService(“com.sun.星/主役にする.util.URLTransformer”)

薄暗い args1(1) as new com.sun.星/主役にする.beans.PropertyValue



' 体制/機構 Input Param arguments

' 公式文書,認める: args1(x).指名する can be left blank

' 始める,決める argsl(x).指名する to “Referrer” if you do not want it 追加するd as an input param

args1(0).Value = conversionRatesFile

args1(1).Value = numConversions



url.完全にする = “script://道具s.変える.DisplayEuroRates?_

language=Java&機能(する)/行事=com.sun.星/主役にする.beans.道具s.基準.変える.displayEuro&場所=使用者”

parser.parseStrict(url)

disp = 文書.queryDispatch(url,“”,0)



disp.派遣(する)(url, args1()) 'No 接近 to Out params

End Sub



生産(高) Params

Are 現在/一般に not supported in the Java and BeanShell Runtimes. If you do 器具/実施する them in your Runtime, the XDispatch script 議定書 handler has no way to 過程 them [supports one way call only]. You would only be able to 過程 them if you use the XFunction interface above in the calling script.

Returns

The script runtime can return the result of the script in an Any if it makes sense to do so. The return result must be a type that is supported by the UNO language 橋(渡しをする) 存在 used by the Runtime [一般に a 原始の type or an UNO type]. If an unsupported type is passed 支援する by the script the UNO 橋(渡しをする) will 原因(となる) an 主張する. Both the Java and BeanShell runtimes pass 支援する the return value of scripts they invoke, it is the 責任/義務 of the script writers to return types supported by the UNO 橋(渡しをする) [言及する to the Developer's Guide].

If there is no return value or the Runtime chooses not to support return values from scripts, it must always return a 無効の Any [created as follows in Java: new Any(new Type(), null);]

Errors

If any problems arise in the Runtime the に引き続いて exceptions can be thrown by the invoke call. The Runtime should make sure the errors raised match the meaning of the the exceptions given below.

Exception

Description

IllegalArgumentException

If there is no matching script 指名する.

CannotConvertException

If arguments do not match or cannot be 変えるd the those of the invokee

InvocationTargetException

If the running script throws an exception, this (警察などへの)密告,告訴(状) is 逮捕(する)d and re thrown as this exception type.



Runtime Singleton

The Runtime must be 体制/機構 as a Singleton. The 指名する of the singleton must follow the に引き続いて 計画/陰謀:

theScriptRuntimeFor<Runtime Language>

For example for Java the singleton is 指名するd theScriptRuntimeForJava and for BeanShell it is 指名するd theScriptRuntimeForBeanShell.

This needs to be done programmatically in the _writeRegistryServiceInfo( ) method of the XServiceInfo service. In this method you need to create the appropriate singleton registry 重要な under the UNO/Singletons 重要な in the Office 登録 database in the [言及する to example below for BeanShell].

[公式文書,認める: this is an undocumented feature of 643 builds and above and is not covered in the Developer's Guide].

Singleton Registry 入ること/参加(者):

[実施 指名する]+ "/UNO/SINGLETONS/” + [Service Module] + “.theScriptRuntimeFor<Runtime Language>”

BeanShell Example

public static boolean __writeRegistryServiceInfo( XRegistryKey regKey ) {

String impl = "com.sun.星/主役にする.scripting.runtime.beanshell.ScriptRuntimeForBeanShell$_ScriptRuntimeForBeanShell";

String serviceModule = "草案s.com.sun.星/主役にする.script.枠組み";

String service = serviceModule + ".ScriptRuntimeForBeanShell";



if (FactoryHelper.writeRegistryServiceInfo(impl, service, regKey)) {

try {

XRegistryKey newKey = regKey.createKey(

impl + "/UNO/SINGLETONS/”+ serviceModule + “.theScriptRuntimeForBeanShell");

newKey.setStringValue(service);

return true;

} catch (Exception ex) {

System.err.println("Error 登録(する)ing ScriptRuntimeForBeanShell: " + ex);

}

}

return 誤った;

}

Configuration Changes

As of 解放(する) 0.3, runtime developers also need to make a change to the OpenOffice registry. The とじ込み/提出する <Officeinstall>/株/registry/schema/org/openoffice/Office/Scripting.xcs defines the schema used to 決定する the 関係 between a runtime, eg. BeanShell, and the とじ込み/提出する 拡張s supported by that runtime, eg. .bsh. Thus developes need to bundle a Scripting.xcu とじ込み/提出する along with their UNO 一括 (see に引き続いて section). The とじ込み/提出する used for the BeanShell runtime which follows could be used as a template:
<?xml 見解/翻訳/版="1.0" encoding="UTF-8"?>
<oor:node xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:指名する="Scripting" oor:一括="org.openoffice.Office">
    <node oor:指名する="ScriptRuntimes">
        <node oor:指名する="BeanShell" oor:op="取って代わる">
            <支え(る) oor:指名する="SupportedFileExtensions">
                <value xml:lang="en-US">bsh</value>
            </支え(る)>
        </node>
    </node>
</oor:node>

一括ing

The new Runtime must be 一括d as an UNO 構成要素. 言及する to the Developer's Guide on 指示/教授/教育s on how to use the pkgchk 道具 to 一括 the Runtime and any 付加 資源s it may 要求する.

Creating Scripts

If you want to 許す your 使用者s to create script 小包s for the new language Runtime, you can create a 道具 to create a script 小包, or you can use the 存在するing 命令(する) line 道具s to do so.

The script 小包 is just a zip とじ込み/提出する 含む/封じ込めるing the script and any associated 資源s and a 小包-descriptor.xml とじ込み/提出する, which gives the 詳細(に述べる)s of the script, 含むing language 明確な/細部 (警察などへの)密告,告訴(状) that may be needed to run the script.

You could 令状 your own 道具s to create the 小包-descriptor.xml とじ込み/提出する. 言及する to 虫垂 I for the 小包-descriptor.xml DTD.

Binding to Scripts

If a Runtime has been 任命する/導入するd the 割り当てる dialogs will automatically (悪事,秘密などを)発見する the new language Scripting Runtime singleton. The language will then be 利用できる as a choice in the language 減少(する) 負かす/撃墜する combo of all of the 割り当てる dialogs. Choosing it the 使用者 will be 現在のd with a 名簿(に載せる)/表(にあげる) of any scripts for this language, (軍隊を)展開する,配備するd into the 明示するd 場所 [取り付け・設備 – 使用者/ 株; 文書].

The Runtime developer has nothing to do other than make sure the Runtime is 登録(する)d as a singleton using the above 指名するing 計画/陰謀.





虫垂 I

Scripting 枠組み 決意/決議

If a Script URI has all of the 重要な fields filled out [論理(学)の 指名する, language, 機能(する)/行事 and 場所] then the Script URI will be unambiguously matched to only one 肉体的に (軍隊を)展開する,配備するd script. If no match is 設立する then a Runtime exception is raised by the 枠組み.


What happens if you omit some or all of the optional fields? The 枠組み will 試みる/企てる to 解決する the Script URI to one of the (軍隊を)展開する,配備するd scripts as follows.


Omitted Script URI Parameter

決意/決議 戦略

機能(する)/行事

Will search for the first match from the 名簿(に載せる)/表(にあげる) of all 利用できる 機能(する)/行事 実施s for a given 論理(学)の 指名する by alphabetical order of the 機能(する)/行事s.

場所

Will search for the first matching script from all the 利用できる 貯蔵 場所s in the order of 文書, 使用者 and 株.

language

Will search for the first match in the 利用できる supported language Runtimes by alphabetical order of the Runtimes.


In the 未来 it may be possible to configure the 枠組み's 決意/決議 戦略s if the Script URI is not fully qualified.

Runtime 明確な/細部 決意/決議

In some Runtime's it may be necessary to do その上の 決意/決議 checks, based not just on the 機能(する)/行事 指名する, but also on the Parameter 名簿(に載せる)/表(にあげる) passed 負かす/撃墜する to the script.
For instance, the Java Runtime will check that the script which the 枠組み has 解決するd also matches a method with the appropriate 署名 on the 利用できる Classpath for this script and if it does not will throw an exception.





虫垂 II

小包 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>
</小包>



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.