
com.adobe.granite.ui.components.BulkEditValueMap Maven / Gradle / Ivy
/*************************************************************************
*
* 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.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
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 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, 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 get(key + Field.IS_MIXED_SUFFIX)
.
*/
public class BulkEditValueMap implements ValueMap {
private List resources;
private HashMap cache; // Populated on-demand
public BulkEditValueMap(List resources) {
this.resources = resources;
this.cache = new HashMap();
}
/**
* Retrieves the merged value for the passed key. Calling get(key + Field.IS_MIXED_SUFFIX) returns true if the value
* is mixed; false otherwise. If the value is non-existant 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 Field.IS_MIXED_SUFFIX)
*/
@Override
public Object get(Object key) {
String keyName = (String) key;
MergedValue mergedValue = fetchMergedValue(keyName);
return keyName.endsWith(Field.IS_MIXED_SUFFIX) ? mergedValue.isMixed() : mergedValue.getValue();
}
@Override
@SuppressWarnings("unchecked")
public T get(String name, Class type) {
// takes into consideration Field.IS_MIXED_SUFFIX
Object value = get(name);
return type == null ? (T) value : convert(value, type);
}
@Override
@SuppressWarnings("unchecked")
public T get(String name, T defaultValue) {
// takes into consideration Field.IS_MIXED_SUFFIX
T value = get(name, defaultValue != null ? (Class) defaultValue.getClass() : null);
return value == null ? defaultValue : value;
}
private MergedValue fetchMergedValue(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 {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy