BrandsRetriever.java 1.48 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.sling.api.resource.AbstractResourceVisitor
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 */
package com.day.cq.personalization.impl;

import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.AbstractResourceVisitor;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

public class BrandsRetriever {
    public static Map<String, String> getBrands(ResourceResolver resourceResolver) {
        BrandsVisitor visitor = new BrandsVisitor();
        visitor.accept(resourceResolver.getResource("/content/campaigns"));
        return visitor.getBrands();
    }

    static class BrandsVisitor
    extends AbstractResourceVisitor {
        Map<String, String> brands = new HashMap<String, String>();

        BrandsVisitor() {
        }

        protected void visit(Resource resource) {
            if ("mcm/components/brandpage".equals(resource.getResourceType())) {
                ValueMap props = (ValueMap)resource.adaptTo(ValueMap.class);
                this.brands.put((String)props.get("jcr:title", (Object)resource.getParent().getName()), resource.getParent().getPath());
            }
        }

        public Map<String, String> getBrands() {
            return this.brands;
        }
    }

}