Extending Tango FunctionalityScript and External ActionsThe Script action provides an interface within Tango for executing JavaScript code at the server. The script executed can return to Tango a value you can access using Results HTML. The External action sends a specified Apple Event with parameters to a specified application and retrieves the results or invokes a Java class file and returns results. On Windows and Unix platforms, the External action calls an executable invoked using a command line, a Dynamic Link Library (DLL), or Java class file, and, if desired, returns results. Tango may also be extended through JavaBean and Tango class file objects. For more information, see "Tango and Objects". This chapter covers the following topics:
Executing JavaScriptThe Script action provides an interface for executing core JavaScript code at the server. The script executed can return a value to Tango, which is accessible using Results HTML. Tango is JavaScript 1.4 compatible, meaning it includes the official JavaScript Reference implementation from Netscape, and conforms to version 1.4 of the language.
Setting Up a Script ActionWhen you drag the Script action icon from the Actions palette into an application file, the Script action editing window appears. The JavaScript object and variable scope parameter defines the lifetime of the objects and functions declared in the script. This is a concept similar to the scope of variables in Tango. |
|
The pop-up menu/text box has several choices, or you can enter a custom scope:
|
|
For information on using the script text area, see "HTML Editing Window", and "The SQL Query Window". |
You enter the text script to be executed in the JavaScript script text area. The script may contain meta tags. All meta tags in the script are substituted before the script is executed.
The script text area functions the same as HTML text editing windows. Executing a Script ActionTango Server executes the Script action in a similar way it executes the <@SCRIPT> meta tag. |
For more information, see "<@SCRIPT>" in the Meta Tags and Configuration Variables manual. |
Any value returned by a script is accessible in the Results HTML by using <@COL 1> inside a <@ROWS> block. The action's result set (a 1 by 1 array) is also stored automatically in a local variable, resultSet. Using an External ActionSetting Up an External ActionWhen you drag the External action icon from the Actions palette into a file, the External action editing window automatically opens. The default External action type is based on the current platform, in this case, Apple Event. You can also specify Java, command line execution, or DLL. From the Type pop-up menu, select the type of action you want to execute.
This User's Guide gives a description of each type of External action. Only an Apple Event or Java action can be used with the Mac OS version of Tango Server. The DLL and Command Line externals are available if you plan to deploy your application file on another Tango Server platform, such as Windows or UNIX. Configuring an Apple EventTo use External actions, you should be familiar with Apple Events and know the event and parameter codes of applications with which you want to communicate. You can also use Apple Event actions to communicate with applications you write in AppleScript. To configure an Apple Event external action
A blank row appears in the Parameters area. The parameter values can be entered as fixed values, or you can use any Tango meta tags that return values. Calling AppleScript ApplicationsTango can send only text parameters and accepts only a string (or value that can be converted to a string), list of strings, or list of lists of strings as return values. If you need to communicate with applications requiring non-string parameters or that return results in a format Tango cannot handle, you should use an intermediate AppleScript application to coerce the non-string types to strings. |
For more information on Apple Events and AppleScripts, consult your Macintosh documentation. |
AppleScript application handlers that are to be called from Tango require special subroutine names and parameter labels. Here is an example: on «event TNGOTest» dir_param given
«class arg1»:arg_1, «class arg2»:arg_2 return {col_one, col_two, col_three} The chevrons (« and ») in the handler name and argument specifications are entered using option-\ and option-shift-\ key combinations. The first four letters of the AppleScript handler name (after the event keyword) make up the Event Class Code; the second four are the Event Code. In this example, the event class is TNGO and the event is Test. Except for the direct parameter, which immediately follows the handler name, the parameters must be labeled with the class keyword and a unique four letter code. In this example there are three parameters: the direct parameter, "arg1", and "arg2". As with any other applications Tango communicates with through Apple Events, results from an AppleScript application must be returned as a string, list of strings, or list of lists of strings. Here is an example of each: Configuring a DLL CallTo configure a DLL call
Using a Command LineExternal actions allow you to run any executable file (for example, batch file, shell or Perl script, C application) and, if desired, retrieve results. Values are passed from Tango to the executable by means of environment variables. Results are retrieved by Tango from text that the external action has written to the standard output stream (stdout). Rows and columns are delimited with tabs and returns, respectively. To configure a command line External action
|
Environment variables may include any value-returning Tango meta tags, which are substituted when the action is executed.
Configuring a Java ActionTango ships with its own Java server. The Java server is on the same machine as Tango Server. The Java type external action allows you to connect to the Java server. To configure a Java external action
|
|
Appendix B provides additional information on calling Java classes from Tango. |
Arguments may include any value-returning Tango meta tags, which are substituted when the action is executed. Assigning AttributesYou can also assign the following attributes to an External action: |
For a description of each attribute, see "Assigning Attributes to Actions". |
You assign these attributes using the Attributes menu. You can also control+click the External action icon or name in the application file, or click the open External action editing window to display a contextual menu of available attributes. The Properties command is also available in this menu. If you control+click an action parameter, the Edit command is active allowing you to edit the parameter value; otherwise, it is disabled (grayed). Deleting ParametersTo delete an External action parameter
Executing an External ActionWhen an External action is executed, the DLL, command line, or Java specified is called and the parameters are passed to it. An Apple Event, along with any parameters specified, is sent to the target application. |
For more information, see "<@COLUMN>" in the Meta Tags and Configuration Variables manual. |
Any results returned are accessible in Results HTML in the same way as in the Search action--by using a <@ROWS></@ROWS> block. The <@COLUMN> meta tag, however, does not work in the External action. You must use the <@COL> meta tag along with an item number to refer to data items, as the items do not have names. A single item result is treated as a one-column row, a list of items is treated as a row of columns, and a list of lists is treated as a rowset. For example, if an External action returns a list of lists of three data items each, all the results can be viewed with the following Results HTML: |
For more information, see "<@ROWS> </@ROWS>" in the Meta Tags and Configuration Variables manual. |
<@ROWS> For the command line and Java options, the value returned is treated as tab and return delimited: a tab separates columns and a return separates rows. (For DLLs, rows and columns are determined by the Tango DLL interface: see the Tango 2000 User's Guide for Windows for details.) Only textual data can be returned from an External action. If any data item retrieved from an Apple Event is not a text string, Tango tries to convert it to a text representation. Most standard Apple Event data types can be converted to text; one exception is Boolean data items. If Tango cannot convert the data to a string, an error occurs. The entire result rowset from an External action is automatically assigned to a local array variable, resultSet. If the External action generates no data, and you have specified No Results HTML for the action, that HTML is processed instead of the Results HTML. Disabling JavaScript, Java and External Actions |
You can specify that external actions only are executed in a specified directory of Tango Server using the absolutePathPrefix configuration variable. Using this configuration variable to set the path ensures that users cannot access directories other than the specified ones when using the External action. |
|
JavaScript, Java, and External actions are by default enabled in Tango. If you want to disable (or enable) these features, you can do so by changing the following options in the Configuration Manager (the config.taf application file), in the Feature Switches screen: |
|
Copyright © 1999, Pervasive Software. All rights reserved.