PageEvent.java
2.81 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
80
81
82
83
84
85
86
87
88
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.osgi.service.event.Event
*/
package com.day.cq.wcm.api;
import com.day.cq.wcm.api.PageModification;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.osgi.service.event.Event;
public final class PageEvent
implements Serializable {
public static final String EVENT_TOPIC = "com/day/cq/wcm/core/page";
private static final String PROPERTY_MODIFICATIONS = "modifications";
private static final String PROPERTY_APPLICATION = "event.application";
private static final String PROPERTY_DISTRIBUTE = "event.distribute";
private final boolean isLocal;
private final List<PageModification> modifications;
public PageEvent(PageModification mod) {
this(Collections.singletonList(mod), true);
}
public PageEvent(List<PageModification> mods) {
this(mods, true);
}
public PageEvent(List<PageModification> mods, boolean isLocal) {
this.modifications = mods;
this.isLocal = isLocal;
}
public Iterator<PageModification> getModifications() {
return this.modifications.iterator();
}
public boolean isLocal() {
return this.isLocal;
}
public static PageEvent fromEvent(Event evt) {
if (!evt.getTopic().equals("com/day/cq/wcm/core/page")) {
return null;
}
ArrayList<PageModification> mods = new ArrayList<PageModification>();
List modProps = (List)evt.getProperty("modifications");
if (modProps != null) {
for (Map modProp : modProps) {
mods.add(PageModification.fromEventProperties(modProp));
}
}
return new PageEvent(mods, evt.getProperty("event.application") == null);
}
protected Dictionary<String, Object> getEventProperties() {
Hashtable<String, Object> properties = new Hashtable<String, Object>();
ArrayList<Map<String, Object>> modProps = new ArrayList<Map<String, Object>>();
Iterator<PageModification> i = this.getModifications();
while (i.hasNext()) {
modProps.add(i.next().getEventProperties());
}
properties.put("modifications", modProps);
if (!this.isLocal) {
properties.put("event.application", "unknown");
}
return properties;
}
public Event toEvent() {
Dictionary<String, Object> props = this.getEventProperties();
props.put("event.distribute", "");
return new Event("com/day/cq/wcm/core/page", props);
}
public Event toNonDistributableEvent() {
return new Event("com/day/cq/wcm/core/page", this.getEventProperties());
}
}