use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class VersionControlledItemCollection method merge.
/**
* Merge the repository node represented by this resource according to the
* information present in the given {@link MergeInfo} object.
*
* @param mergeInfo
* @return <code>MultiStatus</code> recording all repository items modified
* by this merge call as well as the resources that a client must modify to
* complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)
* @see Node#merge(String, boolean)
*/
// TODO: with jcr the node must not be versionable in order to perform Node.merge
@Override
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
if (mergeInfo == null) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST);
}
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
MultiStatus ms = new MultiStatus();
try {
// NOTE: RFC requires that all modified resources are reported in the
// multistatus response. this doesn't work however with the remoting
// there is no way to distinguish the 'failedId's from any other
// resources that got modified by this merge operation -> omitted.
// todo: RFC allows multiple href elements inside the DAV:source element
final String href = normalizeResourceHref(mergeInfo.getSourceHrefs()[0]);
String workspaceName = getLocatorFromHref(href).getWorkspaceName();
String depth = DomUtil.getChildTextTrim(mergeInfo.getMergeElement(), DavConstants.XML_DEPTH, DavConstants.NAMESPACE);
boolean isShallow = "0".equals(depth);
NodeIterator failed = getVersionManager().merge(item.getPath(), workspaceName, !mergeInfo.isNoAutoMerge(), isShallow);
// add resources to the multistatus, that failed to be merged
while (failed.hasNext()) {
Node failedNode = failed.nextNode();
DavResourceLocator loc = getLocatorFromItem(failedNode);
DavResource res = createResourceFromLocator(loc);
ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
return ms;
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doMkActivity.
/**
* The MKACTIVITY method
*
* @param request
* @param response
* @param resource
* @throws DavException
* @throws IOException
*/
protected void doMkActivity(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
if (resource.exists()) {
AbstractWebdavServlet.log.warn("Unable to create activity: A resource already exists at the request-URL " + request.getRequestURL());
response.sendError(DavServletResponse.SC_FORBIDDEN);
return;
}
DavResource parentResource = resource.getCollection();
if (parentResource == null || !parentResource.exists() || !parentResource.isCollection()) {
// parent does not exist or is not a collection
response.sendError(DavServletResponse.SC_CONFLICT);
return;
}
// TODO: improve. see http://issues.apache.org/jira/browse/JCR-394
if (!parentResource.getComplianceClass().contains(DavCompliance.ACTIVITY)) {
response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
if (!(resource instanceof ActivityResource)) {
AbstractWebdavServlet.log.error("Unable to create activity: ActivityResource expected");
response.sendError(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// try to add the new activity resource
parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
// Note: mandatory cache control header has already been set upon response creation.
response.setStatus(DavServletResponse.SC_CREATED);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doPut.
/**
* The PUT method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doPut(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
if (request.getHeader("Content-Range") != null) {
response.sendError(DavServletResponse.SC_BAD_REQUEST, "Content-Range in PUT request not supported");
return;
}
DavResource parentResource = resource.getCollection();
if (parentResource == null || !parentResource.exists()) {
// parent does not exist
response.sendError(DavServletResponse.SC_CONFLICT);
return;
}
int status;
// test if resource already exists
if (resource.exists()) {
status = DavServletResponse.SC_NO_CONTENT;
} else {
status = DavServletResponse.SC_CREATED;
}
parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
response.setStatus(status);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doBind.
/**
* The BIND method
*
* @param request
* @param response
* @param resource the collection resource to which a new member will be added
* @throws IOException
* @throws DavException
*/
protected void doBind(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
if (!resource.exists()) {
response.sendError(DavServletResponse.SC_NOT_FOUND);
}
BindInfo bindInfo = request.getBindInfo();
DavResource oldBinding = getResourceFactory().createResource(request.getHrefLocator(bindInfo.getHref()), request, response);
if (!(oldBinding instanceof BindableResource)) {
response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
DavResource newBinding = getResourceFactory().createResource(request.getMemberLocator(bindInfo.getSegment()), request, response);
int status = validateDestination(newBinding, request, false);
if (status > DavServletResponse.SC_NO_CONTENT) {
response.sendError(status);
return;
}
((BindableResource) oldBinding).bind(resource, newBinding);
response.setStatus(status);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doUnbind.
/**
* The UNBIND method
*
* @param request
* @param response
* @param resource the collection resource from which a member will be removed
* @throws IOException
* @throws DavException
*/
protected void doUnbind(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
UnbindInfo unbindInfo = request.getUnbindInfo();
DavResource srcResource = getResourceFactory().createResource(request.getMemberLocator(unbindInfo.getSegment()), request, response);
resource.removeMember(srcResource);
}
Aggregations