Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2015 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
**************************************************************************/
package com.adobe.granite.ui.components;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import com.adobe.granite.ui.components.impl.ValueMapValueFetchStrategy;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.jackrabbit.util.ISO8601;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
/**
* BulkEditValueMap is a ValueMap specific to the needs of Bulk Editing. It is
* aimed at merging the given Resources' ValueMaps.
*
*
* Please not that the merge is actually "virtual" since under the hood the
* ValueMap will always be empty. In other words, {@link #get(Object key)}
* performs an on-demand merge for the passed key.
*
*
* In addition to providing the actual (merged) value for a given key, this
* specific ValueMap can also tell if a given key has a mixed value using
* {@code #get(key + Field.IS_MIXED_SUFFIX)}.
*/
public class BulkEditValueMap implements ValueMap {
private List resources;
private Map cache;
private Map fetchStrategies;
public BulkEditValueMap(@Nonnull List resources) {
this(resources, Collections.emptyMap());
}
public BulkEditValueMap(@Nonnull List resources,
@Nonnull Map fetchStrategies) {
this.resources = resources;
this.cache = new HashMap();
this.fetchStrategies = fetchStrategies;
}
/**
* Retrieves the merged value for the passed key. Calling {@code #get(key +
* Field.IS_MIXED_SUFFIX)} returns {@code true} if the value is mixed;
* {@code false} otherwise. If the value is non-existent {@code null} is
* returned.
*
* @param key
* The key of the value to retrieve.
* @return The merged value for the passed key; or a boolean telling if the
* value is mixed or not (if the key ends with
* {@link Field#IS_MIXED_SUFFIX}).
*/
@Override
public Object get(Object key) {
String keyName = (String) key;
@SuppressWarnings("null")
MergedValue mergedValue = fetchMergedValue(keyName);
return keyName.endsWith(Field.IS_MIXED_SUFFIX) ? mergedValue.isMixed() : mergedValue.getValue();
}
@SuppressWarnings("unchecked")
@Override
public T get(@Nonnull String name, @Nonnull Class type) {
// takes into consideration Field.IS_MIXED_SUFFIX
Object value = get(name);
return type == null ? (T) value : convert(value, type);
}
@Override
@Nonnull
public T get(@Nonnull String name, @Nonnull T defaultValue) {
// takes into consideration Field.IS_MIXED_SUFFIX
@SuppressWarnings("unchecked")
T value = get(name, defaultValue != null ? (Class) defaultValue.getClass() : null);
return value == null ? defaultValue : value;
}
@SuppressWarnings("null")
@Nonnull
private MergedValue fetchMergedValue(@Nonnull String key) {
MergedValue mergedValue;
// Keys are stored without prefix, so we need to clean it first
if (key.endsWith(Field.IS_MIXED_SUFFIX)) {
key = key.replace(Field.IS_MIXED_SUFFIX, "");
}
// Check cache first
if (this.cache.containsKey(key)) {
mergedValue = this.cache.get(key);
} else {
ValueFetchStrategy strategy = fetchStrategies.containsKey(key) ? fetchStrategies.get(key)
: new ValueMapValueFetchStrategy();
List