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 */
036@Deprecated
037public class PlainImagePreviewer extends AbstractPreviewer implements MimeTypePreviewer {
038
039    @Override
040    public List<Blob> getPreview(Blob blob, DocumentModel dm) throws PreviewException {
041        List<Blob> blobResults = new ArrayList<>();
042        StringBuilder htmlPage = new StringBuilder();
043        htmlPage.append("<html><head><title>");
044        htmlPage.append(getPreviewTitle(dm));
045        htmlPage.append("</title></head><body>");
046        appendPreviewSettings(htmlPage);
047        htmlPage.append("<img src=\"image\">");
048        Blob mainBlob = Blobs.createBlob(htmlPage.toString(), "text/html", null, "index.html");
049        blob.setFilename("image");
050        blobResults.add(mainBlob);
051        blobResults.add(blob);
052        return blobResults;
053    }
054
055    private static void appendPreviewSettings(StringBuilder sb) {
056        sb.append("<script type=\"text/javascript\">");
057        sb.append("var previewSettings = { ");
058        sb.append("imageOnly: true");
059        sb.append("}");
060        sb.append("</script>");
061    }
062
063}