All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.cq.screens.impl.aemio.ScreensModelLookup Maven / Gradle / Ivy

There is a newer version: 6.5.21
Show newest version
/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2016 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 ************************************************************************/
package com.adobe.cq.screens.impl.aemio;

import org.apache.sling.api.resource.Resource;

import com.adobe.cq.screens.assignment.AssignmentService;
import com.adobe.cq.screens.binding.ScreensConstants;
import com.adobe.cq.screens.impl.util.DeviceUtils;
import com.adobe.granite.haf.api.ModelLookup;
import com.day.cq.wcm.api.NameConstants;

public class ScreensModelLookup implements ModelLookup {

    public static final String CATEGORY = "screens";
    public static final String CONTENT_ROOT = "/content/screens";

    public Class getModel(Resource resource) {

        if (resource != null) {

            if (resource.isResourceType("sling:OrderedFolder")) {
                return ScreensRootModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_PROJECT)) {
                return ScreensProjectModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_APPLICATION_FOLDER)) {
                return ScreensApplicationsFolderModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_APPLICATION)) {
                return ScreensApplicationModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_CHANNEL_FOLDER)) {
                return ScreensChannelsFolderModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_CHANNEL)) {
                return ScreensChannelModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_LOCATION_FOLDER)) {
                return ScreensLocationsFolderModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_LOCATION)) {
                return ScreensLocationModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_DISPLAY)) {
                return ScreensDisplayModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_SCHEDULE_FOLDER)) {
                return ScreensSchedulesFolderModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_SCHEDULE)) {
                return ScreensScheduleModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_SCREEN)) {
                return ScreensScreenModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_DEVICE_CONFIG)) {
                return ScreensDeviceConfigModel.class;
            }

            if (isPageContentResourceType(resource, ScreensConstants.RT_DEVICE_FOLDER)) {
                return ScreensDevicesFolderModel.class;
            }

            final Resource profileResource = resource.getChild("profile_screens");
            if (profileResource != null && profileResource.isResourceType(ScreensConstants.RT_DEVICE)) {
                return ScreensDeviceModel.class;
            }

            AssignmentService assignmentSvc = resource.getResourceResolver().adaptTo(AssignmentService.class);
            if (assignmentSvc != null && assignmentSvc.isAssignment(resource)) {
                return ScreensAssignmentModel.class;
            }

            if (resource.isResourceType("nt:unstructured")) {
                Resource p = resource.getParent();
                Resource pp = p == null ? null : p.getParent();
                if (pp != null && pp.isResourceType(ScreensConstants.RT_DISPLAY)) {
                    return ScreensAssignmentModel.class;
                }
            }
        }

        return null;
    }

    private boolean isPageContentResourceType(Resource resource, String resourceType) {
        if (resource != null) {
            Resource jcrContent = resource.getChild(NameConstants.NN_CONTENT);
            if (jcrContent != null && resourceType != null) {
                return jcrContent.isResourceType(resourceType);
            }
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy