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 * Andre Justo 019 * Miguel Nixo 020 * 021 * $Id$ 022 */ 023 024package org.nuxeo.ecm.platform.preview.adapter; 025 026import java.util.ArrayList; 027import java.util.List; 028 029import org.nuxeo.ecm.core.api.Blob; 030import org.nuxeo.ecm.core.api.Blobs; 031import org.nuxeo.ecm.core.api.DocumentModel; 032import org.nuxeo.ecm.platform.preview.api.PreviewException; 033import org.nuxeo.ecm.platform.web.common.vh.VirtualHostHelper; 034 035/** 036 * @author Alexandre Russel 037 */ 038public class ImagePreviewer extends AbstractPreviewer implements MimeTypePreviewer { 039 040 protected Blob getContentBlob(Blob original, DocumentModel doc) { 041 return original; 042 } 043 044 public List<Blob> getPreview(Blob blob, DocumentModel dm) throws PreviewException { 045 List<Blob> blobResults = new ArrayList<>(); 046 String basePath = VirtualHostHelper.getContextPathProperty(); 047 StringBuffer html = new StringBuffer(); 048 html.append("<html><head>"); 049 html.append("<title>" + getPreviewTitle(dm) + "</title>"); 050 html.append(String.format("<script src=\"%s/bower_components/webcomponentsjs/webcomponents-lite.js\"></script>", basePath)); 051 html.append(String.format("<link rel=\"import\" href=\"%s/viewers/nuxeo-image-viewer.vulcanized.html\">", basePath)); 052 html.append("<style>"); 053 html.append("nuxeo-image-viewer {"); 054 html.append("height: 100%; }"); 055 html.append("</style>"); 056 html.append("</head><body>"); 057 html.append("<nuxeo-image-viewer src=\"image\" controls responsive></nuxeo-image-viewer>"); 058 html.append("</body>"); 059 Blob mainBlob = Blobs.createBlob(html.toString(), "text/html", null, "index.html"); 060 blobResults.add(mainBlob); 061 Blob content = getContentBlob(blob, dm); 062 content.setFilename("image"); 063 blobResults.add(content); 064 return blobResults; 065 } 066}