Search in sources :

Example 1 with Chunk

use of com.zimbra.cs.doc.Diff.Chunk in project zm-mailbox by Zimbra.

the class DiffDocument method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    Element doc = request.getElement(MailConstants.E_DOC);
    String idStr = doc.getAttribute(MailConstants.A_ID, null);
    int v1 = (int) doc.getAttributeLong(MailConstants.A_V1, -1);
    int v2 = (int) doc.getAttributeLong(MailConstants.A_V2, -1);
    ItemId id = new ItemId(idStr, zsc);
    Document r1 = (Document) mbox.getItemRevision(octxt, id.getId(), MailItem.Type.UNKNOWN, v1);
    Document r2 = (Document) mbox.getItemRevision(octxt, id.getId(), MailItem.Type.UNKNOWN, v2);
    Element response = zsc.createElement(MailConstants.DIFF_DOCUMENT_RESPONSE);
    try {
        Collection<Chunk> diffResult = Diff.getResult(r1.getContentStream(), r2.getContentStream());
        for (Chunk c : diffResult) {
            Element chunk = response.addElement(MailConstants.E_CHUNK);
            chunk.addAttribute(MailConstants.A_DISP, c.disposition.toString());
            chunk.setText(StringUtil.join("\n", c.content));
        }
    } catch (IOException e) {
        throw ServiceException.FAILURE("can't diff documents", e);
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) IOException(java.io.IOException) Document(com.zimbra.cs.mailbox.Document) Chunk(com.zimbra.cs.doc.Diff.Chunk) ItemId(com.zimbra.cs.service.util.ItemId)

Aggregations

Element (com.zimbra.common.soap.Element)1 Chunk (com.zimbra.cs.doc.Diff.Chunk)1 Document (com.zimbra.cs.mailbox.Document)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ItemId (com.zimbra.cs.service.util.ItemId)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 IOException (java.io.IOException)1