PageSubscription.java
3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.replication.ReplicationAction
* com.day.cq.replication.ReplicationActionType
* com.day.cq.wcm.api.PageEvent
* com.day.cq.wcm.api.PageModification
* com.day.cq.wcm.api.PageModification$ModificationType
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.PersistableValueMap
* org.osgi.service.event.Event
*/
package com.day.cq.wcm.notification.impl;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.wcm.api.PageEvent;
import com.day.cq.wcm.api.PageModification;
import com.day.cq.wcm.notification.AbstractSubscription;
import com.day.cq.wcm.notification.NotificationContext;
import com.day.cq.wcm.notification.Subscription;
import java.util.Iterator;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.PersistableValueMap;
import org.osgi.service.event.Event;
@Component(metatype=0)
@Service(value={Subscription.class})
@Properties(value={@Property(name="type", value={"page"}, propertyPrivate=1), @Property(name="event.filter", value={"(!(event.application=*))"})})
public class PageSubscription
extends AbstractSubscription {
public static final String PAGE_TYPE = "page";
@Override
public boolean matches(NotificationContext context, Event event) {
String action;
String path;
boolean result = false;
if (event.getTopic().equals("com/day/cq/wcm/core/page")) {
PageEvent pageEvent = PageEvent.fromEvent((Event)event);
PageModification mod = (PageModification)pageEvent.getModifications().next();
path = mod.getPath();
action = mod.getType().toString();
} else if (event.getTopic().equals("com/day/cq/replication")) {
ReplicationAction repEvent = ReplicationAction.fromEvent((Event)event);
path = repEvent.getPath();
action = repEvent.getType().toString();
} else {
path = null;
action = null;
}
if (path != null) {
AbstractSubscription.Filter filter = new AbstractSubscription.Filter(context.getConfiguration());
boolean found = false;
int index = 0;
while (!found && index < filter.actions.length) {
if (filter.actions[index].toLowerCase().equals(action.toLowerCase())) {
found = true;
continue;
}
++index;
}
if (found) {
for (int i = 0; i < filter.list.length; ++i) {
result = filter.list[i].apply(path, result);
}
}
}
return result;
}
}