Console projects give you the possibility to run Java methods using the current selection as the input. This can be either objects you are browsing with the Object Stores viewer or the result of a query. The output of these Java methods can be printed to the Eclipse console using a simple System.out.println() method, hence the name “Console Projects”. This way you can add functionality that is at this moment not present in the ECM Developer plug-in. It also saves you from creating a full blown project every time you want to do something simple.

Creating Console Projects

For the Console Project to work you have to use the New Project wizard to create a new project. Choose a new Content Engine Console Project in the ECM Developer category. The wizard follow the standard steps you take when you create a new Java Project. When the wizard is finished it adds the infrastructure necessary for running your Console Project to the newly created project. This includes references to the relevant Java API files.

Creating Console Classes

The Java method that you will be calling must be encapsulated in a Java Class. You can either use the New Console Class wizard to generate the Java Class for you or create a new Java Class from scratch. There are two requirement for this class:

  •  The class should have a no arguments constructor.
  •  The class contains a public Java method which takes one argument with the type Object. You can cast this object in the Java method to your specific need.

A minimal Java class will look like this:

package main;

public class MinimalConsoleClass {

	public void run(Object object) throws Exception {

		// TODO write code

	}
}

If you want to generate the Java Class then you can start the wizard using the standard New Class wizard of Eclipse. The wizard for the Content Engine Console class is also located in the ECM developer category.

  • In the first page the basic characteristics of the Java class is configured:
    new_console_project_class
  • In the second wizard page the details of the method can be configured: configure_method
    You can specify the name of the method and the type of the object you expect as the input. The generated method will contain code with a cast to the appropriate Java class. This can of course be changed to anything you like.

The generated code for a Content Engine Console Class targeting documents will look like this:

package client;

import com.filenet.api.core.Document;

/**
 * @author ricardo.belfor
 *
 */
public class MyConsoleClass {

	/**
	 * This method is called for every selected object. The signature of the
	 * method should not be changed. The name of the method and the rest of the
	 * code can be adjusted to your needs.
	 *
	 * @param object
	 *            the selected object
	 * @throws Exception
	 *             the exception. Exceptions are displayed in the console and
	 *             does not stop the execution of the rest of the selected
	 *             objects.
	 */
	public void run(Object object) throws Exception {
		Document document = (Document) object;

		// TODO Auto-generated method stub

	}

}

Coding Console Classes

You write your Java code using the standard Content Engine Java API. When you are writing code for a Content Engine object store then the single object used as the input for the method can be used to access most of the Java domain model. From a Document, Folder and CustomObject object you can get the ObjectStore object, and from this object you can go almost anywhere.

Running Console Projects

Before you execute the method make sure that the Java class is built by the Eclipse IDE. This will normally be the case if you are building the code automatically. Also make sure that you have placed a break point if you are executing in debug mode.

The method can be executed using the Run Console Project command of the context menu. This will start a wizard:

  • In the first page you have to specify the method and you configure if you want to start in debug mode:
    select_method
    The method is specified using the method selection dialog which is activated by the Browse button. The method selection dialog consists of two parts:
    mehod_selection_dialog
    The top part shows all the Console Project Classes in the workspace and the bottom part contains all the eligible methods of the selected class. If you don’t see you class here you have probably not created the Console Project using the wizard.

  • In the optional second page of the wizard you can specify if you want to use other credentials instead of the default credentials:
    configure_launch_credentials

If the wizard is finished the current selection is used as the input for the method. Output can be shown in the Console using the standard System.out.print() methods. Errors are also shown in the Console. An exception thrown when a object is processed will not terminate execution. A exception thrown during the initialization of the class will stop execution.