Item item = session.getItem(Text.getRelativeParent(itemPath, 1));
if (!item.isNode()) {
throw new DiffException("No such node " + itemPath, new ItemNotFoundException(itemPath));
}
Node parent = (Node) item;
String propName = Text.getName(itemPath);
if (JcrConstants.JCR_MIXINTYPES.equals(propName)) {
setMixins(parent, extractValuesFromRequest(targetPath));
} else if (JcrConstants.JCR_PRIMARYTYPE.equals(propName)) {
setPrimaryType(parent, extractValuesFromRequest(targetPath));
} else {
if (diffValue == null || diffValue.length() == 0) {
// single valued property with value present in multipart.
Value[] vs = extractValuesFromRequest(targetPath);
if (vs.length == 0) {
if (parent.hasProperty(propName)) {
// avoid problems with single vs. multi valued props.
parent.getProperty(propName).remove();
} else {
// property does not exist -> stick to rule that missing
// [] indicates single valued.
parent.setProperty(propName, (Value) null);
}
} else if (vs.length == 1) {
parent.setProperty(propName, vs[0]);
} else {
throw new DiffException("Unexpected number of values in multipart. Was " + vs.length + " but expected 1.");
}
} else if (diffValue.startsWith("[") && diffValue.endsWith("]")) {
// multivalued property
if (diffValue.length() == 2) {
// empty array OR values in multipart
Value[] vs = extractValuesFromRequest(targetPath);
parent.setProperty(propName, vs);
} else {
// json array
Value[] vs = extractValues(diffValue);
parent.setProperty(propName, vs);
}
} else {
// single prop value included in the diff
Value v = extractValue(diffValue);
parent.setProperty(propName, v);
}
}
} catch (RepositoryException e) {
throw new DiffException(e.getMessage(), e);
} catch (IOException e) {