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 do the same things with a few mouse clicks. For compatibility reasons there is also an Automation task where you can put BeanShell code.

OpenKM uses BeanShell. For more information, see 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 a script as part of the 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 as a 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 are several variables that are directly injected into the scripting environment and can be used.

List of variables that can be used directly:

VariableDescription

systemToken

The system token.

node

Involved node (NodeDocument, NodeFolder, etc.)

uuid

The node's unique identifier.

file

Only available when uploading or updating document content.

userId

The user ID.

Example:

import com.openkm.util.*;
import com.openkm.api.*;

OKMProperty okmProperty = ContextWrapper.getContext().getBean(OKMProperty.class);

// Variable uuid is injected by automation to the scripting environment
okmProperty.addKeyword(null, uuid, "test");