001/* 002 * (C) Copyright 2014 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-2.1.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 * <a href="mailto:grenard@nuxeo.com">Guillaume Renard</a> 016 * 017 */ 018 019package org.nuxeo.ecm.restapi.server.jaxrs.routing.io; 020 021import java.io.IOException; 022import java.util.Map.Entry; 023 024import javax.servlet.http.HttpServletRequest; 025import javax.ws.rs.Produces; 026import javax.ws.rs.core.Context; 027import javax.ws.rs.core.HttpHeaders; 028import javax.ws.rs.core.MediaType; 029import javax.ws.rs.ext.Provider; 030 031import org.codehaus.jackson.JsonFactory; 032import org.codehaus.jackson.JsonGenerator; 033import org.nuxeo.ecm.automation.jaxrs.io.EntityWriter; 034import org.nuxeo.ecm.platform.routing.core.impl.jsongraph.JsonGraphRoute; 035 036@Provider 037@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON + "+nxentity" }) 038public class GraphRouteWriter extends EntityWriter<JsonGraphRoute> { 039 040 @Context 041 JsonFactory factory; 042 043 @Context 044 protected HttpHeaders headers; 045 046 @Context 047 protected HttpServletRequest request; 048 049 @Override 050 protected String getEntityType() { 051 return "graph"; 052 } 053 054 @Override 055 protected void writeEntityBody(JsonGenerator jg, JsonGraphRoute item) throws IOException { 056 for (Entry<String, Object> e : item.getGraphElements().entrySet()) { 057 jg.writeObjectField(e.getKey(), e.getValue()); 058 } 059 } 060 061}