SymlinkValueMap.java
1.5 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
*/
package com.adobe.granite.confmgr.impl;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
class SymlinkValueMap
extends ValueMapDecorator {
private final Map<String, Object> source;
private final Resource target;
public SymlinkValueMap(Resource source, Resource target) {
super((Map)target.getValueMap());
this.source = source.getValueMap();
this.target = target;
}
public Object get(Object key) {
if (this.source.containsKey(key.toString())) {
String v;
Object value = this.source.get(key);
if (value instanceof String && (v = (String)value).startsWith("${") && v.endsWith("}")) {
return this.evaluateVariable(v.substring(2, v.length() - 1));
}
return value;
}
return super.get(key);
}
protected Object evaluateVariable(String var) {
if ("sling:targetName".equals(var)) {
return this.target.getName();
}
if (var.startsWith("sling:targetProp/")) {
var = var.substring("sling:targetProp/".length());
return super.get((Object)var);
}
return "${" + var + "}";
}
}