Utils.java 1.29 KB
/*
 * 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;
    }
}