001/*
002 * (C) Copyright 2006-2008 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 * Contributors:
015 *     Alexandre Russel
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.preview.adapter;
021
022import java.util.ArrayList;
023import java.util.List;
024
025import org.nuxeo.ecm.core.api.Blob;
026import org.nuxeo.ecm.core.api.Blobs;
027import org.nuxeo.ecm.core.api.DocumentModel;
028import org.nuxeo.ecm.platform.preview.api.PreviewException;
029
030/**
031 * @author Alexandre Russel
032 */
033public class ImagePreviewer extends AbstractPreviewer implements MimeTypePreviewer {
034
035    public List<Blob> getPreview(Blob blob, DocumentModel dm) throws PreviewException {
036        List<Blob> blobResults = new ArrayList<Blob>();
037        StringBuffer htmlPage = new StringBuffer();
038        htmlPage.append("<html><head><title>");
039        htmlPage.append(getPreviewTitle(dm));
040        htmlPage.append("</title></head><body>");
041        appendPreviewSettings(htmlPage);
042        htmlPage.append("<img src=\"image\">");
043        Blob mainBlob = Blobs.createBlob(htmlPage.toString(), "text/html", null, "index.html");
044        blob.setFilename("image");
045        blobResults.add(mainBlob);
046        blobResults.add(blob);
047        return blobResults;
048    }
049
050    private static void appendPreviewSettings(StringBuffer sb) {
051        sb.append("<script type=\"text/javascript\">");
052        sb.append("var previewSettings = { ");
053        sb.append("imageOnly: true");
054        sb.append("}");
055        sb.append("</script>");
056    }
057
058}