001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thibaud Arguillere
016 */
017package org.nuxeo.diff.pictures;
018
019import java.util.List;
020import java.util.Locale;
021
022import org.nuxeo.ecm.core.api.Blob;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.core.convert.api.ConversionException;
025import org.nuxeo.ecm.diff.content.ContentDiffException;
026import org.nuxeo.ecm.diff.content.adapter.MimeTypeContentDiffer;
027import org.nuxeo.ecm.diff.content.adapter.base.AbstractContentDiffAdapter;
028import org.nuxeo.ecm.diff.content.adapter.base.ContentDiffConversionType;
029
030/**
031 * @since 7.4
032 */
033public class ImageMagickContentDiffAdapter extends AbstractContentDiffAdapter {
034
035    public static final String IMAGE_MAGIC_CONTENT_DIFFER_NAME = "imageMagickContentDiffer";
036
037    @Override
038    public boolean cachable() {
039
040        return true;
041    }
042
043    @Override
044    public void cleanup() {
045        // Cleanup your stuff here
046    }
047
048    @Override
049    protected List<Blob> getContentDiffBlobs(DocumentModel otherDoc, ContentDiffConversionType conversionType,
050            Locale locale) throws ContentDiffException, ConversionException {
051
052        return getContentDiffBlobs(otherDoc, null, conversionType, locale);
053    }
054
055    @Override
056    protected List<Blob> getContentDiffBlobs(DocumentModel otherDoc, String xpath,
057            ContentDiffConversionType conversionType, Locale locale) throws ContentDiffException, ConversionException {
058
059        MimeTypeContentDiffer contentDiffer = getContentDiffAdapterManager().getContentDifferForName(
060                IMAGE_MAGIC_CONTENT_DIFFER_NAME);
061        if (contentDiffer instanceof ImageMagickContentDiffer) {
062            ImageMagickContentDiffer imContentDiffer = (ImageMagickContentDiffer) contentDiffer;
063            return imContentDiffer.getContentDiff(adaptedDoc, otherDoc, xpath, locale);
064        }
065        throw new ContentDiffException("The contentDiffer for '" + IMAGE_MAGIC_CONTENT_DIFFER_NAME
066                + "' should be a ImageMagickContentDiffer. Check the xml contribution.");
067    }
068
069}