Search in sources :

Example 1 with Position

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

Example 2 with Position

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

the class WebdavRequestImpl method getPosition.

/**
     * @see org.apache.jackrabbit.webdav.ordering.OrderingDavServletRequest#getPosition()
     */
public Position getPosition() {
    String h = getHeader(OrderingConstants.HEADER_POSITION);
    Position pos = null;
    if (h != null) {
        String[] typeNSegment = h.split("\\s");
        if (typeNSegment.length == 2) {
            try {
                pos = new Position(typeNSegment[0], typeNSegment[1]);
            } catch (IllegalArgumentException e) {
                log.error("Cannot parse Position header: " + e.getMessage());
            }
        }
    }
    return pos;
}
Also used : Position(org.apache.jackrabbit.webdav.ordering.Position)

Aggregations

Position (org.apache.jackrabbit.webdav.ordering.Position)2 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 DavException (org.apache.jackrabbit.webdav.DavException)1 OrderPatch (org.apache.jackrabbit.webdav.ordering.OrderPatch)1