001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Alexandre Russel 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.preview.adapter; 023 024import java.util.ArrayList; 025import java.util.List; 026 027import org.nuxeo.ecm.core.api.Blob; 028import org.nuxeo.ecm.core.api.Blobs; 029import org.nuxeo.ecm.core.api.DocumentModel; 030import org.nuxeo.ecm.platform.preview.api.PreviewException; 031 032/** 033 * @author Alexandre Russel 034 */ 035public class ImagePreviewer extends AbstractPreviewer implements MimeTypePreviewer { 036 037 public List<Blob> getPreview(Blob blob, DocumentModel dm) throws PreviewException { 038 List<Blob> blobResults = new ArrayList<Blob>(); 039 StringBuffer htmlPage = new StringBuffer(); 040 htmlPage.append("<html><head><title>"); 041 htmlPage.append(getPreviewTitle(dm)); 042 htmlPage.append("</title></head><body>"); 043 appendPreviewSettings(htmlPage); 044 htmlPage.append("<img src=\"image\">"); 045 Blob mainBlob = Blobs.createBlob(htmlPage.toString(), "text/html", null, "index.html"); 046 blob.setFilename("image"); 047 blobResults.add(mainBlob); 048 blobResults.add(blob); 049 return blobResults; 050 } 051 052 private static void appendPreviewSettings(StringBuffer sb) { 053 sb.append("<script type=\"text/javascript\">"); 054 sb.append("var previewSettings = { "); 055 sb.append("imageOnly: true"); 056 sb.append("}"); 057 sb.append("</script>"); 058 } 059 060}