use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AclPrincipalReport method init.
/**
* @see Report#init(DavResource, ReportInfo)
*/
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
super.init(resource, info);
// build the DAV:responses objects.
DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL);
if (!(acl instanceof AclProperty)) {
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected.");
}
DavResourceLocator loc = resource.getLocator();
Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>();
List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty) acl).getValue();
for (AclProperty.Ace ace : list) {
String href = ace.getPrincipal().getHref();
if (href == null || respMap.containsKey(href)) {
// ignore non-href principals and principals that have been listed before
continue;
}
// href-principal that has not been found before
DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href);
DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession());
respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet()));
}
this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]);
}
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);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class CompareBaselineReport method init.
/**
*
* @param resource
* @param info
* @throws DavException
* @see Report#init(DavResource, ReportInfo)
*/
public void init(DavResource resource, ReportInfo info) throws DavException {
// validate info
if (!getType().isRequestedReportType(info)) {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:compare-baseline element expected.");
}
// make sure the report is applied to a version history resource
if (resource != null && (resource instanceof BaselineResource)) {
this.requestBaseline = (BaselineResource) resource;
} else {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:compare-baseline report can only be created for a baseline resource.");
}
// make sure the DAV:href element inside the request body points to
// an baseline resource (precondition for this report).
String compareHref = DomUtil.getText(info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE));
DavResourceLocator locator = resource.getLocator();
DavResourceLocator compareLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), compareHref);
DavResource compRes = resource.getFactory().createResource(compareLocator, resource.getSession());
if (compRes instanceof BaselineResource) {
compareBaseline = (BaselineResource) compRes;
} else {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version report: The DAV:href in the request body MUST identify an activity.");
}
// TODO: eventually add check for 'same-baseline-history' (RFC: "A server MAY require that the baselines being compared be from the same baseline history.")
}
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 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 {
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);
}
Aggregations