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);
}
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;
}
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);
}
}
Aggregations