ComponentInheritanceValueMap.java
2.01 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.commons.inherit;
import com.day.cq.commons.ValueMapWrapper;
import com.day.cq.commons.inherit.InheritanceValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
public class ComponentInheritanceValueMap
extends ValueMapWrapper
implements InheritanceValueMap {
protected Resource resource;
public ComponentInheritanceValueMap(Resource resource) {
super(ResourceUtil.getValueMap((Resource)resource));
this.resource = resource;
}
public ComponentInheritanceValueMap(ValueMap map) {
super(map);
this.resource = null;
}
@Override
public <T> T get(String name, Class<T> type) {
if (type == null) {
return (T)this.get(name);
}
return (T)super.get(name, type);
}
@Override
public <T> T getInherited(String name, Class<T> type) {
T value = this.get(name, type);
if (value == null) {
value = this.getParentComponentValue(name, type);
}
return value;
}
@Override
public <T> T getInherited(String name, T defaultValue) {
Class type = defaultValue == null ? null : defaultValue.getClass();
Class value = this.getInherited(name, (T)type);
if (value == null) {
value = defaultValue;
}
return (T)value;
}
protected <T> T getParentComponentValue(String name, Class<T> type) {
if (this.resource == null || this.resource.getName().equals("jcr:content")) {
return null;
}
Resource parent = this.resource.getParent();
if (parent == null) {
return null;
}
return (T)new ComponentInheritanceValueMap(parent).getInherited(name, (T)type);
}
}