DPSCollectionImpl.java 3.1 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.Page
 *  org.apache.sling.api.resource.ValueMap
 *  org.apache.sling.commons.json.JSONArray
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.dps.impl.metadata;

import com.adobe.cq.mobile.dps.DPSCollection;
import com.adobe.cq.mobile.dps.impl.metadata.AbstractDPSEntityImpl;
import com.adobe.cq.mobile.dps.impl.utils.MetadataJSONUtil;
import com.day.cq.wcm.api.Page;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DPSCollectionImpl
extends AbstractDPSEntityImpl
implements DPSCollection {
    private static final Logger LOGGER = LoggerFactory.getLogger(DPSCollectionImpl.class);

    public DPSCollectionImpl(Page page) {
        super(page);
        if (!this.getDPSResourceType().equals("dps:Collection")) {
            throw new IllegalArgumentException("Underlying page, " + page.getPath() + ", is not a " + "dps:Collection" + ".");
        }
    }

    @Override
    public String getProductId() {
        return (String)this.page.getProperties().get("dps-productId", String.class);
    }

    @Override
    public String getReadingPosition() {
        return (String)this.page.getProperties().get("dps-readingPosition", String.class);
    }

    @Override
    public boolean getEnableHorizontalSwipe() {
        return (Boolean)this.page.getProperties().get("dps-horizontalSwipe", (Object)false);
    }

    @Override
    public boolean getAllowDownload() {
        return (Boolean)this.page.getProperties().get("dps-allowDownload", (Object)false);
    }

    @Override
    public String getOpenDefault() {
        return (String)this.page.getProperties().get("dps-openDefault", String.class);
    }

    @Override
    public String getLayout() {
        return (String)this.page.getProperties().get("dps-layout", String.class);
    }

    @Override
    public String getLayoutTitle() {
        return (String)this.page.getProperties().get("dps-layoutTitle", String.class);
    }

    @Override
    public JSONObject toJSON() throws JSONException {
        return MetadataJSONUtil.getCollectionJSON(this);
    }

    @Override
    public JSONArray getContentLinks() {
        JSONArray links = new JSONArray();
        try {
            String[] jsonStrings = (String[])this.page.getProperties().get("dps-contentLinks", String[].class);
            if (jsonStrings != null) {
                for (String jsonString : jsonStrings) {
                    links.put((Object)new JSONObject(jsonString));
                }
            }
        }
        catch (JSONException ex) {
            LOGGER.error("Failed to load content links for " + this, (Throwable)ex);
        }
        return links;
    }

    @Override
    public String getBackgroundImagePath() {
        return this.getImagePath("./background-image");
    }
}