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 * Antoine Taillefer <ataillefer@nuxeo.com> 016 * Thibaud Arguillere 017 */ 018 019package org.nuxeo.diff.pictures; 020 021import java.io.StringWriter; 022import java.util.ArrayList; 023import java.util.List; 024import java.util.Locale; 025 026import org.nuxeo.ecm.core.api.Blob; 027import org.nuxeo.ecm.core.api.Blobs; 028import org.nuxeo.ecm.core.api.DocumentModel; 029import org.nuxeo.ecm.diff.content.ContentDiffException; 030import org.nuxeo.ecm.diff.content.adapter.MimeTypeContentDiffer; 031 032/** 033 * ImageMagickContentDiffer 034 * 035 * @since 7.4 036 */ 037public class ImageMagickContentDiffer implements MimeTypeContentDiffer { 038 039 @Override 040 public List<Blob> getContentDiff(DocumentModel leftDoc, DocumentModel rightDoc, String xpath, Locale locale) 041 throws ContentDiffException { 042 043 try { 044 List<Blob> blobResults = new ArrayList<Blob>(); 045 StringWriter sw = new StringWriter(); 046 047 String html = DiffPictures.buildDiffHtml(leftDoc, rightDoc, xpath); 048 sw.write(html); 049 050 String stringBlob = sw.toString(); 051 Blob mainBlob = Blobs.createBlob(stringBlob); 052 sw.close(); 053 054 mainBlob.setFilename("contentDiff.html"); 055 mainBlob.setMimeType("text/html"); 056 057 blobResults.add(mainBlob); 058 return blobResults; 059 060 } catch (Exception e) { 061 throw new ContentDiffException(e); 062 } 063 } 064 065 @Override 066 public List<Blob> getContentDiff(Blob leftBlob, Blob rightBlob, Locale locale) throws ContentDiffException { 067 throw new UnsupportedOperationException("ImageMagickContentDiffer can handle only DocumentModel"); 068 } 069}