Scripting

Scripting was an advanced feature that enables administrators to execute some BeanShell scripts in folders, triggered on every notified event ( for example uploading documents ).

This feature has been enhanced by Automation ( see ExecuteScripting at Built in Automation Action plugins ), which helps you to do the same things with a few mouse clicks. For compatibility reasons there is also an Automation task where you can put a BeanShell code.

OpenKM uses BeanShell. For more information check http://www.beanshell.org/intro.html.

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.

See some examples at Scripting samples.

Execute script as part of application starting process

Can be executed as an script as a part of application starting process. To do so, just create a start.bsh file in $TOMCAT_HOME

For example, we use this feature to create a complete environment (create custom users, register property groups, register workflow) each time the OpenKM demo is restarted.

Execute script as part of application stopping process

Can be executed a an script as part of the application stopping process. To do so, just create a stop.bsh file in $TOMCAT_HOME

Scripting in Automation

In the  Automation Scripting execution, there're several variables that are directly injected in scripting environment that can be used.

List of variables what can be used directly:

VariableDescription

systemToken

The system token.

node

Involved node (NodeDocument, NodeFolder, etc. )

uuid

Node unique identifier.

file

Only available when converting a document to PDF or to SWF.

userId

The user id.

Example:

import com.openkm.api.*;
    
// Variable uuid is injected by automation to the scripting environment
OKMProperty.getInstance().addKeyword(null, uuid, "test");