use of com.revolsys.io.map.MapWriter 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();
}
}
use of com.revolsys.io.map.MapWriter 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();
}
}
use of com.revolsys.io.map.MapWriter 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();
}
}
Aggregations