MetaDataNodeImpl.java 2.09 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 */
package com.adobe.cq.mcm.campaign.profile.impl;

import com.adobe.cq.mcm.campaign.profile.MetaDataNode;
import com.adobe.cq.mcm.campaign.profile.OptionValue;
import com.adobe.cq.mcm.campaign.profile.Options;
import com.adobe.cq.mcm.campaign.profile.impl.AbstractMetaDataNode;
import com.adobe.cq.mcm.campaign.profile.impl.OptionValueImpl;
import com.adobe.cq.mcm.campaign.profile.impl.OptionsImpl;
import java.util.Iterator;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;

public class MetaDataNodeImpl
extends AbstractMetaDataNode {
    public MetaDataNodeImpl(JSONObject json, String key, MetaDataNode parent) {
        super(key, parent.getPath(), MetaDataNodeImpl.getStringSafe(json, "label"), MetaDataNodeImpl.getStringSafe(json, "type"), MetaDataNodeImpl.getOptions(json));
    }

    private static String getStringSafe(JSONObject obj, String key) {
        String str = null;
        try {
            str = obj.getString(key);
        }
        catch (JSONException je) {
            // empty catch block
        }
        return str;
    }

    private static Options getOptions(JSONObject obj) {
        OptionsImpl options = null;
        try {
            if (obj.has("values")) {
                options = new OptionsImpl();
                JSONObject optionValues = obj.getJSONObject("values");
                Iterator optionKeys = optionValues.keys();
                while (optionKeys.hasNext()) {
                    String optionKey = (String)optionKeys.next();
                    JSONObject option = optionValues.getJSONObject(optionKey);
                    String name = option.getString("name");
                    String label = option.getString("label");
                    options.addValue(new OptionValueImpl(optionKey, name, label));
                }
            }
        }
        catch (JSONException je) {
            options = null;
        }
        return options;
    }
}