Search in sources :

Example 11 with MultiStatusResponse

use of org.apache.jackrabbit.webdav.MultiStatusResponse 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 12 with MultiStatusResponse

use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.

the class JcrPrivilegeReport method addResponses.

private void addResponses(DavResourceLocator locator) {
    String repositoryPath = locator.getRepositoryPath();
    MultiStatusResponse resp = new MultiStatusResponse(locator.getHref(false), null);
    List<Privilege> currentPrivs = new ArrayList<Privilege>();
    for (Privilege priv : PRIVS) {
        try {
            if (getRepositorySession().hasPermission(repositoryPath, priv.getName())) {
                currentPrivs.add(priv);
            }
        } catch (RepositoryException e) {
            // ignore
            log.debug(e.toString());
        }
    }
    resp.add(new CurrentUserPrivilegeSetProperty(currentPrivs.toArray(new Privilege[currentPrivs.size()])));
    ms.addResponse(resp);
}
Also used : CurrentUserPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Privilege(org.apache.jackrabbit.webdav.security.Privilege)

Example 13 with MultiStatusResponse

use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.

the class SearchResourceImpl method queryResultToMultiStatus.

/**
     * Build a <code>MultiStatus</code> object from the specified query result.
     *
     * @param query the query to execute.
     * @return <code>MultiStatus</code> object listing the query result in
     * Webdav compatible form.
     * @throws RepositoryException if an error occurs.
     */
private void queryResultToMultiStatus(QueryResult result, MultiStatus ms) throws RepositoryException {
    List<String> columnNames = new ArrayList<String>();
    ValueFactory vf = getRepositorySession().getValueFactory();
    List<RowValue> descr = new ArrayList<RowValue>();
    for (String columnName : result.getColumnNames()) {
        if (!isPathOrScore(columnName)) {
            columnNames.add(columnName);
            descr.add(new PlainValue(columnName, null, vf));
        }
    }
    // add path and score for each selector
    String[] sns = result.getSelectorNames();
    boolean join = sns.length > 1;
    for (String selectorName : sns) {
        descr.add(new PathValue(JcrConstants.JCR_PATH, selectorName, vf));
        columnNames.add(JcrConstants.JCR_PATH);
        descr.add(new ScoreValue(JcrConstants.JCR_SCORE, selectorName, vf));
        columnNames.add(JcrConstants.JCR_SCORE);
    }
    int n = 0;
    String root = getHref("/");
    String[] selectorNames = createSelectorNames(descr);
    String[] colNames = columnNames.toArray(new String[columnNames.size()]);
    RowIterator rowIter = result.getRows();
    while (rowIter.hasNext()) {
        Row row = rowIter.nextRow();
        List<Value> values = new ArrayList<Value>();
        for (RowValue rv : descr) {
            values.add(rv.getValue(row));
        }
        // create a new ms-response for this row of the result set
        String href;
        if (join) {
            // We need a distinct href for each join result row to
            // allow the MultiStatus response to keep them separate
            href = root + "?" + n++;
        } else {
            href = getHref(row.getPath());
        }
        MultiStatusResponse resp = new MultiStatusResponse(href, null);
        // build the s-r-property
        SearchResultProperty srp = new SearchResultProperty(colNames, selectorNames, values.toArray(new Value[values.size()]));
        resp.add(srp);
        ms.addResponse(resp);
    }
}
Also used : ArrayList(java.util.ArrayList) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ValueFactory(javax.jcr.ValueFactory) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value) Row(javax.jcr.query.Row)

Example 14 with MultiStatusResponse

use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.

the class DefaultItemCollection method alterProperties.

/**
     * Loops over the given <code>List</code>s and alters the properties accordingly.
     * Changes are persisted at the end according to the rules defined with
     * the {@link AbstractItemResource#complete()} method.<p>
     * Please note: since there is only a single property
     * ({@link ItemResourceConstants#JCR_MIXINNODETYPES}
     * that can be set or removed with PROPPATCH, this method either succeeds
     * or throws an exception, even if this violates RFC 2518. Thus no property
     * specific multistatus will be created in case of an error.
     *
     * @param changeList
     * @return
     * @throws DavException
     */
@Override
public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
    for (PropEntry propEntry : changeList) {
        if (propEntry instanceof DavPropertyName) {
            // use the internal remove method in order to prevent premature 'save'
            DavPropertyName propName = (DavPropertyName) propEntry;
            internalRemoveProperty(propName);
        } else if (propEntry instanceof DavProperty) {
            // use the internal set method in order to prevent premature 'save'
            DavProperty<?> prop = (DavProperty<?>) propEntry;
            internalSetProperty(prop);
        } else {
            throw new IllegalArgumentException("unknown object in change list: " + propEntry.getClass().getName());
        }
    }
    // TODO: missing undo of successful set/remove if subsequent operation fails
    // NOTE, that this is relevant with transactions only.
    // success: save all changes together if no error occurred
    complete();
    return new MultiStatusResponse(getHref(), DavServletResponse.SC_OK);
}
Also used : PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 15 with MultiStatusResponse

use of org.apache.jackrabbit.webdav.MultiStatusResponse in project jackrabbit by apache.

the class DavResourceImpl method alterProperties.

public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
    if (isLocked(this)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatusResponse msr = new MultiStatusResponse(getHref(), null);
    try {
        Map<? extends PropEntry, ?> failures = config.getPropertyManager().alterProperties(getPropertyImportContext(changeList), isCollection());
        if (failures.isEmpty()) {
            // save all changes together (reverted in case this fails)
            node.save();
        } else {
            // set/remove of at least a single prop failed: undo modifications.
            node.refresh(false);
        }
        /* loop over list of properties/names that were successfully altered
               and them to the multistatus response respecting the result of the
               complete action. in case of failure set the status to 'failed-dependency'
               in order to indicate, that altering those names/properties would
               have succeeded, if no other error occured.*/
        for (PropEntry propEntry : changeList) {
            int statusCode;
            if (failures.containsKey(propEntry)) {
                Object error = failures.get(propEntry);
                statusCode = (error instanceof RepositoryException) ? new JcrDavException((RepositoryException) error).getErrorCode() : DavServletResponse.SC_INTERNAL_SERVER_ERROR;
            } else {
                statusCode = (failures.isEmpty()) ? DavServletResponse.SC_OK : DavServletResponse.SC_FAILED_DEPENDENCY;
            }
            if (propEntry instanceof DavProperty) {
                msr.add(((DavProperty<?>) propEntry).getName(), statusCode);
            } else {
                msr.add((DavPropertyName) propEntry, statusCode);
            }
        }
        return msr;
    } catch (RepositoryException e) {
        // revert any changes made so far an throw exception
        try {
            node.refresh(false);
        } catch (RepositoryException re) {
        // should not happen
        }
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException)

Aggregations

MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)27 RepositoryException (javax.jcr.RepositoryException)18 HttpResponse (org.apache.http.HttpResponse)18 DavException (org.apache.jackrabbit.webdav.DavException)17 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 IOException (java.io.IOException)13 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)11 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 ArrayList (java.util.ArrayList)5 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)5 NodeId (org.apache.jackrabbit.spi.NodeId)4 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)4 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)4 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)4 Element (org.w3c.dom.Element)4 HashSet (java.util.HashSet)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 CurrentUserPrivilegeSetProperty (org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty)3 Privilege (org.apache.jackrabbit.webdav.security.Privilege)3