Create your own import station plugin

To create your own import plugin must create a new class that implements PropertiesProcessor interface:

public interface PropertiesProcessor extends Plugin {
    String getName();
    String getDescription();
    Class<?> getFormBeanClass();
    boolean doJob(long executionTaskId, FormProperties formProperties, OKMWebservices webService);
    String getAddTaskFormName();
    String getEditTaskFormName();

Do not miss the tag @PluginImplementation otherwise the application plugin system will not be able to retrieve the new class.

 The new class must be loaded into the package com.openkm.processor because application plugin system will try to load from there.

Methods description

getName() String

This method will provide the name of the plugin.

getDescription() String

Detailed plugin description shown below the combo named "Processor" in the task edit view.

getFormBeanClass() Class<?>

Return the bean used to store the information of the application form.

doJob(long executionTaskId, FormProperties formProperties, WsInterface wsInterface) boolean

This is the main method of the plugin.

getAddTaskFormName() String

Return the name of the form used for creating properties.

getEditTaskFormName() String

Return the name of the form used for editing properties.

Form bean

The plugin must have a bean class associated what is used for setting plugin custom properties. These properties will be stored in a map named customProperties.

The Form bean class must extend FormProperties class.

You can get these properties values from object formProperties in the method doJob. The  object formProperties has a field named customProperties.


  • The value of the keys into the map, must be the same of the HTML form names.


For example if we want to store a String property named path in this form, the html form name must be <input name="path" ...>. 

Html forms

The plugin must have two forms:

  • Create task form.
  • Edit task form.

They must be located inside src/main/html folder.

We need these forms, because each plugin will have it's own custom properties.

The name convention should be: <name_of_plugin>-form.html and <name_of_plugin>-form-edit.html but could be whatever name.

This convention is usefull in order to not override predefined forms. 


  • Plugin class at src/main/java/com/openkm/processor/ExampleProcessor.class
  • Create form at src/main/html/ExampleProcessor-form.html
  • Edit form  at src/main/html/ExampleProcessor-form.html

These forms will be loaded in the Add Task and Edit Task web screens when processor combo is changed.

They should contain neccessary HTML and Javascript code in order to store and load Processor properties.

In edit form, for automatic filling fields you must use the class="form-control parameter".

For example:

<input type="text" class="form-control parameter" name="userPath">

Will set the parameter userPath and into the input with name equals to "userPath".

Event log

Application have a log feature what enables to get a complete trace of what is happening while processing a task.

Log or not the events is an implementation decision of the plugin code designer. We encourage log every event, however is a decision of the plugin code designer do it or not.

For this purpose the class used to log events is ImportStationLogger.

There are the following methods available:

logOk(long taskExecutionId, String description) void

Log and event to indicate that the operation was OK

logErrorEvent(long taskExecutionId, String description) void

Log and event to indicate that there was an error.

logErrorEvent(long taskExecutionId, String header, Exception e)


Log and event to indicate that there was an error. This method will log exception stack trace as description.

The parameter header is used to add a log message to the exception stack trace.


long taskExecutionId = ...;
// Mark as ok
ImportStationLogger.logOkEvent(taskExecutionId, "description");
// Mark with errors
ImportStationLogger.logErrorEvent(taskExecutionId, "description of error");
// Mark with error and exception detail
ImportStationLogger.logErrorEvent(taskExecutionId, "header", new Exception("exception"));


This is a sample pom.xml configuration:

You can download source code from here: 

<project xmlns="" xmlns:xsi=""
			<name>OpenKM Maven Repository</name>
		<dependency>                                               <groupId>com.openkm</groupId>
		<!-- Plugin framework -->
		<!-- OpenKM SDK -->

ExampleProcessor class:

Description: Imports only files from an specific source folder.

public class ExampleProcessor implements PropertiesProcessor {

