01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver.wms.responses.legend.jai;
06:
07: import org.vfny.geoserver.ServiceException;
08: import org.vfny.geoserver.wms.WmsException;
09: import org.vfny.geoserver.wms.requests.GetLegendGraphicRequest;
10: import org.vfny.geoserver.wms.responses.DefaultRasterLegendProducer;
11: import org.vfny.geoserver.wms.responses.helpers.JAISupport;
12: import java.io.IOException;
13: import java.io.OutputStream;
14:
15: /**
16: * Producer of legend graphics in all the formats available through JAI.
17: *
18: * @author Gabriel Roldan, Axios Engineering
19: * @version $Id: JaiLegendGraphicProducer.java 7728 2007-11-09 01:53:31Z groldan $
20: */
21: class JaiLegendGraphicProducer extends DefaultRasterLegendProducer {
22: /** holds the desired output format MIME type */
23: private String outputFormat;
24:
25: /**
26: * Creates a new JAI based legend producer for creating
27: * <code>outputFormat</code> type images.
28: *
29: * @param outputFormat DOCUMENT ME!
30: */
31: JaiLegendGraphicProducer(String outputFormat) {
32: super ();
33: this .outputFormat = outputFormat;
34: }
35:
36: /**
37: * Overrides to force request.isTransparent() to false when the output
38: * format is <code>image/jpeg</code>.
39: *
40: * @see DefaultRasterLegendProducer#produceLegendGraphic(GetLegendGraphicRequest)
41: */
42: public void produceLegendGraphic(GetLegendGraphicRequest request)
43: throws WmsException {
44: //HACK: should we provide a jpeg specific legend producer just
45: //like for GetMap?
46: if (outputFormat.startsWith("image/jpeg")) {
47: //no transparency in jpeg
48: request.setTransparent(false);
49: }
50: super .produceLegendGraphic(request);
51: }
52:
53: /**
54: * Encodes the image created by the superclss to the format specified at
55: * the constructor and sends it to <code>out</code>.
56: *
57: * @see org.vfny.geoserver.wms.responses.GetLegendGraphicProducer#writeTo(java.io.OutputStream)
58: */
59: public void writeTo(OutputStream out) throws IOException,
60: ServiceException {
61: JAISupport.encode(this .outputFormat, super .getLegendGraphic(),
62: out);
63: }
64:
65: /**
66: * Returns the MIME type in which the legend graphic will be encoded.
67: *
68: * @see org.vfny.geoserver.wms.responses.GetLegendGraphicProducer#getContentType()
69: */
70: public String getContentType() throws IllegalStateException {
71: return this.outputFormat;
72: }
73: }
|