EmulatorInfoProvider.java 3.85 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.PageInfoProvider
 *  org.apache.commons.lang.StringUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.emulator.impl;

import com.day.cq.wcm.api.PageInfoProvider;
import com.day.cq.wcm.emulator.Emulator;
import com.day.cq.wcm.emulator.EmulatorGroup;
import com.day.cq.wcm.emulator.EmulatorService;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service(value={PageInfoProvider.class})
public class EmulatorInfoProvider
implements PageInfoProvider {
    private static final Logger log = LoggerFactory.getLogger(EmulatorInfoProvider.class);
    @Reference
    private EmulatorService emulatorService;

    public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
        JSONObject entries = new JSONObject();
        List<EmulatorGroup> emulatorGroups = this.emulatorService.getEmulatorGroups(resource);
        if (!emulatorGroups.isEmpty()) {
            JSONObject groups = new JSONObject();
            for (EmulatorGroup emulatorGroup : emulatorGroups) {
                String path = emulatorGroup.getPath();
                JSONObject group = new JSONObject();
                group.put("title", (Object)emulatorGroup.getTitle());
                group.put("description", (Object)emulatorGroup.getDescription());
                group.put("path", (Object)(StringUtils.isNotBlank((String)path) ? path : JSONObject.NULL));
                for (Emulator emulator : emulatorGroup.getEmulators()) {
                    if (null == emulator) continue;
                    JSONObject entry = new JSONObject();
                    entry.put("text", (Object)emulator.getTitle());
                    String desc = emulator.getDescription();
                    if (desc != null) {
                        entry.put("description", (Object)desc);
                    }
                    entry.put("action", (Object)"start");
                    entry.put("path", (Object)emulator.getPath());
                    entry.put("canRotate", emulator.canRotate());
                    entry.put("hasTouchScrolling", emulator.hasTouchScrolling());
                    entry.put("contentCssPath", (Object)(request.getContextPath() + emulator.getContentCssPath()));
                    entry.put("width", emulator.getWidth());
                    entry.put("height", emulator.getHeight());
                    entry.put("device-pixel-ratio", emulator.getPixelRatio());
                    group.put(emulator.getName(), (Object)entry);
                    groups.put(emulatorGroup.getName(), (Object)group);
                }
                entries.put("groups", (Object)groups);
            }
        }
        info.put("emulators", (Object)entries);
    }

    protected void bindEmulatorService(EmulatorService emulatorService) {
        this.emulatorService = emulatorService;
    }

    protected void unbindEmulatorService(EmulatorService emulatorService) {
        if (this.emulatorService == emulatorService) {
            this.emulatorService = null;
        }
    }
}