    public boolean doJob(long executionTaskId, FormProperties formProperties, OKMWebservices webServices) {
        boolean returnValue = true;
        File folder = new File((String) formProperties.getCustomPropertiesMap().get(ProcessorConstants.USER_PATH));
        if (folder.exists() && folder.isDirectory()) {
            for (File file : folder.listFiles()) {
                if (file.isFile() && file.canRead()) {
                    try {
                        uploadDocument(file, formProperties, webServices);
                        ImportStationLogger.logOkEvent(executionTaskId, "File uploaded: " + file.getName());
                    } catch (IOException | UnsupportedMimeTypeException | FileSizeExceededException | UserQuotaExceededException
                            | VirusDetectedException | ItemExistsException | PathNotFoundException | AccessDeniedException
                            | RepositoryException | DatabaseException | ExtensionException | AutomationException
                            | UnknowException | WebserviceException e) {
                        ImportStationLogger.logErrorEvent(executionTaskId, "Error uploading file" + file.getName(), e);
                        returnValue = false;
        return returnValue;

    private void uploadDocument(File file, FormProperties formProperties, OKMWebservices webServices) throws IOException, UnsupportedMimeTypeException,       FileSizeExceededException, UserQuotaExceededException, VirusDetectedException, ItemExistsException, PathNotFoundException, AccessDeniedException,       RepositoryException, DatabaseException, ExtensionException, AutomationException, UnknowException, WebserviceException {
        Document doc = new Document();

                + ImportStationConstants.OKM_REPOSITORY_FILE_SEPARATOR + FilenameUtils.getBaseName(file.getName()) + "."
                + FilenameUtils.getExtension(file.getName()));

        // Create document
        webServices.createDocument(doc, FileUtils.openInputStream(file));        

    public String getAddTaskFormName() {
        return "ExampleProcessor-form.html";

    public String getDescription() {
        return "This is my custom form";

    public String getEditTaskFormName() {
        return "ExampleProcessor-form-edit.html";

    public Class<?> getFormBeanClass() {
        return ExampleFormProperties.class;

    public String getName() {
        return "ExampleProcessor";


 Bean code. Only stores user local path and OpenKM destiny path:

ExampleFormProperties class:


  • Set source folder path.
  • Set OpenKM folder target.

public class ExampleFormProperties extends FormProperties {

     * Public constructor.
     * @param parameterMap
     *        map with values
    public ExampleFormProperties(final Map<String, Object> parameterMap) {

        // Add custom properties
                parameterMap.get(ProcessorConstants.USER_PATH) instanceof String[]
                        ? ((String[]) parameterMap.get(ProcessorConstants.USER_PATH))[0]
                        : parameterMap.get(ProcessorConstants.USER_PATH));
                parameterMap.get(ProcessorConstants.DESTINY_PATH) instanceof String[]
                        ? ((String[]) parameterMap.get(ProcessorConstants.DESTINY_PATH))[0]
                        : parameterMap.get(ProcessorConstants.DESTINY_PATH));




  • Form field source folder.
  • Form field target folder.

<div class="form-group">
	<label class="control-label col-sm-2" for="userPath">User path:</label>
	<div class="col-sm-10">
		<input type="text" class="form-control" name="userPath"
			placeholder="user path" required />
<div class="form-group">
	<label class="control-label col-sm-2" for="destinyPath">Destiny path into OpenKM:</label>
	<div class="col-sm-10">
		<input type="text" class="form-control" name="destinyPath" placeholder="/okm:root/import/" required />



  • Form field source folder.
  • Form field target folder.
Note: The fields have a class named "parameter" for automatic fields initialization.
<div class="form-group">
	<label class="control-label col-sm-2" for="userPath">User path:</label>
	<div class="col-sm-10">
		<input type="text" class="form-control parameter" name="userPath"
			value="${userPath}" required />
<div class="form-group">
	<label class="control-label col-sm-2" for="destinyPath">Destiny path into OpenKM:</label>
	<div class="col-sm-10">
		<input type="text" class="form-control parameter" name="destinyPath" placeholder="/okm:root/import/" required />