in commons-vfs2-jackrabbit1/src/main/java/org/apache/commons/vfs2/provider/webdav/WebdavFileObject.java [111:195]
protected void onClose() throws IOException {
final RequestEntity entity = new ByteArrayRequestEntity(((ByteArrayOutputStream) out).toByteArray());
final URLFileName fileName = (URLFileName) getName();
final String urlStr = toUrlString(fileName);
if (builder.isVersioning(getFileSystem().getFileSystemOptions())) {
DavPropertySet set = null;
boolean fileExists = true;
boolean isCheckedIn = true;
try {
set = getPropertyNames(fileName);
} catch (final FileNotFoundException fnfe) {
fileExists = false;
}
if (fileExists && set != null) {
if (set.contains(VersionControlledResource.CHECKED_OUT)) {
isCheckedIn = false;
} else if (!set.contains(VersionControlledResource.CHECKED_IN)) {
DavProperty prop = set.get(VersionControlledResource.AUTO_VERSION);
if (prop != null) {
prop = getProperty(fileName, VersionControlledResource.AUTO_VERSION);
if (DeltaVConstants.XML_CHECKOUT_CHECKIN.equals(prop.getValue())) {
createVersion(urlStr);
}
}
}
}
if (fileExists && isCheckedIn) {
try {
final CheckoutMethod checkout = new CheckoutMethod(urlStr);
setupMethod(checkout);
execute(checkout);
isCheckedIn = false;
} catch (final FileSystemException ex) {
log(ex);
}
}
try {
final PutMethod method = new PutMethod(urlStr);
method.setRequestEntity(entity);
setupMethod(method);
execute(method);
setUserName(fileName, urlStr);
} catch (final FileSystemException ex) {
if (!isCheckedIn) {
try {
final UncheckoutMethod method = new UncheckoutMethod(urlStr);
setupMethod(method);
execute(method);
isCheckedIn = true;
} catch (final Exception e) {
// Going to throw original.
log(e);
}
throw ex;
}
}
if (!fileExists) {
createVersion(urlStr);
try {
final DavPropertySet props = getPropertyNames(fileName);
isCheckedIn = !props.contains(VersionControlledResource.CHECKED_OUT);
} catch (final FileNotFoundException fnfe) {
log(fnfe);
}
}
if (!isCheckedIn) {
final CheckinMethod checkin = new CheckinMethod(urlStr);
setupMethod(checkin);
execute(checkin);
}
} else {
final PutMethod method = new PutMethod(urlStr);
method.setRequestEntity(entity);
setupMethod(method);
execute(method);
try {
setUserName(fileName, urlStr);
} catch (final IOException e) {
// Unable to set the user name.
log(e);
}
}
((DefaultFileContent) this.file.getContent()).resetAttributes();
}