use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class ExpandPropertyReport method getResponse.
/**
* Builds a <code>MultiStatusResponse</code> for the given resource respecting
* the properties specified. Any property that represents a {@link HrefProperty}
* is expanded: It's name equals the name of a valid {@link HrefProperty}.
* However the value of that given property (consisting of one or multiple DAV:href elements)
* is replaced by the Xml representation of a separate
* {@link MultiStatusResponse multistatus responses} for the
* resource referenced by the given DAV:href elements. The responses may
* themselves have properties, which are defined by the separate list.
*
* @param res
* @param propertyElements
* @return <code>MultiStatusResponse</code> for the given resource.
* @see ExpandProperty
*/
private MultiStatusResponse getResponse(DavResource res, Iterator<Element> propertyElements) {
MultiStatusResponse resp = new MultiStatusResponse(res.getHref(), null);
while (propertyElements.hasNext()) {
Element propertyElem = propertyElements.next();
// retrieve the localName present in the "name" attribute
String nameAttr = propertyElem.getAttribute(ATTR_NAME);
if (nameAttr == null || "".equals(nameAttr)) {
// NOTE: this is not valid according to the DTD
continue;
}
// retrieve the namespace present in the "namespace" attribute
// NOTE: if this attribute is missing the DAV: namespace represents the default.
String namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE);
Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr) : NAMESPACE;
DavPropertyName propName = DavPropertyName.create(nameAttr, namespace);
DavProperty<?> p = res.getProperty(propName);
if (p != null) {
if (p instanceof HrefProperty && res instanceof DeltaVResource) {
ElementIterator it = DomUtil.getChildren(propertyElem, XML_PROPERTY, NAMESPACE);
resp.add(new ExpandProperty((DeltaVResource) res, (HrefProperty) p, it));
} else {
resp.add(p);
}
} else {
resp.add(propName, DavServletResponse.SC_NOT_FOUND);
}
}
return resp;
}
use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.
private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new PathNotFoundException("Unable to retrieve privileges definitions.");
}
DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
if (p == null) {
return new PrivilegeDefinition[0];
} else {
// build PrivilegeDefinition(s) from the supported-privileges dav property
Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
for (Name privilegeName : spMap.keySet()) {
SupportedPrivilege sp = spMap.get(privilegeName);
Set<Name> aggrnames = null;
SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
if (aggregates != null && aggregates.length > 0) {
aggrnames = new HashSet<Name>();
for (SupportedPrivilege aggregate : aggregates) {
Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
aggrnames.add(aggregateName);
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
pDefs.add(def);
}
return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class RepositoryServiceImpl method getChildInfos.
@Override
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException {
// set of properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(DavPropertyName.RESOURCETYPE);
HttpPropfind request = null;
try {
String uri = getItemUri(parentId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_1);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
List<ChildInfo> childEntries;
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(parentId, sessionInfo));
} else if (mresponses.length == 1) {
// no child nodes nor properties
childEntries = Collections.emptyList();
return childEntries.iterator();
}
childEntries = new ArrayList<ChildInfo>();
for (MultiStatusResponse mresponse : mresponses) {
if (!isSameResource(uri, mresponse)) {
DavPropertySet childProps = mresponse.getProperties(DavServletResponse.SC_OK);
if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
childEntries.add(buildChildInfo(childProps, sessionInfo));
}
// else: property -> ignore
}
// else: ignore the response related to the parent
}
return childEntries.iterator();
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class RepositoryServiceImpl method merge.
@Override
public Iterator<NodeId> merge(SessionInfo sessionInfo, NodeId nodeId, String srcWorkspaceName, boolean bestEffort, boolean isShallow) throws RepositoryException {
HttpMerge request = null;
try {
Document doc = DomUtil.createDocument();
String wspHref = obtainAbsolutePathFromUri(uriResolver.getWorkspaceUri(srcWorkspaceName));
Element mElem = MergeInfo.createMergeElement(new String[] { wspHref }, !bestEffort, false, doc);
if (isShallow) {
mElem.appendChild(DomUtil.depthToXml(false, doc));
}
MergeInfo mInfo = new MergeInfo(mElem);
String uri = getItemUri(nodeId, sessionInfo);
request = new HttpMerge(uri, mInfo);
initMethod(request, sessionInfo, !isUnLockMethod(request));
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] resps = request.getResponseBodyAsMultiStatus(response).getResponses();
List<NodeId> failedIds = new ArrayList<NodeId>(resps.length);
for (MultiStatusResponse resp : resps) {
String href = resolve(uri, resp.getHref());
failedIds.add(uriResolver.getNodeId(href, sessionInfo));
}
return failedIds.iterator();
} catch (IOException e) {
throw new RepositoryException(e);
} catch (ParserConfigurationException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.
the class RepositoryServiceImpl method loadType.
private int loadType(String propertyURI, HttpClient client, PropertyId propertyId, SessionInfo sessionInfo, NamePathResolver resolver) throws IOException, DavException, RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(propertyURI, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length == 1) {
DavPropertySet props = mresponses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
if (type != null) {
return PropertyType.valueFromName(type.getValue().toString());
} else {
throw new RepositoryException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} else {
throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + saveGetIdString(propertyId, resolver));
}
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations