Search in sources :

Example 6 with DavPropertySet

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);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) HttpPut(org.apache.http.client.methods.HttpPut)

Example 7 with DavPropertySet

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);
    }
}
Also used : CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery)

Example 8 with DavPropertySet

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();
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpProppatch(org.apache.jackrabbit.webdav.client.methods.HttpProppatch) DavException(org.apache.jackrabbit.webdav.DavException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 9 with DavPropertySet

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();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 10 with DavPropertySet

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();
        }
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpProppatch(org.apache.jackrabbit.webdav.client.methods.HttpProppatch) DavException(org.apache.jackrabbit.webdav.DavException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)20 RepositoryException (javax.jcr.RepositoryException)14 HttpResponse (org.apache.http.HttpResponse)14 DavException (org.apache.jackrabbit.webdav.DavException)13 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)13 IOException (java.io.IOException)11 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)11 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)11 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 NodeId (org.apache.jackrabbit.spi.NodeId)3 PropertyId (org.apache.jackrabbit.spi.PropertyId)3 HttpProppatch (org.apache.jackrabbit.webdav.client.methods.HttpProppatch)3 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 ArrayList (java.util.ArrayList)2 Name (org.apache.jackrabbit.spi.Name)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2 CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)2 Element (org.w3c.dom.Element)2