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