in vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty2.java [536:595]
public boolean apply(@NotNull Node node) throws RepositoryException {
String qualifiedName = getQualifiedName(node.getSession(), name);
Property prop = node.hasProperty(qualifiedName) ? node.getProperty(qualifiedName) : null;
// check if multiple flags are equal
if (prop != null && isMultiValue != prop.getDefinition().isMultiple()) {
prop.remove();
prop = null;
}
if (prop != null) {
int propType = prop.getType();
if (propType != type && (propType != PropertyType.STRING || type != PropertyType.UNDEFINED)) {
// never compare if types differ
prop = null;
}
}
if (isMultiValue) {
Value[] vs = prop == null ? null : prop.getValues();
if (type == PropertyType.BINARY) {
return applyBinary(node, vs);
}
if (vs != null && vs.length == values.size()) {
// quick check all values
boolean modified = false;
for (int i=0; i<vs.length; i++) {
if (!vs[i].getString().equals(values.get(i))) {
modified = true;
}
}
if (!modified) {
return false;
}
}
if (type == PropertyType.UNDEFINED) {
node.setProperty(qualifiedName, values.toArray(new String[0]));
} else {
node.setProperty(qualifiedName, values.toArray(new String[0]), type);
}
// assume modified
return true;
} else {
Value v = prop == null ? null : prop.getValue();
if (type == PropertyType.BINARY) {
return applyBinary(node, v);
}
if (v == null || !v.getString().equals(values.get(0))) {
try {
if (type == PropertyType.UNDEFINED) {
node.setProperty(qualifiedName, values.get(0));
} else {
node.setProperty(qualifiedName, values.get(0), type);
}
} catch (ValueFormatException e) {
// forcing string
node.setProperty(qualifiedName, values.get(0), PropertyType.STRING);
}
return true;
}
}
return false;
}