Respond to Create Channel and Update Channel Settings Events

Overview

This page describes how to implement custom logic that executes when a user creates a channel or updates a channel's settings in Bloomreach Content.

When to Use

Implement a ChannelManagerEventListener when you need to trigger custom logic in response to channel creation or channel settings updates. Common use cases include:

  • Logging channel lifecycle events
  • Synchronizing external systems when channels change
  • Enforcing additional business rules on channel configuration

ChannelManagerEventListener Interface

The HST API provides the org.hippoecm.hst.configuration.channel.ChannelManagerEventListener interface. This interface defines two callback methods:

  • void channelCreated(ChannelManagerEvent event)
    Invoked immediately after a channel is created from a blueprint.
  • void channelUpdated(ChannelManagerEvent event)
    Invoked immediately after a channel's settings are updated.

You can register multiple implementations of ChannelManagerEventListener in your project. When a channel is created or updated, the corresponding callback method is called on each registered listener.

To activate your listener, register it as a Spring bean. See the Spring Configuration example below.

Example Implementation

The following example demonstrates a ChannelManagerEventListener that logs information about channel creation and update events. This implementation is part of the Hippo Test Suite.

Implementation Class

hippo-testsuite/components/src/main/java/org/hippoecm/hst/demo/channel/DemoChannelManagerEventListener.java

/** * DemoChannelManagerEventListener * <P> * Example <CODE>ChannelManagerEventListener</CODE> implementation * which simply logs all the triggered event information. * </P> */ public class DemoChannelManagerEventListener implements ChannelManagerEventListener { private static Logger log = LoggerFactory.getLogger(DemoChannelManagerEventListener.class); public void channelCreated(ChannelManagerEvent event) { log.info("A channel has been created. {}", channelManagerEventToString(event)); } public void channelUpdated(ChannelManagerEvent event) { log.info("A channel has been updated. {}", channelManagerEventToString(event)); } private String channelManagerEventToString(ChannelManagerEvent event) { StringBuilder sb = new StringBuilder(100); sb.append("{ "); Blueprint blueprint = event.getBlueprint(); // blueprint can be null if (blueprint != null) { sb.append("blueprint: [ "); sb.append(blueprint.getId()).append(", "); sb.append(blueprint.getName()).append(", "); sb.append(blueprint.getDescription()); sb.append(" ], "); } Channel channel = event.getChannel(); // channel will never be null sb.append("channel: [ "); sb.append(event.getChannel().getId()).append(", "); sb.append(channel.getName()).append(", "); sb.append(channel.getContentRoot()); sb.append(" ], "); Node configRootNode = event.getConfigRootNode(); try { if (configRootNode != null) { sb.append("configRootNode: "); sb.append(configRootNode.getPath()); } } catch (RepositoryException e) { log.error("Failed to read channel node path", e); } sb.append(" }"); return sb.toString(); } }

Spring Configuration

Register your ChannelManagerEventListener implementation as a Spring bean to enable event handling.

hippo-testsuite/components/src/main/resources/META-INF/hst-assembly/overrides/channelManagerListenerExample.xml

<!-- Custom channel manager event listeners in the following may be overriden in their project specific assembly. --> <bean id="customChannelManagerEventListeners" class="org.springframework.beans.factory.config.ListFactoryBean"> <property name="sourceList"> <list> <bean class= "org.hippoecm.hst.demo.channel.DemoChannelManagerEventListener"> </bean> </list> </property> </bean>

Verification

After registering your listener and deploying your project, create or update a channel in the Experience manager. Verify that your custom logic executes as expected (for example, check the logs for output from your listener).

Share Feedback
Page: /build/experience-pages-channels/channelmanagereventlistener
Section: Build
Category *