SubscriptionParameters.java 2 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.foundation.forms.FormsHelper
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceUtil
 *  org.apache.sling.api.resource.ValueMap
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.mcm.campaign.servlets.util;

import com.day.cq.wcm.foundation.forms.FormsHelper;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SubscriptionParameters {
    private final Logger log;
    private List<String> subscriptions;

    public SubscriptionParameters() {
        this.log = LoggerFactory.getLogger(this.getClass());
        this.subscriptions = new ArrayList<String>(4);
    }

    public void parseParameters(SlingHttpServletRequest request, Resource form) {
        Iterator formElements = FormsHelper.getFormElements((Resource)form);
        while (formElements.hasNext()) {
            String[] subscriptPrms;
            String name;
            Resource field = (Resource)formElements.next();
            ValueMap props = ResourceUtil.getValueMap((Resource)field);
            boolean isSubscription = "services".equals(props.get("acType", (Object)""));
            if (!isSubscription || !props.containsKey((Object)"name") || (subscriptPrms = request.getParameterValues(name = (String)props.get("name", String.class))) == null) continue;
            for (String subscriptPrm : subscriptPrms) {
                if (this.subscriptions.contains(subscriptPrm)) continue;
                this.subscriptions.add(subscriptPrm);
            }
        }
    }

    public Iterator<String> getSubscriptions() {
        return this.subscriptions.iterator();
    }
}