001/* 002 * (C) Copyright 2016 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 git lat 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 * Andre Justo 018 */ 019 020package org.nuxeo.ecm.platform.preview.adapter; 021 022import org.nuxeo.ecm.core.api.Blob; 023import org.nuxeo.ecm.core.api.Blobs; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.platform.preview.api.PreviewException; 026import org.nuxeo.ecm.platform.web.common.vh.VirtualHostHelper; 027 028import java.util.ArrayList; 029import java.util.Arrays; 030import java.util.List; 031 032/** 033 * @since 8.2 034 */ 035public class VideoPreviewer extends AbstractPreviewer implements MimeTypePreviewer { 036 037 public List<Blob> getPreview(Blob blob, DocumentModel dm) throws PreviewException { 038 List<Blob> blobs = Arrays.asList(blob); 039 return buildPreview(blobs, dm); 040 } 041 042 protected List<Blob> buildPreview(List<Blob> blobs, DocumentModel dm) { 043 List<Blob> blobResults = new ArrayList<>(); 044 String basePath = VirtualHostHelper.getContextPathProperty(); 045 StringBuffer html = new StringBuffer(); 046 html.append("<html><head>"); 047 html.append("<title>" + getPreviewTitle(dm) + "</title>"); 048 html.append(String.format( 049 "<script src=\"%s/bower_components/webcomponentsjs/webcomponents-lite.js\"></script>", basePath)); 050 html.append(String.format("<link rel=\"import\" href=\"%s/viewers/nuxeo-video-viewer.vulcanized.html\">", 051 basePath)); 052 html.append("<nuxeo-video-viewer controls>"); 053 for (Blob blob : blobs) { 054 html.append(String.format("<source src=\"%s\" type=\"%s\" />", blob.getFilename(), blob.getMimeType())); 055 blobResults.add(blob); 056 } 057 html.append("</nuxeo-video-viewer>"); 058 html.append("</body>"); 059 Blob mainBlob = Blobs.createBlob(html.toString(), "text/html", null, "index.html"); 060 blobResults.add(0, mainBlob); 061 return blobResults; 062 } 063}