use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class RFC4918PropfindTest method testPropfindInclude.
public void testPropfindInclude() throws IOException, DavException, URISyntaxException {
String testuri = this.root + "iftest";
int status;
try {
HttpPut put = new HttpPut(testuri);
put.setEntity(new StringEntity("1"));
status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
assertEquals("status: " + status, 201, status);
DavPropertyNameSet names = new DavPropertyNameSet();
names.add(DeltaVConstants.COMMENT);
HttpPropfind propfind = new HttpPropfind(testuri, DavConstants.PROPFIND_ALL_PROP_INCLUDE, names, 0);
HttpResponse resp = this.client.execute(propfind, this.context);
status = resp.getStatusLine().getStatusCode();
assertEquals(207, status);
MultiStatus multistatus = propfind.getResponseBodyAsMultiStatus(resp);
MultiStatusResponse[] responses = multistatus.getResponses();
assertEquals(1, responses.length);
MultiStatusResponse response = responses[0];
DavPropertySet found = response.getProperties(200);
DavPropertySet notfound = response.getProperties(404);
assertTrue(found.contains(DeltaVConstants.COMMENT) || notfound.contains(DeltaVConstants.COMMENT));
} finally {
delete(testuri);
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class AbstractWebdavServlet method doLock.
/**
* The LOCK method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doLock(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
LockInfo lockInfo = request.getLockInfo();
if (lockInfo.isRefreshLock()) {
// refresh any matching existing locks
ActiveLock[] activeLocks = resource.getLocks();
List<ActiveLock> lList = new ArrayList<ActiveLock>();
for (ActiveLock activeLock : activeLocks) {
// adjust lockinfo with type/scope retrieved from the lock.
lockInfo.setType(activeLock.getType());
lockInfo.setScope(activeLock.getScope());
DavProperty<?> etagProp = resource.getProperty(DavPropertyName.GETETAG);
String etag = etagProp != null ? String.valueOf(etagProp.getValue()) : "";
if (request.matchesIfHeader(resource.getHref(), activeLock.getToken(), etag)) {
lList.add(resource.refreshLock(lockInfo, activeLock.getToken()));
}
}
if (lList.isEmpty()) {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
}
ActiveLock[] refreshedLocks = lList.toArray(new ActiveLock[lList.size()]);
response.sendRefreshLockResponse(refreshedLocks);
} else {
int status = HttpServletResponse.SC_OK;
if (!resource.exists()) {
// lock-empty requires status code 201 (Created)
status = HttpServletResponse.SC_CREATED;
}
// create a new lock
ActiveLock lock = resource.lock(lockInfo);
CodedUrlHeader header = new CodedUrlHeader(DavConstants.HEADER_LOCK_TOKEN, lock.getToken());
response.setHeader(header.getHeaderName(), header.getHeaderValue());
DavPropertySet propSet = new DavPropertySet();
propSet.add(new LockDiscovery(lock));
response.sendXmlResponse(propSet, status);
}
}
use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.
the class RepositoryServiceImpl method internalSetNamespaces.
/**
*
* @param sessionInfo
* @param namespaces
* @throws NamespaceException
* @throws UnsupportedRepositoryOperationException
* @throws AccessDeniedException
* @throws RepositoryException
*/
private void internalSetNamespaces(SessionInfo sessionInfo, Map<String, String> namespaces) throws RepositoryException {
DavPropertySet setProperties = new DavPropertySet();
setProperties.add(createNamespaceProperty(namespaces));
HttpProppatch request = null;
try {
String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
request = new HttpProppatch(uri, setProperties, new DavPropertyNameSet());
initMethod(request, sessionInfo, true);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
} 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.property.DavPropertySet 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.property.DavPropertySet in project jackrabbit by apache.
the class RepositoryServiceImpl method registerNodeTypes.
@Override
public void registerNodeTypes(SessionInfo sessionInfo, QNodeTypeDefinition[] nodeTypeDefinitions, boolean allowUpdate) throws RepositoryException {
HttpProppatch request = null;
try {
DavPropertySet setProperties = new DavPropertySet();
setProperties.add(createRegisterNodeTypesProperty(sessionInfo, nodeTypeDefinitions, allowUpdate));
String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
request = new HttpProppatch(uri, setProperties, new DavPropertyNameSet());
initMethod(request, sessionInfo, true);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations