/*
 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Alexandre Russel
 *
 * $Id$
 */

package org.nuxeo.ecm.platform.preview.adapter;

import java.util.ArrayList;
import java.util.List;

import org.nuxeo.ecm.core.api.Blob;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.impl.blob.StringBlob;
import org.nuxeo.ecm.platform.preview.api.PreviewException;

/**
 * @author Alexandre Russel
 *
 */
public class ImagePreviewer extends AbstractPreviewer implements
        MimeTypePreviewer {

    public List<Blob> getPreview(Blob blob, DocumentModel dm) throws PreviewException {
        List<Blob> blobResults = new ArrayList<Blob>();

        try {
        StringBuffer htmlPage = new StringBuffer();
        String description = (String) dm.getProperty("dublincore",
                "description");

        htmlPage.append("<html><head><title>");
        htmlPage.append(getPreviewTitle(dm));
        htmlPage.append("</title></head><body>");
        appendPreviewSettings(htmlPage);
        htmlPage.append("<img src=\"image\">");
        if (description != null) {
            htmlPage.append("<br />");
            htmlPage.append(description);
        }

        Blob mainBlob = new StringBlob(htmlPage.toString());
        mainBlob.setFilename("index.html");
        mainBlob.setMimeType("text/html");
        blob.setFilename("image");

        blobResults.add(mainBlob);
        blobResults.add(blob);
        } catch (ClientException e) {
            throw new PreviewException("Unable to get document property", e);
        }

        return blobResults;
    }
    
    protected void appendPreviewSettings(StringBuffer sb) {
    	sb.append("<script type=\"text/javascript\">");
    	sb.append("var previewSettings = { ");
    	sb.append("imageOnly: true");
    	sb.append("}");
    	sb.append("</script>");
    }

}

@@ -1345,107 +1345,8 @@
 r();
-%0A        String description = (String) dm.getProperty(%22dublincore%22,%0A                %22description%22);
 %0A%0A  
@@ -1579,134 +1579,8 @@
 %3E%22);
-%0A        if (description != null) %7B%0A            htmlPage.append(%22%3Cbr /%3E%22);%0A            htmlPage.append(description);%0A        %7D
 %0A%0A  
@@ -1992,13 +1992,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -2049,25 +2049,28 @@
 r sb) %7B%0A    
-%09
+    
 sb.append(%22%3C
@@ -2101,33 +2101,36 @@
 cript%5C%22%3E%22);%0A    
-%09
+    
 sb.append(%22var p
@@ -2148,33 +2148,36 @@
 ngs = %7B %22);%0A    
+   
-%09
+ 
 sb.append(%22image
@@ -2186,33 +2186,36 @@
 ly: true%22);%0A    
-%09
+    
 sb.append(%22%7D%22);%0A
@@ -2222,9 +2222,12 @@
     
-%09
+    
 sb.a

remove the description on the image preview