Developing Scripts on the Command Line
For users who do not wish to develop their OpenOffice.org scripts using an IDE there is a simple command line interface built into the OpenOffice.org Scripting module which can be used for the generation and deployment of OpenOffice.org Scripts.Contents
Prerequisites
- The Scripting module office.jar file should be included in the classpath. You can download this file from here
- The main Scripting Framework jar file ScriptFramework.jar also needs to be included in the classpath. You can find it in the program/classes directory of your OpenOffice.org installation.
- The CommandLineTools class will only work if an XML parser (such as Apache Xerces) is available in the classpath.
The CommandLineTools class
The CommandLineTools class takes the following options (Note: Options in angle brackets "<>" are required, options in square brackets "[]" are optional):[-o Path to OpenOffice.org Installation] -g [Path to Parcel directory] [options]
- If a parcel directory is not specified the current directory is used. If the parcel directory does not contain a directory named Contents an error message is printed. Otherwise a Script Parcel (.sxp) file is generated in the parcel directory containing all of the files under the Contents directory. The options that may be used with the -g option allow the user to specify how the parcel-descriptor.xml file for the Script Parcel is generated (see the Scripting Framework developer guide for more information on the parcel-descriptor.xml file). The following options are available:
[-l language[=supported extension list]]
Specifies which language attribute to use for the parcel element in the parcel-descriptor.xml file. The supported extension list is ignored if the language is Java. Otherwise all files that have one of the supported extensions (the list should be separated by the platform specific path separator, ":" on Unix, ";" on Windows) will be added as script entries to the parcel-descriptor.xml file.
Alternatively the user can specify a list of names at the command line which will be added as scripts and no search for script names will be performed. The following table shows the behaviour of CommandLineTools when the -l flag is used:
-l flag used? parcel-descriptor.xml exists? result no no error message printed yes no parcel-descriptor.xml generated
parcel.sxp generatedno yes parcel-descriptor.xml not generated
parcel.sxp generatedyes yes if
language is different from parcel-descriptor.xml language, error
else
parcel-descriptor.xml regenerated
parcel.sxp generated[-p name=value]
Specifies a name value pair to be added as a language dependent property in the parcel-descriptor.xml file
[-v]
Specifies that verbose output should be displayed.
[-o Path to OpenOffice.org Installation] -d <Path to Script Parcel> <Target Directory|Document>
Deploys the given Script Parcel to a directory or an OpenOffice.org document. The optional -o flag is used to specify that path to your OpenOffice.org installation. If it is not provided the CommandLineTools class will attempt to discover your OpenOffice.org installation and will print an error if it fails. A directory will be created with the name of the Parcel and the contents of the Parcel will be put into that directory.
- If deploying to an OpenOffice.org installation the target directory should be the <OpenOffice.org Installation>/user/Scripts or <OpenOffice.org Installation>/share/Scripts directory. If the either the Script Parcel or the target do not exist an error message is printed. Otherwise the Script Parcel is deployed to the target.
Examples
- java CommandLineTools -g -l BeanShell=.bsh
- java CommandLineTools -g myparceldir -l BeanShell MyScript.bsh
- java CommandLineTools -g myparceldir -l Java -p classpath=dep1.jar:dep2.jar
- java CommandLineTools -g myparceldir -l Java -p classpath=dep1.jar:dep2.jar -p secondprop=secondvalue
- java
CommandLineTools -d myparceldir.sxp /export/home/MyOffice/user/Scripts
Deploys the myparceldir.sxp Script Parcel to the specified office directory.
- java
CommandLineTools -g myparceldir -l JavaScript MyScript.js
Generates a myparceldir.sxp file in myparceldir and exports MyScript.js as an OpenOffice.org script.
Last Modified: Nov 19 2003