Search in sources :

Example 1 with MapWriterFactory

use of com.revolsys.io.map.MapWriterFactory in project com.revolsys.open by revolsys.

the class ListOfMapHttpMessageConverter method write.

@SuppressWarnings("unchecked")
@Override
public void write(final ArrayListOfMap list, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    if (!HttpServletUtils.getResponse().isCommitted()) {
        final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, mediaType);
        final OutputStream body = outputMessage.getBody();
        final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
        final MapWriterFactory writerFactory = IoFactory.factoryByMediaType(MapWriterFactory.class, mediaTypeString);
        final MapWriter writer = writerFactory.newMapWriter(body, charset);
        writer.setProperty(IoConstants.INDENT, true);
        writer.setProperty(IoConstants.SINGLE_OBJECT_PROPERTY, false);
        final HttpServletRequest request = HttpServletUtils.getRequest();
        writer.setProperty(IoConstants.JSON_LIST_ROOT_PROPERTY, request.getAttribute(IoConstants.JSON_LIST_ROOT_PROPERTY));
        String callback = request.getParameter("jsonp");
        if (callback == null) {
            callback = request.getParameter("callback");
        }
        if (callback != null) {
            writer.setProperty(IoConstants.JSONP_PROPERTY, callback);
        }
        for (final Map<String, Object> map : (ArrayListOfMap<Object>) list) {
            writer.write(map);
        }
        writer.close();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MapWriter(com.revolsys.io.map.MapWriter) OutputStream(java.io.OutputStream) MapWriterFactory(com.revolsys.io.map.MapWriterFactory) ArrayListOfMap(com.revolsys.collection.ArrayListOfMap) Charset(java.nio.charset.Charset)

Example 2 with MapWriterFactory

use of com.revolsys.io.map.MapWriterFactory in project com.revolsys.open by revolsys.

the class PageInfoHttpMessageConverter method writeResourceList.

public void writeResourceList(final MediaType mediaType, Charset charset, final OutputStream out, final String url, final PageInfo pageInfo) {
    if (charset == null) {
        charset = StandardCharsets.UTF_8;
    }
    final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
    final MapWriterFactory writerFactory = IoFactory.factoryByMediaType(MapWriterFactory.class, mediaTypeString);
    if (writerFactory != null) {
        final MapWriter writer = writerFactory.newMapWriter(out, charset);
        writer.setProperty(IoConstants.INDENT, true);
        writer.setProperty(IoConstants.SINGLE_OBJECT_PROPERTY, true);
        final HttpServletRequest request = HttpServletUtils.getRequest();
        String callback = request.getParameter("jsonp");
        if (callback == null) {
            callback = request.getParameter("callback");
        }
        if (callback != null) {
            writer.setProperty(IoConstants.JSONP_PROPERTY, callback);
        }
        final Map<String, Object> page = getMap(url, pageInfo);
        writer.write(page);
        writer.close();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MapWriter(com.revolsys.io.map.MapWriter) MapWriterFactory(com.revolsys.io.map.MapWriterFactory)

Example 3 with MapWriterFactory

use of com.revolsys.io.map.MapWriterFactory in project com.revolsys.open by revolsys.

the class MapHttpMessageConverter method write.

@SuppressWarnings("unchecked")
@Override
public void write(final Map map, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    if (!HttpServletUtils.getResponse().isCommitted()) {
        final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, mediaType);
        final OutputStream body = outputMessage.getBody();
        final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
        final MapWriterFactory writerFactory = IoFactory.factoryByMediaType(MapWriterFactory.class, mediaTypeString);
        final MapWriter writer = writerFactory.newMapWriter(body, charset);
        writer.setProperty(IoConstants.INDENT, true);
        writer.setProperty(IoConstants.SINGLE_OBJECT_PROPERTY, true);
        final HttpServletRequest request = HttpServletUtils.getRequest();
        String callback = request.getParameter("jsonp");
        if (callback == null) {
            callback = request.getParameter("callback");
        }
        if (callback != null) {
            writer.setProperty(IoConstants.JSONP_PROPERTY, callback);
        }
        final Object title = request.getAttribute(IoConstants.TITLE_PROPERTY);
        if (title != null) {
            writer.setProperty(IoConstants.TITLE_PROPERTY, title);
        }
        writer.write(map);
        writer.close();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MapWriter(com.revolsys.io.map.MapWriter) OutputStream(java.io.OutputStream) MapWriterFactory(com.revolsys.io.map.MapWriterFactory) Charset(java.nio.charset.Charset)

Aggregations

MapWriter (com.revolsys.io.map.MapWriter)3 MapWriterFactory (com.revolsys.io.map.MapWriterFactory)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 OutputStream (java.io.OutputStream)2 Charset (java.nio.charset.Charset)2 ArrayListOfMap (com.revolsys.collection.ArrayListOfMap)1