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.map.kml;
006:
007: import java.util.Collections;
008: import java.util.Map;
009: import java.util.Set;
010:
011: import org.vfny.geoserver.global.WMS;
012: import org.vfny.geoserver.wms.GetMapProducer;
013: import org.vfny.geoserver.wms.GetMapProducerFactorySpi;
014:
015: /**
016: * KMZMapProducerFactory This class is used as part of the SPI auto discovery
017: * process which enables new format producers to be plugged in.
018: *
019: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $
020: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $
021: * @version $Id: KMZMapProducerFactory.java 7467 2007-08-28 22:29:03Z afabiani $
022: */
023: public class KMZMapProducerFactory implements GetMapProducerFactorySpi {
024: /**
025: * this is just to check the requested mime type starts with this string,
026: * since the most common error when performing the HTTP request is not to
027: * escape the '+' sign in "kml+xml", which is decoded as a space character
028: * at server side.
029: */
030: private static final String PRODUCE_TYPE = "kmz";
031:
032: /**
033: * Official KMZ mime type
034: */
035: static final String MIME_TYPE = "application/vnd.google-earth.kmz";
036:
037: /**
038: * Set of supported mime types for the producers made by this Factory
039: */
040: private static final Set SUPPORTED_FORMATS = Collections
041: .singleton(MIME_TYPE);
042:
043: /**
044: * Creates a new KMZMapProducerFactory object.
045: */
046: public KMZMapProducerFactory() {
047: }
048:
049: /**
050: * Human readable description of output format.
051: */
052: public String getName() {
053: return "Keyhole markup language compressed producer";
054: }
055:
056: /**
057: * Discover what output formats are supported by the producers made by this
058: * factory.
059: *
060: * @return Set of supported mime types
061: */
062: public Set getSupportedFormats() {
063: return SUPPORTED_FORMATS;
064: }
065:
066: /**
067: * Reports on the availability of this factory. As no external libraries are
068: * required for KMZ this should always be true.
069: *
070: * @return <code>true</code>
071: */
072: public boolean isAvailable() {
073: return true;
074: }
075:
076: /**
077: * evaluates if this Map producer can generate the map format specified by
078: * <code>mapFormat</code>
079: *
080: * @param mapFormat
081: * the mime type of the output map format requiered
082: *
083: * @return true if class can produce a map in the passed format.
084: */
085: public boolean canProduce(String mapFormat) {
086: return (mapFormat != null)
087: && (mapFormat.startsWith(PRODUCE_TYPE) // "KMZ"
088: || mapFormat
089: .startsWith("application/vnd.google-earth.kmz"));
090: }
091:
092: /**
093: * Create an actual instance of a KMZMapProducer.
094: *
095: * @param mapFormat
096: * String which MUST match the supported formats. Call canProcess
097: * fisrt if you are unsure.
098: *
099: * @return GetMapProducer instance.
100: *
101: * @throws IllegalArgumentException
102: * DOCUMENT ME!
103: */
104: public GetMapProducer createMapProducer(String mapFormat, WMS wms)
105: throws IllegalArgumentException {
106: if (canProduce(mapFormat)) {
107: return new KMZMapProducer(mapFormat, MIME_TYPE, wms);
108: }
109:
110: throw new IllegalArgumentException("Unable to produce format "
111: + mapFormat);
112: }
113:
114: /*
115: * (non-Javadoc)
116: *
117: * @see org.geotools.factory.Factory#getImplementationHints() This just
118: * returns java.util.Collections.EMPTY_MAP
119: */
120: public Map getImplementationHints() {
121: return java.util.Collections.EMPTY_MAP;
122: }
123: }
|