in src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java [221:291]
private void processMovesCopiesInternal(
RequestProperty property,
boolean isMove,
final ResourceResolver resolver,
Map<String, RequestProperty> reqProperties,
List<Modification> changes,
VersioningConfiguration versioningConfiguration)
throws PersistenceException {
String propPath = property.getPath();
String source = property.getRepositorySource();
// only continue here, if the source really exists
if (resolver.getResource(source) != null) {
// if the destination item already exists, remove it
// first, otherwise ensure the parent location
if (resolver.getResource(propPath) != null) {
final Resource parent = resolver.getResource(propPath).getParent();
this.jcrSupport.checkoutIfNecessary(parent, changes, versioningConfiguration);
resolver.delete(resolver.getResource(propPath));
changes.add(Modification.onDeleted(propPath));
} else {
Resource parent = deepGetOrCreateResource(
resolver, property.getParentPath(), reqProperties, changes, versioningConfiguration);
this.jcrSupport.checkoutIfNecessary(parent, changes, versioningConfiguration);
}
// move through the session and record operation
// check if the item is backed by JCR
Resource sourceRsrc = resolver.getResource(source);
final Object sourceItem = this.jcrSupport.getItem(sourceRsrc);
final Object destItem = this.jcrSupport.getItem(resolver.getResource(property.getParentPath()));
if (sourceItem != null && destItem != null) {
if (this.jcrSupport.isNode(sourceRsrc)) {
if (isMove) {
this.jcrSupport.checkoutIfNecessary(sourceRsrc.getParent(), changes, versioningConfiguration);
this.jcrSupport.move(sourceItem, destItem, ResourceUtil.getName(propPath));
} else {
this.jcrSupport.checkoutIfNecessary(
resolver.getResource(property.getParentPath()), changes, versioningConfiguration);
this.jcrSupport.copy(sourceItem, destItem, property.getName());
}
} else {
// property: move manually
this.jcrSupport.checkoutIfNecessary(
resolver.getResource(property.getParentPath()), changes, versioningConfiguration);
// create destination property
this.jcrSupport.copy(sourceItem, destItem, ResourceUtil.getName(source));
// remove source property (if not just copying)
if (isMove) {
this.jcrSupport.checkoutIfNecessary(sourceRsrc.getParent(), changes, versioningConfiguration);
resolver.delete(sourceRsrc);
}
}
}
// make sure the property is not deleted even in case for a given
// property both @MoveFrom and @Delete is set
property.setDelete(false);
// record successful move
if (isMove) {
changes.add(Modification.onMoved(source, propPath));
} else {
changes.add(Modification.onCopied(source, propPath));
}
}
}