in src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java [618:671]
protected Set<LocalRestriction> toLocalRestrictions(JsonObject allowOrDenyObj,
Map<String, RestrictionDefinition> srMap,
ValueFactory vf) throws RepositoryException {
Set<LocalRestriction> restrictions = new HashSet<>();
for (Entry<String, JsonValue> restrictionEntry : allowOrDenyObj.entrySet()) {
String restrictionName = restrictionEntry.getKey();
RestrictionDefinition rd = srMap.get(restrictionName);
if (rd == null) {
// illegal restriction name?
throw new JsonException("Invalid or not supported restriction name was supplied: " + restrictionName);
}
boolean multival = rd.getRequiredType().isArray();
int restrictionType = rd.getRequiredType().tag();
LocalRestriction lr = null;
JsonValue jsonValue = restrictionEntry.getValue();
if (multival) {
if (jsonValue.getValueType() == ValueType.ARRAY) {
JsonArray jsonArray = (JsonArray) jsonValue;
int size = jsonArray.size();
Value[] values = new Value[size];
for (int i = 0; i < size; i++) {
values[i] = toValue(vf, jsonArray.get(i), restrictionType);
}
lr = new LocalRestriction(restrictionName, values);
} else {
Value v = toValue(vf, jsonValue, restrictionType);
lr = new LocalRestriction(restrictionName, new Value[] { v });
}
} else {
if (jsonValue.getValueType() == ValueType.ARRAY) {
JsonArray jsonArray = (JsonArray) jsonValue;
int size = jsonArray.size();
if (size == 1) {
Value v = toValue(vf, jsonArray.get(0), restrictionType);
lr = new LocalRestriction(restrictionName, v);
} else if (size > 1) {
throw new JsonException(
"Unexpected multi value array data found for single-value restriction value for name: "
+ restrictionName);
}
} else {
Value v = toValue(vf, jsonValue, restrictionType);
lr = new LocalRestriction(restrictionName, v);
}
}
if (lr != null) {
restrictions.add(lr);
}
}
return restrictions;
}