Show TOC

Procedure documentationDeveloping Custom Script Handlers Locate this document in the navigation structure

 

A handler enables you to define code that can be executed by uploading a properly formatted XML file.

For example, to run code to create an iView, the portal provides a handler of the com.sapportals.portal.iview type that enables administrators to create an iView by uploading an XML file.

When an XML file is uploaded, the specified handler classes are called in two phases:

  • Validation: The doValidate() method of each handler is called to make sure the XML for each handler is valid and all mandatory attributes exist. The method returns true if the XML is validated, otherwise false.

  • Execution: The doExecute() and doClean() methods of each handler are called as needed, based on the mode attribute of the <GenericCreator> tag.

Creating a Script Handler

Use the following interfaces to develop a custom script handler:

IHandler

The interface that your handler must implement

IGenericCreatorRegister

An interface that represents a portal service that enables you to register your handler

To create a handler for the XML Content and Actions features, do the following:

  1. Create a class that implements the IHandler interface, as described below.

  2. Within the handler class, modify the necessary attributes of the XML script, as described in Accessing Attributes in the XML Script

  3. Register the handler, as described in Registering and Unregistering Custom Script Handlers

Procedure

  1. Create a new class that implements com.sap.portal.genericcreator.handlers.IHandler.

  2. Implement the following methods:

    • doValidate(): Called once for each <Context> or <Action> tag that specifies the handler. Validate all necessary parameters in this method.

      If any call to doValidate() returns false, the doExecute() and doClean() methods are not called, and the XML script is not executed.

    • doExecute(): Called once for each <Context> or <Action> tag that specifies the handler, if the mode attribute of the <GenericCreator> tag is set to execute.

    • doClean(): Called once for each <Context> or <Action> tag that specifies the handler, if the mode attribute of the <GenericCreator> tag is set to clean.

    Each method receives information about the XML attributes in the <Context> or <Action> tag for which the handler was called, as well as any attributes specified in a nested <Attributes> tag. More information: Accessing Attributes in the XML Script

    Each method also receives information about the user.