LinkCheckerSettingsProviderImpl.java
6.72 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.i18n.I18n
* com.day.cq.rewriter.linkchecker.LinkCheckerSettings
* com.day.cq.rewriter.linkchecker.LinkCheckerSettingsProvider
* com.day.cq.rewriter.linkchecker.LinkRewriteConfig
* com.day.cq.wcm.api.WCMMode
* javax.servlet.ServletRequest
* javax.servlet.http.HttpServletRequest
* org.apache.felix.scr.annotations.Component
* 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.SlingHttpServletRequest
* org.apache.sling.commons.osgi.PropertiesUtil
* org.apache.sling.jcr.api.SlingRepository
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.core.impl;
import com.day.cq.i18n.I18n;
import com.day.cq.rewriter.linkchecker.LinkCheckerSettings;
import com.day.cq.rewriter.linkchecker.LinkCheckerSettingsProvider;
import com.day.cq.rewriter.linkchecker.LinkRewriteConfig;
import com.day.cq.wcm.api.WCMMode;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
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.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={LinkCheckerSettingsProvider.class})
@Properties(value={@Property(name="service.description", value={"LinkChecker Service"})})
public class LinkCheckerSettingsProviderImpl
implements LinkCheckerSettingsProvider {
private final Logger log;
@Reference
protected SlingRepository repository;
private ReentrantReadWriteLock readWriteLock;
private Map<String, RewriteConfigs> configs;
public LinkCheckerSettingsProviderImpl() {
this.log = LoggerFactory.getLogger(this.getClass());
this.readWriteLock = new ReentrantReadWriteLock(true);
this.configs = new HashMap<String, RewriteConfigs>();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public LinkCheckerSettings createSettings(SlingHttpServletRequest request) {
this.readWriteLock.readLock().lock();
try {
LinkCheckerSettings settings = null;
WCMMode mode = WCMMode.fromRequest((ServletRequest)request);
I18n i18n = new I18n((HttpServletRequest)request);
for (Map.Entry<String, RewriteConfigs> configsEntry : this.configs.entrySet()) {
if (!configsEntry.getValue().matches(mode)) continue;
settings = configsEntry.getValue().createSettings(i18n);
break;
}
Iterator<Map.Entry<String, RewriteConfigs>> i$ = settings;
return i$;
}
finally {
this.readWriteLock.readLock().unlock();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void updateConfigs(Map<String, Object> params) {
this.readWriteLock.writeLock().lock();
try {
this.configs.put(PropertiesUtil.toString((Object)params.get("service.pid"), (String)null), new RewriteConfigs(params));
}
finally {
this.readWriteLock.writeLock().unlock();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void deleteConfig(Map<String, Object> params) {
this.readWriteLock.writeLock().lock();
try {
this.configs.remove(PropertiesUtil.toString((Object)params.get("service.pid"), (String)null));
}
finally {
this.readWriteLock.writeLock().unlock();
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
private static class RewriteConfigs {
private final EnumSet<WCMMode> modes = EnumSet.noneOf(WCMMode.class);
private final LinkRewriteConfig invalid;
private final LinkRewriteConfig predated;
private final LinkRewriteConfig expired;
private RewriteConfigs(Map<String, Object> params) {
for (String v : PropertiesUtil.toStringArray((Object)params.get("link.wcmmodes"), (String[])null)) {
this.modes.add(WCMMode.valueOf((String)v.toUpperCase()));
}
this.invalid = this.readRewriteConfig(PropertiesUtil.toBoolean((Object)params.get("link.invalid.remove"), (boolean)false), PropertiesUtil.toString((Object)params.get("link.invalid.prefix"), (String)null), PropertiesUtil.toString((Object)params.get("link.invalid.suffix"), (String)null));
this.predated = this.readRewriteConfig(PropertiesUtil.toBoolean((Object)params.get("link.predated.remove"), (boolean)false), PropertiesUtil.toString((Object)params.get("link.predated.prefix"), (String)null), PropertiesUtil.toString((Object)params.get("link.predated.suffix"), (String)null));
this.expired = this.readRewriteConfig(PropertiesUtil.toBoolean((Object)params.get("link.expired.remove"), (boolean)false), PropertiesUtil.toString((Object)params.get("link.expired.prefix"), (String)null), PropertiesUtil.toString((Object)params.get("link.expired.suffix"), (String)null));
}
private LinkRewriteConfig readRewriteConfig(boolean remove, String prefix, String suffix) {
return new LinkRewriteConfig(remove, prefix, suffix);
}
public boolean matches(WCMMode mode) {
return this.modes.contains((Object)mode);
}
private LinkRewriteConfig localize(LinkRewriteConfig config, I18n i18n) {
return new LinkRewriteConfig(config.remove(), i18n.getVar(config.getPrefix()), i18n.getVar(config.getSuffix()));
}
public LinkCheckerSettings createSettings(I18n i18n) {
LinkCheckerSettings settings = new LinkCheckerSettings();
settings.setInvalidConfig(this.localize(this.invalid, i18n));
settings.setExpiredConfig(this.localize(this.expired, i18n));
settings.setPredatedConfig(this.localize(this.predated, i18n));
return settings;
}
}
}