001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.forms.layout.export; 018 019import java.io.IOException; 020import java.io.OutputStream; 021import java.lang.annotation.Annotation; 022import java.lang.reflect.Type; 023 024import javax.ws.rs.Produces; 025import javax.ws.rs.WebApplicationException; 026import javax.ws.rs.core.MediaType; 027import javax.ws.rs.core.MultivaluedMap; 028import javax.ws.rs.ext.MessageBodyWriter; 029import javax.ws.rs.ext.Provider; 030 031import org.nuxeo.ecm.platform.forms.layout.api.WidgetTypeDefinition; 032import org.nuxeo.ecm.platform.forms.layout.io.JSONLayoutExporter; 033 034/** 035 * @author Anahide Tchertchian 036 * @since 5.4 037 */ 038@Provider 039@Produces({ "application/json", "text/plain" }) 040public class WidgetTypeDefinitionJsonWriter implements MessageBodyWriter<WidgetTypeDefinition> { 041 042 @Override 043 public long getSize(WidgetTypeDefinition arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) { 044 return -1; 045 } 046 047 @Override 048 public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) { 049 return WidgetTypeDefinition.class.isAssignableFrom(arg0); 050 } 051 052 @Override 053 public void writeTo(WidgetTypeDefinition arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, 054 MultivaluedMap<String, Object> arg5, OutputStream arg6) throws IOException, WebApplicationException { 055 JSONLayoutExporter.export(arg0, arg6); 056 } 057 058}