Search in sources :

Example 1 with GeometryWriter

use of com.revolsys.geometry.io.GeometryWriter in project com.revolsys.open by revolsys.

the class GeometryHttpMessageConverter method write.

@Override
public void write(final Geometry geometry, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    if (!HttpServletUtils.getResponse().isCommitted()) {
        MediaType actualMediaType;
        if (mediaType == null) {
            actualMediaType = getDefaultMediaType();
        } else {
            actualMediaType = mediaType;
        }
        if (actualMediaType != null) {
            final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, actualMediaType);
            final OutputStream body = outputMessage.getBody();
            final String mediaTypeString = actualMediaType.getType() + "/" + actualMediaType.getSubtype();
            final GeometryWriterFactory writerFactory = IoFactory.factoryByMediaType(GeometryWriterFactory.class, mediaTypeString);
            if (writerFactory == null) {
                throw new IllegalArgumentException("Media type " + actualMediaType + " not supported");
            } else {
                final String baseName = HttpServletUtils.getRequestBaseFileName();
                final GeometryWriter writer = writerFactory.newGeometryWriter(baseName, body, charset);
                writer.write(geometry);
                writer.close();
            }
        }
    }
}
Also used : OutputStream(java.io.OutputStream) MediaType(org.springframework.http.MediaType) Charset(java.nio.charset.Charset) GeometryWriter(com.revolsys.geometry.io.GeometryWriter) GeometryWriterFactory(com.revolsys.geometry.io.GeometryWriterFactory)

Aggregations

GeometryWriter (com.revolsys.geometry.io.GeometryWriter)1 GeometryWriterFactory (com.revolsys.geometry.io.GeometryWriterFactory)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1 MediaType (org.springframework.http.MediaType)1