ReplicationInventoryPrinter.java
5.63 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.inventory.Format
* org.apache.felix.inventory.InventoryPrinter
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.replication.impl.inventory;
import com.day.cq.replication.impl.inventory.AgentPrinter;
import com.day.cq.replication.impl.inventory.BaseAgentPrinter;
import com.day.cq.replication.impl.inventory.DefaultAgentPrinter;
import com.day.cq.replication.impl.inventory.StaticAgentPrinter;
import com.day.cq.replication.impl.inventory.TriggeredAgentPrinter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.InventoryPrinter;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
@Component
@Service(value={InventoryPrinter.class})
@Properties(value={@Property(name="felix.inventory.printer.name", value={"replication"}), @Property(name="felix.inventory.printer.title", value={"Granite Replication"})})
public class ReplicationInventoryPrinter
implements InventoryPrinter {
@Reference
private ResourceResolverFactory resolverFacoty;
private final Map<String, AgentPrinter> printers = new HashMap<String, AgentPrinter>();
private final AgentPrinter defaultPrinter = new DefaultAgentPrinter();
@Activate
protected void activate() throws Exception {
this.register(new TriggeredAgentPrinter(), "publish", "flush", "test_and_target", "outbox");
this.register(new BaseAgentPrinter(), "publish_reverse");
this.register(new StaticAgentPrinter(), "static");
}
private /* varargs */ void register(AgentPrinter printerDelegate, String ... printersName) {
for (String printerName : printersName) {
this.printers.put(printerName, printerDelegate);
}
}
@Deactivate
protected void deactivate() throws Exception {
this.printers.clear();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void print(PrintWriter pw, Format fmt, boolean isZip) {
ResourceResolverFactory rrf = this.resolverFacoty;
if (rrf != null) {
pw.println("Granite Replication");
pw.println("-------------------");
pw.println();
ResourceResolver resolver = null;
try {
resolver = rrf.getServiceResourceResolver((Map)new HashMap<String, Object>(){});
Resource parentRsrc = resolver.getResource("/etc/replication");
if (parentRsrc == null) {
pw.println("Unable to read any configured agents. /etc/replication does not exist.");
return;
}
for (Resource agentsRsrc : parentRsrc.getChildren()) {
Resource content;
if (agentsRsrc.isResourceType("sling:Folder") || (content = agentsRsrc.getChild("jcr:content")) == null) continue;
String category = (String)((ValueMap)content.adaptTo(ValueMap.class)).get("jcr:title", (Object)agentsRsrc.getName());
pw.println(category);
pw.println("----------------------------------------------------");
for (Resource agentRsrc : agentsRsrc.getChildren()) {
if (agentRsrc.isResourceType("nt:unstructured") || (content = agentRsrc.getChild("jcr:content")) == null) continue;
AgentPrinter printer = this.printers.get(agentRsrc.getName());
if (printer == null) {
printer = this.defaultPrinter;
}
String id = agentRsrc.getName();
ValueMap vm = (ValueMap)content.adaptTo(ValueMap.class);
printer.print(id, vm, pw);
pw.println();
pw.println("----------------------------------------------------");
}
pw.println();
}
}
catch (LoginException parentRsrc) {}
finally {
if (resolver != null) {
resolver.close();
}
}
}
}
protected void bindResolverFacoty(ResourceResolverFactory resourceResolverFactory) {
this.resolverFacoty = resourceResolverFactory;
}
protected void unbindResolverFacoty(ResourceResolverFactory resourceResolverFactory) {
if (this.resolverFacoty == resourceResolverFactory) {
this.resolverFacoty = null;
}
}
}