Search in sources :

Example 11 with DavPropertySet

use of org.apache.jackrabbit.webdav.property.DavPropertySet 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();
        }
    }
}
Also used : 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) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 12 with DavPropertySet

use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.

the class RepositoryServiceImpl method getLockInfo.

@Override
public LockInfo getLockInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
    // set of Dav-properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(DavPropertyName.LOCKDISCOVERY);
    nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(nodeId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_0);
        initMethod(request, sessionInfo, false);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length != 1) {
            throw new ItemNotFoundException("Unable to retrieve the LockInfo. No such node " + saveGetIdString(nodeId, sessionInfo));
        }
        DavPropertySet ps = mresponses[0].getProperties(DavServletResponse.SC_OK);
        if (ps.contains(DavPropertyName.LOCKDISCOVERY)) {
            DavProperty<?> p = ps.get(DavPropertyName.LOCKDISCOVERY);
            LockDiscovery ld = LockDiscovery.createFromXml(p.toXml(DomUtil.createDocument()));
            NodeId parentId = getParentId(uri, ps, sessionInfo);
            return retrieveLockInfo(ld, sessionInfo, nodeId, parentId);
        } else {
            // no lock present
            log.debug("No Lock present on node with id " + saveGetIdString(nodeId, sessionInfo));
            return null;
        }
    } 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();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) NodeId(org.apache.jackrabbit.spi.NodeId) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 13 with DavPropertySet

use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.

the class WebdavResponseImpl method sendRefreshLockResponse.

/**
     * Send response body for a lock request that was intended to refresh one
     * or several locks.
     *
     * @param locks
     * @throws java.io.IOException
     * @see DavServletResponse#sendRefreshLockResponse(org.apache.jackrabbit.webdav.lock.ActiveLock[])
     */
public void sendRefreshLockResponse(ActiveLock[] locks) throws IOException {
    DavPropertySet propSet = new DavPropertySet();
    propSet.add(new LockDiscovery(locks));
    sendXmlResponse(propSet, SC_OK);
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery)

Example 14 with DavPropertySet

use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.

the class RepositoryServiceImpl method obtain.

private SessionInfo obtain(CredentialsWrapper credentials, String workspaceName) throws RepositoryException {
    // check if the workspace with the given name is accessible
    HttpPropfind request = null;
    SessionInfoImpl sessionInfo = new SessionInfoImpl(credentials, workspaceName);
    try {
        DavPropertyNameSet nameSet = new DavPropertyNameSet();
        // for backwards compat. -> retrieve DAV:workspace if the newly
        // added property (workspaceName) is not supported by the server.
        nameSet.add(DeltaVConstants.WORKSPACE);
        nameSet.add(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
        request = new HttpPropfind(uriResolver.getWorkspaceUri(workspaceName), nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (responses.length != 1) {
            throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
        }
        DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
        DavProperty<?> prop = props.get(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
        if (prop != null) {
            String wspName = prop.getValue().toString();
            if (workspaceName == null) {
                // login with 'null' workspace name -> retrieve the effective
                // workspace name from the property and recreate the SessionInfo.
                sessionInfo = new SessionInfoImpl(credentials, wspName);
            } else if (!wspName.equals(workspaceName)) {
                throw new LoginException("Login failed: Invalid workspace name '" + workspaceName + "'.");
            }
        } else if (props.contains(DeltaVConstants.WORKSPACE)) {
            String wspHref = new HrefProperty(props.get(DeltaVConstants.WORKSPACE)).getHrefs().get(0);
            String wspName = Text.unescape(Text.getName(wspHref, true));
            if (!wspName.equals(workspaceName)) {
                throw new LoginException("Login failed: Invalid workspace name " + workspaceName);
            }
        } else {
            throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
        }
    } catch (IOException e) {
        throw new RepositoryException(e.getMessage());
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
    // mappings.
    if (nsCache.prefixToURI.isEmpty()) {
        try {
            getRegisteredNamespaces(sessionInfo);
        } catch (RepositoryException e) {
        // ignore
        }
    }
    // return the sessionInfo
    return sessionInfo;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) LoginException(javax.jcr.LoginException)

Example 15 with DavPropertySet

use of org.apache.jackrabbit.webdav.property.DavPropertySet in project jackrabbit by apache.

the class RepositoryServiceImpl method getWorkspaceNames.

@Override
public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(DeltaVConstants.WORKSPACE);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uriResolver.getRepositoryUri(), nameSet, DEPTH_1);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        Set<String> wspNames = new HashSet<String>();
        for (MultiStatusResponse mresponse : mresponses) {
            DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
            if (props.contains(DeltaVConstants.WORKSPACE)) {
                HrefProperty hp = new HrefProperty(props.get(DeltaVConstants.WORKSPACE));
                String wspHref = hp.getHrefs().get(0);
                String name = Text.unescape(Text.getName(wspHref, true));
                wspNames.add(name);
            }
        }
        return wspNames.toArray(new String[wspNames.size()]);
    } 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) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) HashSet(java.util.HashSet)

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