UndoConfigServiceImpl.java
7.27 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Modified
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.apache.sling.commons.osgi.OsgiUtil
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.undo.impl;
import com.day.cq.wcm.undo.UndoConfigService;
import java.io.IOException;
import java.io.Writer;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(label="Day CQ WCM Undo Configuration", immediate=1, metatype=1, description="Provides configuration for CQ's undo facilities.", name="com.day.cq.wcm.undo.UndoConfig")
@Service
public class UndoConfigServiceImpl
implements UndoConfigService {
@Property(boolValue={1})
protected static final String UNDO_ENABLED = "cq.wcm.undo.enabled";
@Property(value={"/var/undo"})
protected static final String UNDO_PATH = "cq.wcm.undo.path";
@Property(intValue={10})
protected static final String UNDO_DATA_VALIDITY = "cq.wcm.undo.validity";
@Property(intValue={20})
protected static final String UNDO_STEPS = "cq.wcm.undo.steps";
@Property(value={""})
protected static final String UNDO_PERSISTENCE = "cq.wcm.undo.persistence";
@Property(boolValue={1})
protected static final String UNDO_PERSISTENCE_MODE = "cq.wcm.undo.persistence.mode";
@Property(value={""})
protected static final String UNDO_MARKER_MODE = "cq.wcm.undo.markermode";
@Property(value={"foundation/components/*"}, cardinality=4096)
protected static final String UNDO_WHITELIST = "cq.wcm.undo.whitelist";
@Property(value={"foundation/components/form/start:removeParagraph"}, cardinality=4096)
protected static final String UNDO_BLACKLIST = "cq.wcm.undo.blacklist";
private Map<String, Object> config;
private static final Logger log = LoggerFactory.getLogger(UndoConfigServiceImpl.class);
private String toString(String[] array) {
StringBuilder str = new StringBuilder(128);
boolean isFirst = true;
for (String item : array) {
if (!isFirst) {
str.append(", ");
} else {
isFirst = false;
}
str.append(item);
}
return str.toString();
}
private void configure(ComponentContext context) {
Boolean isStepSave;
this.config = new HashMap<String, Object>();
Dictionary dict = context.getProperties();
Boolean enabled = (Boolean)dict.get("cq.wcm.undo.enabled");
enabled = enabled != null ? enabled : Boolean.TRUE;
this.config.put("enabled", enabled);
String undoPath = (String)dict.get("cq.wcm.undo.path");
this.config.put("path", undoPath);
log.info("Path for undo: {}", (Object)undoPath);
Integer undoDataValidity = (Integer)dict.get("cq.wcm.undo.validity");
this.config.put("dataValidity", undoDataValidity);
log.info("Undo data validity: {} hours", (Object)undoDataValidity);
Integer undoSteps = (Integer)dict.get("cq.wcm.undo.steps");
this.config.put("steps", undoSteps);
log.info("Number of undoable steps: {}", (Object)undoSteps);
String persistence = (String)dict.get("cq.wcm.undo.persistence");
if (persistence.length() > 0) {
this.config.put("persistence", persistence);
log.info("Undo persistence module: {}", (Object)persistence);
}
String persistenceMode = (isStepSave = (Boolean)dict.get("cq.wcm.undo.persistence.mode")) != false ? "step" : "unload";
this.config.put("persistenceMode", persistenceMode);
log.info("Undo persistence mode: {}", (Object)persistenceMode);
String markerMode = (String)dict.get("cq.wcm.undo.markermode");
if (markerMode.length() > 0) {
this.config.put("markerMode", markerMode);
log.info("Undo marker mode: {}", (Object)markerMode);
}
String[] whitelist = OsgiUtil.toStringArray(dict.get("cq.wcm.undo.whitelist"));
this.config.put("whitelisted", whitelist);
log.info("Whitelisted components: {}", (Object)this.toString(whitelist));
String[] blacklist = OsgiUtil.toStringArray(dict.get("cq.wcm.undo.blacklist"));
this.config.put("blacklisted", blacklist);
log.info("Blacklisted component oeprations: {}", (Object)this.toString(blacklist));
}
@Activate
protected void activate(ComponentContext context) {
this.configure(context);
}
@Modified
protected void modified(ComponentContext context) {
this.configure(context);
}
@Override
public <T> T getConfig(String name, Class<T> type) {
Object value = this.config.get(name);
try {
return (T)value;
}
catch (ClassCastException cce) {
return null;
}
}
@Override
public void writeClientConfig(Writer out) throws IOException {
try {
String[] blacklist;
String[] whitelist;
JSONWriter json = new JSONWriter(out);
json.object();
json.key("enabled");
json.value((Object)this.getConfig("enabled", Boolean.class));
json.key("maxUndoSteps");
json.value((Object)this.getConfig("steps", Integer.class));
String persistenceMode = this.getConfig("persistence", String.class);
if (persistenceMode != null) {
json.key("persistence");
json.value((Object)persistenceMode);
}
json.key("persistenceMode");
json.value((Object)this.getConfig("persistenceMode", String.class));
String markerMode = this.getConfig("markerMode", String.class);
if (markerMode != null) {
json.key("markerMode");
json.value((Object)markerMode);
}
json.key("whitelist");
json.array();
for (String item : whitelist = this.getConfig("whitelisted", String[].class)) {
json.value((Object)item);
}
json.endArray();
json.key("blacklist");
json.array();
for (String item2 : blacklist = this.getConfig("blacklisted", String[].class)) {
json.value((Object)item2);
}
json.endArray();
json.endObject();
}
catch (JSONException je) {
IOException ioe = new IOException("Could not create JavaScript representation");
ioe.initCause((Throwable)je);
throw ioe;
}
}
}