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