catch( Exception x ) {};
}
if( sendError ) {
int statusCode = WebdavStatus.SC_FORBIDDEN;
sendError( statusCode, getClass().getName()+".restrictedDestinationUri", new Object[]{resourcePath} );
throw new WebdavException( statusCode );
}
}
try {
// fire put event
if ( WebdavEvent.PUT.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.PUT, new WebdavEvent(this));
try {
boolean isLockedNullResource = false;
NodeRevisionDescriptors revisionDescriptors =
content.retrieve(slideToken, resourcePath);
NodeRevisionNumber revisionNumber =
revisionDescriptors.getLatestRevision();
NodeRevisionDescriptor oldRevisionDescriptor = null;
if (revisionNumber != null) {
try {
oldRevisionDescriptor = content.retrieve
(slideToken, revisionDescriptors);
} catch (RevisionDescriptorNotFoundException e) {
}
}
if (WebdavUtils.isCollection(oldRevisionDescriptor)) {
int statusCode = WebdavStatus.SC_METHOD_NOT_ALLOWED;
sendError( statusCode, getClass().getName()+".mustNotBeCollection" );
throw new WebdavException( statusCode );
}
NodeRevisionDescriptor revisionDescriptor = null;
if (oldRevisionDescriptor == null) {
revisionDescriptor = new NodeRevisionDescriptor();
} else {
revisionDescriptor = oldRevisionDescriptor;
revisionDescriptor.setContentLength(-1);
}
ResourceInfo resourceInfo =
new ResourceInfo(resourcePath, revisionDescriptor);
// Checking If headers
if (!checkIfHeaders(req, resp, resourceInfo)) {
return;
}
ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, resourcePath, revisionDescriptor);
versioningHelper.isWriteLocked(slideToken, revisionDescriptors);
// check preconditions
ViolatedPrecondition violatedPrecondition = getPreconditionViolation(revisionDescriptors, revisionDescriptor, resourceKind);
if (violatedPrecondition != null) {
throw new PreconditionViolationException(violatedPrecondition, resourcePath);
}
// Changed for DeltaV --start--
boolean mustCheckIn = false;
if( Configuration.useVersionControl() &&
(resourceKind instanceof CheckedInVersionControlled) &&
versioningHelper.mustCheckoutAutoVersionedVCR(revisionDescriptors, revisionDescriptor) ) {
versioningHelper.checkout(revisionDescriptors, revisionDescriptor, false, false, true );
mustCheckIn = versioningHelper.mustCheckinAutoVersionedVCR(slideToken, revisionDescriptors, revisionDescriptor);
}
// Changed for DeltaV --end--
NodeRevisionContent revisionContent =
new NodeRevisionContent();
//revisionContent.setContent(req.getReader());
revisionContent.setContent(req.getInputStream());
// Get content length
int contentLength = req.getContentLength();
if (contentLength == (-1)) {
contentLength = revisionContent.getContentBytes().length;
}
revisionDescriptor.setContentLength(contentLength);
// Last modification date
revisionDescriptor.setLastModified(new Date());
// Etag generation
revisionDescriptor.setETag(PropertyHelper.computeEtag(resourcePath, revisionDescriptor) );
// Get content type (allow content-type to be updated here)
String contentType = req.getContentType();
if (contentType == null) {
contentType = getConfig().getServletContext()
.getMimeType(resourcePath);
}
if (contentType == null) {
contentType = getConfig().getDefaultMimeType();
}
revisionDescriptor.setContentType(contentType);
// Normally assume the 'getcontentlanguage'
// is set, however, before we clear the
// 'resourcetype' need to check for the case when a
// 'lock-null' is created just before the initial PUT. In
// that case need to add the missing properties.
if (isLockNull(revisionDescriptor)) {
// if (revisionDescriptor.getResourceType().equals("<lock-null/>")) {
isLockedNullResource = true;
revisionDescriptor.setContentLanguage("en");
// Changed for DeltaV --start--
if( Configuration.useVersionControl() ) {
// Workspace
versioningHelper.setWorkspaceProperty( resourcePath, revisionDescriptor );
}
// Changed for DeltaV --end--
}
// Resource type
revisionDescriptor.setResourceType("");
// Owner
if ( isLockedNullResource ) {
// set the owner when updating a lock-null resource
String creator = ((SubjectNode)security.getPrincipal(slideToken)).getPath().lastSegment();
revisionDescriptor.setCreationUser(creator);
revisionDescriptor.setOwner(creator);
}
content.store(slideToken, resourcePath, revisionDescriptor,
revisionContent);
// Changed for DeltaV --start--
// check if the resource should be put under version-control
if ( isLockedNullResource ) {
if ( Configuration.useVersionControl() && isAutoVersionControl(resourcePath) && !isExcludedForVersionControl(resourcePath) ) {
versioningHelper.versionControl(resourcePath);
}
}
if( Configuration.useVersionControl() && mustCheckIn) {
versioningHelper.checkin(revisionDescriptors, revisionDescriptor, false, false, true ); //forkOk=false, keepCheckedOut=false
}
// Changed for DeltaV --end--
// ETag header
resp.setHeader("ETag", revisionDescriptor.getETag() );
resp.setStatus(WebdavStatus.SC_NO_CONTENT);
} catch (LinkedObjectNotFoundException e) {
int statusCode = getErrorCode( e );
sendError( statusCode, e );
throw new WebdavException( statusCode );
} catch (ObjectNotFoundException e) {
SubjectNode subject = new SubjectNode();
// Creating an object
structure.create(slideToken, subject, resourcePath);
NodeRevisionDescriptor revisionDescriptor =
new NodeRevisionDescriptor(req.getContentLength());
ResourceInfo resourceInfo =
new ResourceInfo(resourcePath, revisionDescriptor);
resourceInfo.exists = false;
// Checking If headers
if (!checkIfHeaders(req, resp, resourceInfo)) {
int statusCode = WebdavStatus.SC_PRECONDITION_FAILED;
sendError( statusCode, "Check If Header failed" );
throw new WebdavException( statusCode );
}
//NodeProperty property = null;
// Creation date
// Resource type
revisionDescriptor.setResourceType("");
// Source
revisionDescriptor.setSource("");
// Get content language
revisionDescriptor.setContentLanguage("en");
// Get content type
String contentType = req.getContentType();
if (contentType == null) {
contentType = getConfig().getServletContext()
.getMimeType(resourcePath);
}
if (contentType == null) {
contentType = getConfig().getDefaultMimeType();
}
revisionDescriptor.setContentType(contentType);
// Last modification date
revisionDescriptor.setLastModified(new Date());
// Etag generation
revisionDescriptor.setETag(PropertyHelper.computeEtag(resourcePath, revisionDescriptor));
// Creation date
revisionDescriptor.setCreationDate(new Date());
// Owner
String creator = ((SubjectNode)security.getPrincipal(slideToken)).getPath().lastSegment();
revisionDescriptor.setCreationUser(creator);
revisionDescriptor.setOwner(creator);
// Added for DeltaV --start--
if( Configuration.useVersionControl() ) {
// Workspace
versioningHelper.setWorkspaceProperty( resourcePath, revisionDescriptor );
}
// Added for DeltaV --end--
if (isMsProprietarySupport()) {
NodeProperty property = null;
// Is hidden
property = new NodeProperty("ishidden", "0", "MICROSOFT");
revisionDescriptor.setProperty(property);
// Is collection
property = new NodeProperty("iscollection", "0",
"MICROSOFT");
revisionDescriptor.setProperty(property);
// Is read only
property = new NodeProperty("isreadonly", "0",
"MICROSOFT");
revisionDescriptor.setProperty(property);
// Last accessed
property = new NodeProperty("lastaccessed",
(new Date()).toString(),
"MICROSOFT");
revisionDescriptor.setProperty(property);
}
// Creating revisionDescriptor associated with the object
NodeRevisionContent revisionContent =
new NodeRevisionContent();
revisionContent.setContent(req.getInputStream());
// Get content length
int contentLength = req.getContentLength();
if (contentLength == -1) {
contentLength = revisionContent.getContentBytes().length;
}
revisionDescriptor.setContentLength(contentLength);
content.create(slideToken, resourcePath, revisionDescriptor,
revisionContent);
// check if the resource should be put under version-control
if ( Configuration.useVersionControl() && isAutoVersionControl(resourcePath) && !isExcludedForVersionControl(resourcePath) ) {
versioningHelper.versionControl(resourcePath);
}
// ETag header
resp.setHeader("ETag", revisionDescriptor.getETag() );
resp.setStatus(WebdavStatus.SC_CREATED);
}
}
catch (PreconditionViolationException e) {
sendPreconditionViolation(e);
throw e;
}
catch (SlideException e) {
int statusCode = getErrorCode( e );
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
catch (Exception e) {
int statusCode = getErrorCode( e );
sendError( statusCode, e );
throw new WebdavException( statusCode );
}
}