001/*
002 * Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Vladimir Pasquier <vpasquier@nuxeo.com>
011 *     Antoine Taillefer <ataillefer@nuxeo.com>
012 *
013 */
014package org.nuxeo.ecm.platform.thumbnail.factories;
015
016import org.nuxeo.ecm.core.api.Blob;
017import org.nuxeo.ecm.core.api.CoreSession;
018import org.nuxeo.ecm.core.api.DocumentModel;
019import org.nuxeo.ecm.core.api.DocumentRef;
020import org.nuxeo.ecm.core.api.NuxeoException;
021import org.nuxeo.ecm.core.api.thumbnail.ThumbnailAdapter;
022
023/**
024 * Default thumbnail factory for all folderish documents
025 *
026 * @since 5.7
027 */
028public class ThumbnailFolderishFactory extends ThumbnailDocumentFactory {
029
030    @Override
031    public Blob getThumbnail(DocumentModel doc, CoreSession session) {
032        if (!doc.isFolder()) {
033            throw new NuxeoException("Document is not folderish");
034        }
035        DocumentRef docRef = doc.getRef();
036        if (session.hasChildren(docRef)) {
037            DocumentModel child = session.getChildren(docRef).get(0);
038            if (!child.isFolder()) {
039                return session.getChildren(docRef).get(0).getAdapter(ThumbnailAdapter.class).getThumbnail(session);
040            }
041        }
042        return getDefaultThumbnail(doc);
043    }
044
045    @Override
046    public Blob computeThumbnail(DocumentModel doc, CoreSession session) {
047        return null;
048    }
049}