* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#update(org.apache.jackrabbit.webdav.version.UpdateInfo)
*/
//TODO: with jcr the node must not be versionable in order to perform Node.update.
public MultiStatus update(UpdateInfo updateInfo) throws DavException {
if (updateInfo == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid update request body required.");
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatus ms = new MultiStatus();
try {
Node node = (Node)item;
Element udElem = updateInfo.getUpdateElement();
boolean removeExisting = DomUtil.hasChildElement(udElem, XML_REMOVEEXISTING, NAMESPACE);
// register eventListener in order to be able to report the modified resources.
EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);
registerEventListener(el, node.getPath());
// perform the update/restore according to the update info
if (updateInfo.getVersionHref() != null) {
VersionHistory vh = node.getVersionHistory();
String[] hrefs = updateInfo.getVersionHref();
Version[] versions = new Version[hrefs.length];
for (int i = 0; i < hrefs.length; i++) {
String itemPath = getLocatorFromHref(hrefs[i]).getRepositoryPath();
versions[i] = vh.getVersion(getItemName(itemPath));
}
if (versions.length == 1) {
String relPath = DomUtil.getChildText(udElem, XML_RELPATH, NAMESPACE);
if (relPath == null) {
node.restore(versions[0], removeExisting);
} else {
node.restore(versions[0], relPath, removeExisting);
}
} else {
getRepositorySession().getWorkspace().restore(versions, removeExisting);
}
} else if (updateInfo.getLabelName() != null) {
String[] labels = updateInfo.getLabelName();
if (labels.length == 1) {
node.restoreByLabel(labels[0], removeExisting);
} else {
Version[] vs = new Version[labels.length];
VersionHistory vh = node.getVersionHistory();
for (int i = 0; i < labels.length; i++) {
vs[i] = vh.getVersionByLabel(labels[i]);
}
getRepositorySession().getWorkspace().restore(vs, removeExisting);
}
} else if (updateInfo.getWorkspaceHref() != null) {
String workspaceName = getLocatorFromHref(updateInfo.getWorkspaceHref()).getWorkspaceName();
node.update(workspaceName);
} else {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body.");
}
// unregister the event listener again
unregisterEventListener(el);