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.svg;
006:
007: import org.vfny.geoserver.config.WMSConfig;
008: import org.vfny.geoserver.global.WMS;
009: import org.vfny.geoserver.wms.GetMapProducer;
010: import org.vfny.geoserver.wms.GetMapProducerFactorySpi;
011: import java.util.Collections;
012: import java.util.Map;
013: import java.util.Set;
014:
015: /**
016: * DOCUMENT ME!
017: *
018: * @author Gabriel Roldan, Axios Engineering
019: * @version $Id: SvgMapProducerFactory.java 6326 2007-03-15 18:36:40Z jdeolive $
020: */
021: public class SvgMapProducerFactory implements GetMapProducerFactorySpi {
022: /**
023: * this is just to check the requested mime type starts with this string,
024: * since the most common error when performing the HTTP request is not to
025: * escape the '+' sign in "image/svg+xml", which is decoded as a space
026: * character at server side.
027: */
028: private static final String PRODUCE_TYPE = "image/svg";
029:
030: /** DOCUMENT ME! */
031: static final String MIME_TYPE = "image/svg+xml";
032:
033: /** DOCUMENT ME! */
034: private static final Set SUPPORTED_FORMATS = Collections
035: .singleton(MIME_TYPE);
036:
037: /**
038: * Creates a new SvgMapProducerFactory object.
039: */
040: public SvgMapProducerFactory() {
041: super ();
042: }
043:
044: /**
045: * DOCUMENT ME!
046: *
047: * @return DOCUMENT ME!
048: */
049: public String getName() {
050: return "Scalable Vector Graphics (SVG) map producer";
051: }
052:
053: /**
054: * DOCUMENT ME!
055: *
056: * @return DOCUMENT ME!
057: */
058: public Set getSupportedFormats() {
059: return SUPPORTED_FORMATS;
060: }
061:
062: /**
063: * By now SVG map producer does not have external dependencied (such as
064: * Batik), so just returns <code>true</code>.
065: *
066: * <p>
067: * It is most probable that this situation change in the future, like when
068: * adding Styling support.
069: * </p>
070: *
071: * @return <code>true</code>
072: */
073: public boolean isAvailable() {
074: return true;
075: }
076:
077: /**
078: * evaluates if this Map producer can generate the map format specified by
079: * <code>mapFormat</code>
080: *
081: * <p>
082: * In this case, true if <code>mapFormat</code> starts with "image/svg", as
083: * both <code>"image/svg"</code> and <code>"image/svg+xml"</code> are
084: * commonly passed.
085: * </p>
086: *
087: * @param mapFormat the mime type of the output map format requiered
088: *
089: * @return true if class can produce a map in the passed format.
090: */
091: public boolean canProduce(String mapFormat) {
092: return (mapFormat != null)
093: && mapFormat.startsWith(PRODUCE_TYPE);
094: }
095:
096: /**
097: * Returns an svg renderer based on the current wms configuration.
098: *
099: * @param mapFormat DOCUMENT ME!
100: *
101: * @return DOCUMENT ME!
102: *
103: * @throws IllegalArgumentException DOCUMENT ME!
104: */
105: public GetMapProducer createMapProducer(String mapFormat, WMS wms)
106: throws IllegalArgumentException {
107: if (wms != null) {
108: if (WMSConfig.SVG_SIMPLE.equals(wms.getSvgRenderer())) {
109: return new SVGMapProducer();
110: }
111:
112: if (WMSConfig.SVG_BATIK.equals(wms.getSvgRenderer())) {
113: return new SVGBatikMapProducer(wms);
114: }
115: }
116:
117: //do the default
118: return new SVGMapProducer();
119: }
120:
121: /* (non-Javadoc)
122: * @see org.geotools.factory.Factory#getImplementationHints()
123: * This just returns java.util.Collections.EMPTY_MAP
124: */
125: public Map getImplementationHints() {
126: return java.util.Collections.EMPTY_MAP;
127: }
128: }
|