Search in sources :

Example 16 with DavPropertySet

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

Example 17 with DavPropertySet

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

the class RepositoryServiceImpl method getNodeInfo.

@Override
public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PRIMARYNODETYPE_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_MIXINNODETYPES_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PATH_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(DavPropertyName.RESOURCETYPE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(nodeId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_1);
        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 node with id " + saveGetIdString(nodeId, sessionInfo));
        }
        MultiStatusResponse nodeResponse = null;
        List<MultiStatusResponse> childResponses = new ArrayList<MultiStatusResponse>();
        for (MultiStatusResponse mresponse : mresponses) {
            if (isSameResource(uri, mresponse)) {
                nodeResponse = mresponse;
            } else {
                childResponses.add(mresponse);
            }
        }
        if (nodeResponse == null) {
            throw new ItemNotFoundException("Unable to retrieve the node " + saveGetIdString(nodeId, sessionInfo));
        }
        DavPropertySet propSet = nodeResponse.getProperties(DavServletResponse.SC_OK);
        Object type = propSet.get(DavPropertyName.RESOURCETYPE).getValue();
        if (type == null) {
            // the given id points to a Property instead of a Node
            throw new ItemNotFoundException("No node for id " + saveGetIdString(nodeId, sessionInfo));
        }
        NamePathResolver resolver = getNamePathResolver(sessionInfo);
        NodeId parentId = getParentId(uri, propSet, sessionInfo);
        NodeInfoImpl nInfo = buildNodeInfo(uri, nodeResponse, parentId, propSet, sessionInfo, resolver);
        for (MultiStatusResponse resp : childResponses) {
            DavPropertySet childProps = resp.getProperties(DavServletResponse.SC_OK);
            if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
                // any other resource type than default (empty) is represented by a node item
                // --> build child info object
                nInfo.addChildInfo(buildChildInfo(childProps, sessionInfo));
            } else {
                PropertyId childId = uriResolver.buildPropertyId(nInfo.getId(), resp, sessionInfo.getWorkspaceName(), getNamePathResolver(sessionInfo));
                nInfo.addPropertyId(childId);
            }
        }
        return nInfo;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } catch (NameException e) {
        throw new RepositoryException(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) PropertyId(org.apache.jackrabbit.spi.PropertyId) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) NodeId(org.apache.jackrabbit.spi.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 18 with DavPropertySet

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

the class RepositoryServiceImpl method unregisterNodeTypes.

@Override
public void unregisterNodeTypes(SessionInfo sessionInfo, Name[] nodeTypeNames) throws RepositoryException {
    HttpProppatch request = null;
    try {
        DavPropertySet setProperties = new DavPropertySet();
        setProperties.add(createUnRegisterNodeTypesProperty(sessionInfo, nodeTypeNames));
        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 19 with DavPropertySet

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

the class WebdavResponseImpl method sendSubscriptionResponse.

//----------------------------< ObservationDavServletResponse Interface >---
/**
     *
     * @param subscription
     * @throws IOException
     * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletResponse#sendSubscriptionResponse(org.apache.jackrabbit.webdav.observation.Subscription)
     */
public void sendSubscriptionResponse(Subscription subscription) throws IOException {
    String id = subscription.getSubscriptionId();
    if (id != null) {
        Header h = new CodedUrlHeader(ObservationConstants.HEADER_SUBSCRIPTIONID, id);
        httpResponse.setHeader(h.getHeaderName(), h.getHeaderValue());
    }
    DavPropertySet propSet = new DavPropertySet();
    propSet.add(new SubscriptionDiscovery(subscription));
    sendXmlResponse(propSet, SC_OK);
}
Also used : CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) Header(org.apache.jackrabbit.webdav.header.Header) SubscriptionDiscovery(org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery)

Example 20 with DavPropertySet

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

the class WebdavRequestImpl method parsePropPatchRequest.

/**
     * Parse the PROPPATCH request body.
     */
private void parsePropPatchRequest() throws DavException {
    proppatchSet = new DavPropertySet();
    proppatchList = new ArrayList<PropEntry>();
    Document requestDocument = getRequestDocument();
    if (requestDocument == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid request body.");
    }
    Element root = requestDocument.getDocumentElement();
    if (!DomUtil.matches(root, XML_PROPERTYUPDATE, NAMESPACE)) {
        log.warn("PropPatch-Request has no <DAV:propertyupdate> tag.");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropPatch-Request has no <propertyupdate> tag.");
    }
    ElementIterator it = DomUtil.getChildren(root);
    while (it.hasNext()) {
        Element el = it.nextElement();
        if (DomUtil.matches(el, XML_SET, NAMESPACE)) {
            Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);
            if (propEl != null) {
                ElementIterator properties = DomUtil.getChildren(propEl);
                while (properties.hasNext()) {
                    DavProperty<?> davProp = DefaultDavProperty.createFromXml(properties.nextElement());
                    proppatchSet.add(davProp);
                    proppatchList.add(davProp);
                }
            }
        } else if (DomUtil.matches(el, XML_REMOVE, NAMESPACE)) {
            Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);
            if (propEl != null) {
                ElementIterator properties = DomUtil.getChildren(propEl);
                while (properties.hasNext()) {
                    DavProperty<?> davProp = DefaultDavProperty.createFromXml(properties.nextElement());
                    proppatchSet.add(davProp);
                    proppatchList.add(davProp.getName());
                }
            }
        } else {
            log.debug("Unknown element in DAV:propertyupdate: " + el.getNodeName());
        // unknown child elements are ignored
        }
    }
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) Element(org.w3c.dom.Element) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) Document(org.w3c.dom.Document)

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