How to use Interface ResourceChangeListener

Avatar

Avatar

Reini-

Avatar

Reini-

Reini-

31-07-2016

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

Replies

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

01-08-2016

Avatar

Avatar

stevec2515680

Avatar

stevec2515680

stevec2515680

01-08-2016

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

01-02-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_CHANG...

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

01-02-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/ad...