IWebDavClient client = WebDavServerCache.getWebDavClient(props.getRepository());
if (client == null) {
client = WebDavClientFactory.createClient(new URL(props.getRepository()));
WebDavServerCache.cacheWebDavClient(props.getRepository(), client);
}
ResourceProperties remoteProps = null;
try {
remoteProps = client.queryProperties(props.getFullpath());
} catch (WebDavException wde) {
if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
// If not an authentication failure, we don't know what to do with it
throw wde;
}
boolean retry = PlatformUtils.getInstance().
authenticateForServer(props.getRepository(), client);
if (retry) {
remoteProps = client.queryProperties(props.getFullpath());
}
}
if (remoteProps == null) {
throw new Exception("Could not retrieve server version of " + props.getFullpath()); //$NON-NLS-1$
}
// Check to make sure that the version in the repository is the same as the base
// version for the local copy
boolean proceed = true;
if (!props.getRevision().equals(remoteProps.getRevision())) {
String msg = MessageFormat.format(Messages.getString("overwrite.confirmation"), //$NON-NLS-1$
new Object[] { selectedFile.getName(),
remoteProps.getRevision(),
props.getRevision() });
Display display = PlatformUI.getWorkbench().getDisplay();
proceed = MessageDialog.openQuestion(display.getActiveShell(),
Messages.getString("overwrite.confirmation.caption"), msg); //$NON-NLS-1$
}
if (proceed) {
client.putResource(props.getFullpath(), selectedFile.getContents());
GuvnorMetadataUtils.markCurrentGuvnorResource(selectedFile);
ResourceProperties resProps = client.queryProperties(props.getFullpath());
GuvnorMetadataProps mdProps = GuvnorMetadataUtils.getGuvnorMetadata(selectedFile);
mdProps.setVersion(resProps.getLastModifiedDate());
mdProps.setRevision(resProps.getRevision());
GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
}
} catch (Exception e) {
Activator.getDefault().displayError(IStatus.ERROR, e.getMessage(), e, true);
}