How to use Interface ResourceChangeListener | Community
Skip to main content
Level 2
July 31, 2016

How to use Interface ResourceChangeListener

  • July 31, 2016
  • 4 replies
  • 6308 views

Hi,

in the past I used some static fields (e.g. SlingConstants.TOPIC_RESOURCE_ADDED, SlingConstants.TOPIC_RESOURCE_CHANGED, ...) to implement EventHandlers. Since AEM 6.2 this static fields are deprecated. In JavaDoc I found the hint to use ResourceChangeListener instead. But I didn't find any example how to use ResourceChangeListener. Has anybody an example how to use them?

regards
Reini

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

smacdonald2008
Level 10
August 1, 2016
Level 4
August 1, 2016
Gdubz-57m2mu
Level 5
February 1, 2017

Not sure why it's not showing the @Deprecated annotation on any of the Sling API JavaDocs online[1], but if you open the org.apache.sling.api.SlingConstants class that's included in the AEM 6.2.0 UberJar, you'll see the following:

/** * The topic for the OSGi event which is sent when a resource has been added * to the resource tree. * The event contains at least the {@link #PROPERTY_PATH}, {@link #PROPERTY_RESOURCE_SUPER_TYPE} * and {@link #PROPERTY_RESOURCE_TYPE} properties. * @since 2.0.6 (Sling API Bundle 2.0.6) * * @deprecated Register a {@link ResourceChangeListener} instead */ @Deprecated public static final String TOPIC_RESOURCE_ADDED = "org/apache/sling/api/resource/Resource/ADDED"; /** * The topic for the OSGi event which is sent when a resource has been removed * from the resource tree. * The event contains at least the {@link #PROPERTY_PATH}. As the resource has already been removed * no further information like resource type etc. might be available. * @since 2.0.6 (Sling API Bundle 2.0.6) * * @deprecated Register a {@link ResourceChangeListener} instead */ @Deprecated public static final String TOPIC_RESOURCE_REMOVED = "org/apache/sling/api/resource/Resource/REMOVED"; /** * The topic for the OSGi event which is sent when a resource has been changed * in the resource tree. * The event contains at least the {@link #PROPERTY_PATH}, {@link #PROPERTY_RESOURCE_SUPER_TYPE} * and {@link #PROPERTY_RESOURCE_TYPE} properties. * Since 2.2.0 the event might contain these properties {@link #PROPERTY_ADDED_ATTRIBUTES}, * {@link #PROPERTY_REMOVED_ATTRIBUTES}, {@link #PROPERTY_CHANGED_ATTRIBUTES}. All of them are * optional. * @since 2.0.6 (Sling API Bundle 2.0.6) * * @deprecated Register a {@link ResourceChangeListener} instead */ @Deprecated public static final String TOPIC_RESOURCE_CHANGED = "org/apache/sling/api/resource/Resource/CHANGED";

[1] http://sling.apache.org/apidocs/sling8/org/apache/sling/api/SlingConstants.html#TOPIC_RESOURCE_CHANGED

Gdubz-57m2mu
Level 5
February 1, 2017

Also worth noting, in my own search for replacement of these deprecations in our own listener classes, I stumbled onto this code sample from Adobe Consulting Services' ACS AEM Samples github[1]: SampleResourceChangeListener.java[2].

Looks like exactly what you need, Reini-.

[1] https://github.com/Adobe-Consulting-Services/acs-aem-samples
[2] https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/adobe/acs/samples/events/impl/SampleResourceChangeListener.java

aanchal-sikka
Community Advisor
Community Advisor
January 31, 2024

Please refer to the examples on : https://techrevelhub.wordpress.com/2017/03/15/resourcechangelistener/ 

 

It has code samples for Resource Change and Property Change as well

Aanchal Sikka