Search in sources :

Example 16 with DavPropertyNameSet

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

the class DefaultItemResource method initPropertyNames.

//--------------------------------------------------------------------------
@Override
protected void initPropertyNames() {
    super.initPropertyNames();
    if (exists()) {
        DavPropertyNameSet propNames = (isMultiple() ? JcrDavPropertyNameSet.PROPERTY_MV_SET : JcrDavPropertyNameSet.PROPERTY_SET);
        names.addAll(propNames);
    }
}
Also used : JcrDavPropertyNameSet(org.apache.jackrabbit.webdav.jcr.property.JcrDavPropertyNameSet) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet)

Example 17 with DavPropertyNameSet

use of org.apache.jackrabbit.webdav.property.DavPropertyNameSet 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 18 with DavPropertyNameSet

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

the class RepositoryServiceImpl method getPrivilegeNames.

@Override
public Name[] getPrivilegeNames(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
    String uri = (nodeId == null) ? uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()) : getItemUri(nodeId, sessionInfo);
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
    HttpPropfind propfindRequest = null;
    try {
        propfindRequest = new HttpPropfind(uri, nameSet, DEPTH_0);
        HttpResponse response = execute(propfindRequest, sessionInfo);
        propfindRequest.checkSuccess(response);
        MultiStatusResponse[] mresponses = propfindRequest.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new PathNotFoundException("Unable to retrieve privileges definitions.");
        }
        DavPropertyName displayName = SecurityConstants.CURRENT_USER_PRIVILEGE_SET;
        DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
        if (p == null) {
            return new Name[0];
        } else {
            Collection<Privilege> privs = new CurrentUserPrivilegeSetProperty(p).getValue();
            Set<Name> privNames = new HashSet<Name>(privs.size());
            for (Privilege priv : privs) {
                privNames.add(nameFactory.create(priv.getNamespace().getURI(), priv.getName()));
            }
            return privNames.toArray(new Name[privNames.size()]);
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (propfindRequest != null) {
            propfindRequest.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) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) CurrentUserPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) PathNotFoundException(javax.jcr.PathNotFoundException) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) Privilege(org.apache.jackrabbit.webdav.security.Privilege) HashSet(java.util.HashSet)

Example 19 with DavPropertyNameSet

use of org.apache.jackrabbit.webdav.property.DavPropertyNameSet 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)

Example 20 with DavPropertyNameSet

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

the class RepositoryServiceImpl method getItemDefinition.

/**
     *
     * @param sessionInfo
     * @param itemId
     * @return
     * @throws RepositoryException
     */
private QItemDefinition getItemDefinition(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_DEFINITION_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(DavPropertyName.RESOURCETYPE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(itemId, sessionInfo);
        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 ItemNotFoundException("Unable to retrieve the item definition for " + saveGetIdString(itemId, sessionInfo));
        }
        if (mresponses.length > 1) {
            throw new RepositoryException("Internal error: ambigous item definition found '" + saveGetIdString(itemId, sessionInfo) + "'.");
        }
        DavPropertySet propertySet = mresponses[0].getProperties(DavServletResponse.SC_OK);
        // check if definition matches the type of the id
        DavProperty<?> rType = propertySet.get(DavPropertyName.RESOURCETYPE);
        if (rType.getValue() == null && itemId.denotesNode()) {
            throw new RepositoryException("Internal error: requested node definition and got property definition.");
        }
        NamePathResolver resolver = getNamePathResolver(sessionInfo);
        // build the definition
        QItemDefinition definition = null;
        DavProperty<?> prop = propertySet.get(JcrRemotingConstants.JCR_DEFINITION_LN, ItemResourceConstants.NAMESPACE);
        if (prop != null) {
            Object value = prop.getValue();
            if (value != null && value instanceof Element) {
                Element idfElem = (Element) value;
                if (itemId.denotesNode()) {
                    definition = DefinitionUtil.createQNodeDefinition(null, idfElem, resolver);
                } else {
                    definition = DefinitionUtil.createQPropertyDefinition(null, idfElem, resolver, getQValueFactory());
                }
            }
        }
        if (definition == null) {
            throw new RepositoryException("Unable to retrieve definition for item with id '" + saveGetIdString(itemId, resolver) + "'.");
        }
        return definition;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) 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)

Aggregations

DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)34 HttpResponse (org.apache.http.HttpResponse)19 RepositoryException (javax.jcr.RepositoryException)16 DavException (org.apache.jackrabbit.webdav.DavException)15 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)15 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)15 IOException (java.io.IOException)14 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)13 NodeId (org.apache.jackrabbit.spi.NodeId)9 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 Batch (org.apache.jackrabbit.spi.Batch)6 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)4 Element (org.w3c.dom.Element)4 Name (org.apache.jackrabbit.spi.Name)3 HttpProppatch (org.apache.jackrabbit.webdav.client.methods.HttpProppatch)3 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 PathNotFoundException (javax.jcr.PathNotFoundException)2