Utils.java
1.29 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
/*
* 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.adobe.granite.contexthub.commons;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
public class Utils {
public static String getInheritedProperty(Resource resource, String property) {
String previousPath = null;
String value = null;
while (value == null && resource != null) {
String currentPath;
Resource here = resource;
if (!"jcr:content".equals(here.getName())) {
here = here.getChild("jcr:content");
}
if (here != null && !(currentPath = here.getPath()).equals(previousPath)) {
ValueMap properties = ResourceUtil.getValueMap((Resource)here);
previousPath = currentPath;
value = (String)properties.get(property, String.class);
if (value != null && value.length() == 0) {
value = null;
}
}
resource = resource.getParent();
}
return value;
}
}