001: /* Copyright (c) 2001, 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.wms.responses;
006:
007: import org.geotools.renderer.GTRenderer;
008: import org.vfny.geoserver.wms.GetMapProducer;
009: import org.vfny.geoserver.wms.WMSMapContext;
010:
011: /**
012: *
013: * @author Simone Giannecchini, GeoSolutions
014: *
015: */
016: public abstract class AbstractGetMapProducer implements GetMapProducer {
017: /**
018: * Holds the map context passed to produceMap, so subclasses can use it if
019: * they need it from inside {@linkPlain #formatImageOutputStream(String,
020: * BufferedImage, OutputStream)}
021: */
022: protected WMSMapContext mapContext;
023:
024: /**
025: * set to <code>true</code> on <code>abort()</code> so
026: * <code>produceMap</code> leaves the image being worked on to the garbage
027: * collector.
028: */
029: protected boolean abortRequested;
030:
031: /**
032: * The one to do the magic of rendering a map
033: */
034: protected GTRenderer renderer;
035:
036: /**
037: * Set in produceMap(...) from the requested output format, it's holded just
038: * to be sure that method has been called before getContentType() thus
039: * supporting the workflow contract of the request processing
040: */
041: protected String format;
042: protected String mime;
043:
044: public AbstractGetMapProducer(String format, String mime) {
045: this .format = format;
046: this .mime = mime;
047: }
048:
049: public AbstractGetMapProducer() {
050: }
051:
052: /**
053: * @see GetMapProducer#setMapContext(WMSMapContext)
054: */
055: public void setMapContext(WMSMapContext mapContext) {
056: this .mapContext = mapContext;
057: }
058:
059: /**
060: * @see GetMapProducer#getMapContext()
061: */
062: public WMSMapContext getMapContext() {
063: return this .mapContext;
064: }
065:
066: /**
067: * Halts the loading. Right now just calls renderer.stopRendering.
068: */
069: public void abort() {
070: this .abortRequested = true;
071:
072: if (this .renderer != null) {
073: this .renderer.stopRendering();
074: }
075: }
076:
077: /**
078: * returns the content encoding for the output data (null for this class)
079: *
080: * @return <code>null</code> since no special encoding is performed while
081: * wrtting to the output stream. Do not confuse this with
082: * getMimeType().
083: */
084: public String getContentEncoding() {
085: return null;
086: }
087:
088: /**
089: * Gets the content type. This is set by the request, should only be called
090: * after execute. GetMapResponse should handle this though.
091: *
092: * @return The mime type that this response will generate.
093: *
094: * @throws IllegalStateException
095: * DOCUMENT ME!
096: */
097: public String getContentType()
098: throws java.lang.IllegalStateException {
099: return mime;
100: }
101:
102: public void setContentType(String mime) {
103: this .mime = mime;
104: }
105:
106: public String getOutputFormat() {
107: return format;
108: }
109:
110: public void setOutputFormat(String outputFormat) {
111: this .format = outputFormat;
112: }
113:
114: public String getContentDisposition() {
115: return null;
116: }
117: }
|