Search in sources :

Example 1 with OrderPatch

use of org.apache.jackrabbit.webdav.ordering.OrderPatch in project jackrabbit by apache.

the class AbstractWebdavServlet method doOrderPatch.

/**
     * The ORDERPATCH method
     *
     * @param request
     * @param response
     * @param resource
     * @throws IOException
     * @throws DavException
     */
protected void doOrderPatch(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    if (!(resource instanceof OrderingResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    OrderPatch op = request.getOrderPatch();
    if (op == null) {
        response.sendError(DavServletResponse.SC_BAD_REQUEST);
        return;
    }
    // perform reordering of internal members
    ((OrderingResource) resource).orderMembers(op);
    response.setStatus(DavServletResponse.SC_OK);
}
Also used : OrderingResource(org.apache.jackrabbit.webdav.ordering.OrderingResource) OrderPatch(org.apache.jackrabbit.webdav.ordering.OrderPatch)

Example 2 with OrderPatch

use of org.apache.jackrabbit.webdav.ordering.OrderPatch in project jackrabbit by apache.

the class WebdavRequestImpl method getOrderPatch.

/**
     * @return <code>OrderPatch</code> object representing the orderpatch request
     *         body or <code>null</code> if the
     * @see org.apache.jackrabbit.webdav.ordering.OrderingDavServletRequest#getOrderPatch()
     */
public OrderPatch getOrderPatch() throws DavException {
    OrderPatch op = null;
    Document requestDocument = getRequestDocument();
    if (requestDocument != null) {
        Element root = requestDocument.getDocumentElement();
        op = OrderPatch.createFromXml(root);
    } else {
        log.error("Error while building xml document from ORDERPATH request body.");
    }
    return op;
}
Also used : OrderPatch(org.apache.jackrabbit.webdav.ordering.OrderPatch) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 3 with OrderPatch

use of org.apache.jackrabbit.webdav.ordering.OrderPatch in project jackrabbit by apache.

the class DefaultItemCollection method orderMembers.

/**
     * Reorder the child nodes of the repository item represented by this
     * resource as indicated by the specified {@link OrderPatch} object.
     *
     * @param orderPatch
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.ordering.OrderingResource#orderMembers(org.apache.jackrabbit.webdav.ordering.OrderPatch)
     * @see Node#orderBefore(String, String)
     */
@Override
public void orderMembers(OrderPatch orderPatch) throws DavException {
    if (!isOrderable()) {
        throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
    }
    // only custom ordering is allowed
    if (!OrderingConstants.ORDERING_TYPE_CUSTOM.equalsIgnoreCase(orderPatch.getOrderingType())) {
        throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Only DAV:custom ordering type supported.");
    }
    Node n = (Node) item;
    try {
        for (OrderPatch.Member instruction : orderPatch.getOrderInstructions()) {
            String srcRelPath = Text.unescape(instruction.getMemberHandle());
            Position pos = instruction.getPosition();
            String destRelPath = getRelDestinationPath(pos, n.getNodes());
            // preform the reordering
            n.orderBefore(srcRelPath, destRelPath);
        }
        complete();
    } catch (RepositoryException e) {
        // UnsupportedRepositoryException should not occur
        throw new JcrDavException(e);
    }
}
Also used : OrderPatch(org.apache.jackrabbit.webdav.ordering.OrderPatch) DavException(org.apache.jackrabbit.webdav.DavException) Position(org.apache.jackrabbit.webdav.ordering.Position) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Aggregations

OrderPatch (org.apache.jackrabbit.webdav.ordering.OrderPatch)3 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 DavException (org.apache.jackrabbit.webdav.DavException)1 OrderingResource (org.apache.jackrabbit.webdav.ordering.OrderingResource)1 Position (org.apache.jackrabbit.webdav.ordering.Position)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1