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.requests;
006:
007: import com.vividsolutions.jts.geom.Envelope;
008: import org.vfny.geoserver.global.FeatureTypeInfo;
009: import org.vfny.geoserver.global.MapLayerInfo;
010: import org.vfny.geoserver.wms.WmsException;
011: import org.vfny.geoserver.wms.servlets.WMService;
012: import java.util.List;
013: import java.util.Map;
014: import java.util.logging.Logger;
015:
016: /**
017: * GetKMLReflectKvpReader:
018: *
019: * This class is a refinement of GetMapKvpReader. It just moves some
020: * of the mandatory parameters to "optional" parameters. This is to allow
021: * the kml reflector (KMLReflector) to accept brief/simple requests and it
022: * will fill in the rest of the information.
023: *
024: * @author Brent Owens
025: *
026: */
027: public class GetKMLReflectKvpReader extends GetMapKvpReader {
028: private static final Logger LOGGER = org.geotools.util.logging.Logging
029: .getLogger("org.vfny.geoserver.requests.readers.wms");
030:
031: public GetKMLReflectKvpReader(Map kvpPairs, WMService service) {
032: super (kvpPairs, service);
033: setStylesRequired(false);
034: }
035:
036: /**
037: * Optional parameters are:
038: * width
039: * height
040: * format
041: */
042: public void parseOptionalParameters(GetMapRequest request)
043: throws WmsException {
044: super .parseOptionalParameters(request);
045:
046: // pulled out some of the mandatory params from superclass and made them optional:
047: if (keyExists("WIDTH") && keyExists("HEIGHT")) {
048: try {
049: int width = Integer.parseInt(getValue("WIDTH"));
050: int height = Integer.parseInt(getValue("HEIGHT"));
051: request.setWidth(width);
052: request.setHeight(height);
053: } catch (NumberFormatException ex) {
054: throw new WmsException(
055: "WIDTH and HEIGHT incorrectly specified, they must be integers");
056: }
057: }
058:
059: // FORMAT parameter, this might be KML, KMZ, or an image
060: if (keyExists("FORMAT")) {
061: String format = getValue("FORMAT");
062: request.setFormat(format);
063: }
064: }
065:
066: /**
067: * Mandatory parameters are 'bbox' and 'layers'. Styles are optional, but they
068: * are parsed at the same time as layers.
069: */
070: public void parseMandatoryParameters(GetMapRequest request,
071: boolean parseStylesLayers) throws WmsException {
072: Envelope bbox = parseBbox(getValue("BBOX"));
073: request.setBbox(bbox);
074:
075: //let styles and layers parsing for the end to give more trivial parameters
076: //a chance to fail before incurring in retrieving the SLD or SLD_BODY
077: if (parseStylesLayers) {
078: parseLayersAndStyles(request);
079: }
080: }
081:
082: /**
083: * Changed from the parent class to allow for missing style parameter.
084: * The parameter is optional now.
085: */
086: protected void parseLayersAndStyles(GetMapRequest request)
087: throws WmsException {
088: String sldParam = getValue("SLD");
089: String sldBodyParam = getValue("SLD_BODY");
090:
091: if (sldBodyParam != null) {
092: LOGGER.fine("Getting layers and styles from SLD_BODY");
093: parseSldBodyParam(request);
094: } else if (sldParam != null) {
095: LOGGER.fine("Getting layers and styles from reomte SLD");
096: parseSldParam(request);
097: } else {
098: MapLayerInfo[] featureTypes = parseLayersParam(request);
099: List styles = null;
100: request.setLayers(featureTypes);
101:
102: if (isStylesRquired()) {
103: styles = parseStylesParam(request, featureTypes);
104: request.setStyles(styles);
105: } else {
106: if (keyExists("STYLES")) {
107: styles = parseStylesParam(request, featureTypes);
108: request.setStyles(styles);
109: }
110: }
111: }
112: }
113: }
|