001package org.nuxeo.template.xdocreport.jaxrs; 002 003import java.io.IOException; 004import java.io.OutputStream; 005import java.lang.annotation.Annotation; 006import java.lang.reflect.Type; 007 008import javax.ws.rs.WebApplicationException; 009import javax.ws.rs.core.MediaType; 010import javax.ws.rs.core.MultivaluedMap; 011import javax.ws.rs.ext.MessageBodyWriter; 012 013import fr.opensagres.xdocreport.remoting.resources.domain.Resource; 014 015/** 016 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 017 */ 018public class ResourceMessageWriter implements MessageBodyWriter<Resource> { 019 020 @Override 021 public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { 022 return Resource.class.isAssignableFrom(type); 023 } 024 025 @Override 026 public long getSize(Resource t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { 027 return -1; 028 } 029 030 @Override 031 public void writeTo(Resource res, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, 032 MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException, WebApplicationException { 033 JSONHelper.writeResource(res, out); 034 } 035 036}