use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class AbstractItemResource method getCollection.
/**
* Returns the resource representing the parent item of the repository item
* represented by this resource. If this resoure represents the root item
* a {@link RootCollection} is returned.
*
* @return the collection this resource is internal member of. Except for the
* repository root, the returned collection always represent the parent
* repository node.
* @see org.apache.jackrabbit.webdav.DavResource#getCollection()
*/
@Override
public DavResource getCollection() {
DavResource collection = null;
String parentPath = Text.getRelativeParent(getResourcePath(), 1);
DavResourceLocator parentLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), getLocator().getWorkspacePath(), parentPath);
try {
collection = createResourceFromLocator(parentLoc);
} catch (DavException e) {
log.error("Unexpected error while retrieving collection: " + e.getMessage());
}
return collection;
}
use of org.apache.jackrabbit.webdav.DavResourceLocator in project jackrabbit by apache.
the class JcrRemotingServlet method canHandle.
private boolean canHandle(int methodCode, WebdavRequest request, DavResource davResource) {
DavResourceLocator locator = davResource.getLocator();
switch(methodCode) {
case DavMethods.DAV_GET:
return davResource.exists() && (locator instanceof WrappingLocator) && ((WrappingLocator) locator).isJsonRequest;
case DavMethods.DAV_POST:
String ct = request.getContentType();
if (ct == null) {
return false;
} else {
int semicolon = ct.indexOf(';');
if (semicolon >= 0) {
ct = ct.substring(0, semicolon);
}
ct = ct.trim().toLowerCase(Locale.ENGLISH);
return "multipart/form-data".equals(ct) || "application/x-www-form-urlencoded".equals(ct);
}
default:
return false;
}
}
use of org.apache.jackrabbit.webdav.DavResourceLocator 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.DavResourceLocator 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.")
}
Aggregations