FrameworkComponentPostProcessor.java 2.63 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.ModifiableValueMap
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.servlets.post.Modification
 *  org.apache.sling.servlets.post.SlingPostProcessor
 */
package com.day.cq.analytics.sitecatalyst.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.SlingPostProcessor;

@Component
@Service
public class FrameworkComponentPostProcessor
implements SlingPostProcessor {
    private static final String PN_DEFAULTSTORE = "cq:defaultStore";
    private static final String RP_DEFAULTSTORE = "./cq:defaultStore";
    private static final String RT_CBCONTEXTHUBMAPPINGS = "cq/analytics/components/mappings/cbcontexthubmappings";

    public void process(SlingHttpServletRequest request, List<Modification> changes) throws Exception {
        if (this.isCBContextHubMappingRequest(request)) {
            this.handleCBContextHubMappings(request);
        }
    }

    private boolean isCBContextHubMappingRequest(SlingHttpServletRequest request) {
        Resource resource = request.getResource();
        String defaultStore = request.getParameter("./cq:defaultStore");
        return resource != null && resource.isResourceType("cq/analytics/components/mappings/cbcontexthubmappings") && defaultStore != null;
    }

    private void handleCBContextHubMappings(SlingHttpServletRequest request) {
        String store;
        ModifiableValueMap valueMap;
        Resource resource = request.getResource();
        String defaultStore = request.getParameter("./cq:defaultStore");
        if (resource != null && defaultStore != null && (store = (String)(valueMap = (ModifiableValueMap)resource.adaptTo(ModifiableValueMap.class)).get("cq:defaultStore", String.class)) != null && !store.equals(defaultStore)) {
            HashSet<String> keysToRemove = new HashSet<String>();
            for (String key2 : valueMap.keySet()) {
                if (key2.indexOf(":") != -1) continue;
                keysToRemove.add(key2);
            }
            for (String key2 : keysToRemove) {
                valueMap.remove((Object)key2);
            }
        }
    }
}