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.platform.picture.preview.adapter.factories; 016 017import org.nuxeo.ecm.core.api.DocumentModel; 018import org.nuxeo.ecm.platform.picture.api.adapters.PictureResourceAdapter; 019import org.nuxeo.ecm.platform.preview.adapter.PreviewAdapterFactory; 020import org.nuxeo.ecm.platform.preview.adapter.base.ConverterBasedHtmlPreviewAdapter; 021import org.nuxeo.ecm.platform.preview.api.HtmlPreviewAdapter; 022 023/** 024 * Preview adapter factory for the Picture document type 025 * 026 * @author qlamerand 027 */ 028public class PicturePreviewAdapterFactory implements PreviewAdapterFactory { 029 030 protected static final String ORIGINAL_JPEG_VIEW_NAME = "OriginalJpeg"; 031 032 /** 033 * @deprecated since 7.2. The Original view does not exist anymore. See NXP-16070. 034 */ 035 @Deprecated 036 protected static final String ORIGINAL_VIEW_NAME = "Original"; 037 038 @Override 039 public HtmlPreviewAdapter getAdapter(DocumentModel doc) { 040 ConverterBasedHtmlPreviewAdapter adapter = new ConverterBasedHtmlPreviewAdapter(); 041 adapter.setAdaptedDocument(doc); 042 043 PictureResourceAdapter prAdapter = doc.getAdapter(PictureResourceAdapter.class); 044 String xpath = prAdapter.getViewXPath(ORIGINAL_JPEG_VIEW_NAME); 045 if (xpath != null) { 046 adapter.setDefaultPreviewFieldXPath(xpath + "content"); 047 } else { 048 adapter.setDefaultPreviewFieldXPath(prAdapter.getFirstViewXPath() + "content"); 049 } 050 051 return adapter; 052 } 053 054}