001package org.nuxeo.template.xdocreport.jaxrs; 002 003import java.io.IOException; 004 005import org.nuxeo.ecm.core.api.Blob; 006import org.nuxeo.ecm.core.api.Blobs; 007import org.nuxeo.template.api.adapters.TemplateSourceDocument; 008 009import fr.opensagres.xdocreport.remoting.resources.domain.LargeBinaryData; 010 011/** 012 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 013 */ 014public class BinaryDataWrapper { 015 016 public static LargeBinaryData wrap(Blob blob) throws IOException { 017 018 LargeBinaryData data = new LargeBinaryData(); 019 data.setContent(blob.getStream()); 020 data.setFileName(blob.getFilename()); 021 data.setMimeType(blob.getMimeType()); 022 if (blob.getLength() > 0) { 023 data.setLength(blob.getLength()); 024 } 025 return data; 026 } 027 028 public static LargeBinaryData wrap(TemplateSourceDocument template) throws IOException { 029 Blob blob = template.getTemplateBlob(); 030 LargeBinaryData data = wrap(blob); 031 data.setResourceId(template.getAdaptedDoc().getId()); 032 return data; 033 } 034 035 public static LargeBinaryData wrapXml(String xml, String fileName) throws IOException { 036 Blob blob = Blobs.createBlob(xml, "text/xml", null, fileName); 037 return wrap(blob); 038 } 039 040}