}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatusResponse msr = new MultiStatusResponse(getHref(), null);
boolean success = true;
// loop over set and remove Sets and remember all properties and propertyNames
// that have successfully been altered
List successList = new ArrayList();
DavPropertyIterator setIter = setProperties.iterator();
while (setIter.hasNext()) {
DavProperty prop = setIter.nextProperty();
try {
setJcrProperty(prop);
successList.add(prop);
} catch (RepositoryException e) {
msr.add(prop.getName(), new JcrDavException(e).getErrorCode());
success = false;
}
}
Iterator remNameIter = removePropertyNames.iterator();
while (remNameIter.hasNext()) {
DavPropertyName propName = (DavPropertyName) remNameIter.next();
try {
removeJcrProperty(propName);
successList.add(propName);
} catch (RepositoryException e) {
msr.add(propName, new JcrDavException(e).getErrorCode());
success = false;
}
}
try {
if (success) {
// save all changes together (reverted in case this fails)
node.save();
} else {
// set/remove of at least a single prop failed: undo modifications.
node.refresh(false);
}
/* loop over list of properties/names that were successfully altered
and them to the multistatus response respecting the resulte of the
complete action. in case of failure set the status to 'failed-dependency'
in order to indicate, that altering those names/properties would
have succeeded, if no other error occured.*/
Iterator it = successList.iterator();
while (it.hasNext()) {
Object o = it.next();
int status = (success) ? DavServletResponse.SC_OK : DavServletResponse.SC_FAILED_DEPENDENCY;
if (o instanceof DavProperty) {
msr.add(((DavProperty) o).getName(), status);
} else {
msr.add((DavPropertyName) o, status);
}
}
return msr;
} catch (RepositoryException e) {
// revert any changes made so far an throw exception