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

com.adobe.granite.ui.components.ValueMapResourceWrapper Maven / Gradle / Ivy

There is a newer version: 6.5.21
Show newest version
/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2015 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.granite.ui.components;

import java.util.HashMap;

import javax.annotation.Nonnull;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceWrapper;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;

/**
 * A resource wrapper that wraps an underlying resource with an empty
 * {@link ValueMap}}, which can be modified accordingly. It is used for the
 * scenario where we want to control the ValueMap returned by a resource.
 */
public class ValueMapResourceWrapper extends ResourceWrapper {

    private ValueMap vm = new ValueMapDecorator(new HashMap());
    private String resourceType;

    /**
     * Instantiates a new wrapper.
     *
     * @param resource
     *            The resource to wrap
     * @param resourceType
     *            The resource type of the resource wrapper
     */
    public ValueMapResourceWrapper(@Nonnull Resource resource, String resourceType) {
        super(resource);
        this.resourceType = resourceType;
        vm.put("sling:resourceType", resourceType);
    }

    @Override
    public String getResourceType() {
        return resourceType;
    }

    @Override
    @SuppressWarnings("unchecked")
    public  AdapterType adaptTo(Class type) {
        if (ValueMap.class.equals(type)) {
            return (AdapterType) vm;
        } else {
            return super.adaptTo(type);
        }
    }

    @Override
    public ValueMap getValueMap() {
        return vm;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy