001/* 002 * (C) Copyright 2012 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 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 * Thierry Delprat 018 */ 019package org.nuxeo.template.xdocreport.jaxrs; 020 021import java.io.IOException; 022import java.io.OutputStream; 023import java.lang.annotation.Annotation; 024import java.lang.reflect.Type; 025 026import javax.ws.rs.WebApplicationException; 027import javax.ws.rs.core.MediaType; 028import javax.ws.rs.core.MultivaluedMap; 029import javax.ws.rs.ext.MessageBodyWriter; 030 031import fr.opensagres.xdocreport.remoting.resources.domain.Resource; 032 033/** 034 * @author <a href="mailto:[email protected]">Tiry</a> 035 */ 036public class ResourceMessageWriter implements MessageBodyWriter<Resource> { 037 038 @Override 039 public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { 040 return Resource.class.isAssignableFrom(type); 041 } 042 043 @Override 044 public long getSize(Resource t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { 045 return -1; 046 } 047 048 @Override 049 public void writeTo(Resource res, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, 050 MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException, WebApplicationException { 051 JSONHelper.writeResource(res, out); 052 } 053 054}