The AlertHandlerInterface defines an interface that the new alert channel calls to carry out the delivery of alert notifications. This interface contains a single method, shown below, that must be implemented. Once written and compiled, the class file must be placed somewhere in the CLASSPATH

public void alertHandlerAction(AlertTargetMessage pMsg,
       List pUsers,AlertMgr.MessageMapProps pMsgProps);

The first parameter is the atg.portal.alert.AlertTargetMessage object that contains properties pertaining to the message and its targeted audience. Typically the only property of this class that is used in the handler is the message bean. The other properties, the message type, the target type, and the list of targets, are available for special situations that might require advanced filtering and also for logging and debug messages. You can access the message bean associated with the alert being processed like this:

...
Object msgBean = pMsg.getMessageBean();
...

The following code sample shows how to use the AlertTargetMessage properties to produce coherent debugging messages. Since the example implementation of the AlertHandlerInterface below is assumed to be an atg.nucleus.GenericService, the logging capability of GenericService is used.

...
// If there aren't any users, then log empty user list
if (pUsers.size() <= 0)
 {
    if (isLoggingDebug())
      logDebug("Empty User list for target = " + pMsg.getTargetType());
    return;
 }
...

For a full description of the methods available in the atg.portal.alert.AlertTargetMessage class, see the Javadoc for that class in the ATG API Reference.

The second parameter in the alertHandlerAction method is a List that contains user objects represented as atg.repository.RepositoryItem objects. You can retrieve any property placed on each user that may have consequences for the delivery of the alert. For example, the code below shows how the EmailAlertHandler loops through the List of users retrieving their e-mail addresses:

...
// Loop thru each user retrieving their email address
List recipients = new ArrayList();
for (int i = 0; i < pUsers.size(); i++)
{
    RepositoryItem user = (RepositoryItem)pUsers.get(i);
    recipients.add((String)user.getPropertyValue(getEmailAddressPropertyName()));
}
...

The third argument in the alertHandlerAction method is the MessageMapProps object. This is a public nested class defined in atg.portal.alert.AlertMgr. The MessageMapProps class reads in all the resources for a specific message type from its resource bundle, provides access methods to these properties, and provides a utility method to format the message’s alert text. The AlertMgr maintains a Map of message types to their resource bundles that is initialized by each gear’s definition file.

The following code sample shows how to use the MessageMapProps argument to obtain a locale-sensitive alert message formatted with the message bean argument. Note that the locale obtained from the user’s properties may or may not be desirable depending upon the circumstances. For example, if you want to send an alert to a user by e-mail, then you probably want to obtain the locale from the user’s locale property. However, if you want to send an alert to a portal page using the Alerts gear, you should instead use the Web page’s request locale to create the Web alert display text.

...
Object msgBean = pMsg.getMessageBean()
for (int i = 0; i < pUsers.size(); i++)
{
    RepositoryItem user = (RepositoryItem)pUsers.get(i);
    String locName = (String)user.getPropertyValue(getLocalePropertyName()));
    Locale locale = RequestLocale.getCachedLocale(locName);
    String alertText = pMsgProps.getWebDisplayString(msgBean, locale);
}
...

The class atg.servlet.RequestLocale is an ATG utility class that houses information about the current request’s locale. For a full description of the methods available in the atg.portal.alert.AlertMgr.MessageMapProps class, see the Javadoc for that class in the ATG API Reference.

 
loading table of contents...