001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (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 */ 015package org.nuxeo.ecm.diff.content.adapter.factories; 016 017import org.nuxeo.ecm.core.api.DocumentModel; 018import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 019import org.nuxeo.ecm.diff.content.ContentDiffAdapter; 020import org.nuxeo.ecm.diff.content.adapter.ContentDiffAdapterFactory; 021import org.nuxeo.ecm.diff.content.adapter.base.ConverterBasedContentDiffAdapter; 022 023/** 024 * Content diff adapter factory for all documents that have the file schema. 025 * 026 * @author Antoine taillefer 027 * @since 5.6 028 */ 029public class FileBasedContentDiffAdapterFactory implements ContentDiffAdapterFactory { 030 031 public ContentDiffAdapter getAdapter(DocumentModel doc) { 032 ConverterBasedContentDiffAdapter adapter = new ConverterBasedContentDiffAdapter(); 033 adapter.setAdaptedDocument(doc); 034 BlobHolder bh = doc.getAdapter(BlobHolder.class); 035 if (bh == null) { 036 if (doc.hasSchema("file")) { 037 adapter.setDefaultContentDiffFieldXPath("file:content"); 038 } else { 039 // Has "files" schema, set xpath to first blob as default 040 adapter.setDefaultContentDiffFieldXPath("files:files/0/file"); 041 } 042 } 043 return adapter; 044 } 045 046}