001/* 002 * (C) Copyright 2006-2012 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.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 016 */ 017package org.nuxeo.ecm.diff.content.adapter.base; 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.ContentDiffAdapter; 026import org.nuxeo.ecm.diff.content.ContentDiffException; 027import org.nuxeo.ecm.diff.content.ContentDiffHelper; 028import org.nuxeo.ecm.diff.content.adapter.ContentDiffAdapterManager; 029import org.nuxeo.runtime.api.Framework; 030 031/** 032 * Abstract base class for content diff adapters. 033 * 034 * @author Antoine Taillefer 035 * @since 5.6 036 */ 037public abstract class AbstractContentDiffAdapter implements ContentDiffAdapter { 038 039 protected DocumentModel adaptedDoc; 040 041 public String getFileContentDiffURL(DocumentModel otherDoc, ContentDiffConversionType conversionType, String locale) { 042 return ContentDiffHelper.getContentDiffURL(adaptedDoc, otherDoc, conversionType.name(), locale); 043 } 044 045 public String getFileContentDiffURL(DocumentModel otherDoc, String xpath, ContentDiffConversionType conversionType, 046 String locale) { 047 return ContentDiffHelper.getContentDiffURL(adaptedDoc, otherDoc, xpath, conversionType.name(), locale); 048 } 049 050 public List<Blob> getFileContentDiffBlobs(DocumentModel otherDoc, ContentDiffConversionType conversionType, 051 Locale locale) throws ContentDiffException, ConversionException { 052 return getContentDiffBlobs(otherDoc, conversionType, locale); 053 } 054 055 public List<Blob> getFileContentDiffBlobs(DocumentModel otherDoc, String xpath, 056 ContentDiffConversionType conversionType, Locale locale) throws ContentDiffException, ConversionException { 057 return getContentDiffBlobs(otherDoc, xpath, conversionType, locale); 058 } 059 060 protected abstract List<Blob> getContentDiffBlobs(DocumentModel otherDoc, ContentDiffConversionType conversionType, 061 Locale locale) throws ContentDiffException, ConversionException; 062 063 protected abstract List<Blob> getContentDiffBlobs(DocumentModel otherDoc, String xpath, 064 ContentDiffConversionType conversionType, Locale locale) throws ContentDiffException, ConversionException; 065 066 public void setAdaptedDocument(DocumentModel doc) { 067 this.adaptedDoc = doc; 068 } 069 070 /** 071 * Gets the content diff adapter manager. 072 * 073 * @return the content diff adapter manager 074 */ 075 protected final ContentDiffAdapterManager getContentDiffAdapterManager() { 076 return Framework.getService(ContentDiffAdapterManager.class); 077 } 078 079}