001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thibaud Arguillere 018 */ 019package org.nuxeo.diff.pictures; 020 021import java.util.List; 022import java.util.Locale; 023 024import org.nuxeo.ecm.core.api.Blob; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.convert.api.ConversionException; 027import org.nuxeo.ecm.diff.content.ContentDiffException; 028import org.nuxeo.ecm.diff.content.adapter.MimeTypeContentDiffer; 029import org.nuxeo.ecm.diff.content.adapter.base.AbstractContentDiffAdapter; 030import org.nuxeo.ecm.diff.content.adapter.base.ContentDiffConversionType; 031 032/** 033 * @since 7.4 034 */ 035public class ImageMagickContentDiffAdapter extends AbstractContentDiffAdapter { 036 037 public static final String IMAGE_MAGIC_CONTENT_DIFFER_NAME = "imageMagickContentDiffer"; 038 039 @Override 040 public boolean cachable() { 041 042 return true; 043 } 044 045 @Override 046 public void cleanup() { 047 // Cleanup your stuff here 048 } 049 050 @Override 051 protected List<Blob> getContentDiffBlobs(DocumentModel otherDoc, ContentDiffConversionType conversionType, 052 Locale locale) throws ContentDiffException, ConversionException { 053 054 return getContentDiffBlobs(otherDoc, null, conversionType, locale); 055 } 056 057 @Override 058 protected List<Blob> getContentDiffBlobs(DocumentModel otherDoc, String xpath, 059 ContentDiffConversionType conversionType, Locale locale) throws ContentDiffException, ConversionException { 060 061 MimeTypeContentDiffer contentDiffer = getContentDiffAdapterManager().getContentDifferForName( 062 IMAGE_MAGIC_CONTENT_DIFFER_NAME); 063 if (contentDiffer instanceof ImageMagickContentDiffer) { 064 ImageMagickContentDiffer imContentDiffer = (ImageMagickContentDiffer) contentDiffer; 065 return imContentDiffer.getContentDiff(adaptedDoc, otherDoc, xpath, locale); 066 } 067 throw new ContentDiffException("The contentDiffer for '" + IMAGE_MAGIC_CONTENT_DIFFER_NAME 068 + "' should be a ImageMagickContentDiffer. Check the xml contribution."); 069 } 070 071}