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 org.vfny.geoserver.Request;
008: import org.vfny.geoserver.ServiceException;
009: import org.vfny.geoserver.global.CoverageInfo;
010: import org.vfny.geoserver.global.Data;
011: import org.vfny.geoserver.global.FeatureTypeInfo;
012: import org.vfny.geoserver.global.MapLayerInfo;
013: import org.vfny.geoserver.wms.WmsException;
014: import org.vfny.geoserver.wms.servlets.WMService;
015: import java.util.List;
016: import java.util.Map;
017: import java.util.NoSuchElementException;
018: import java.util.logging.Level;
019: import java.util.logging.Logger;
020: import javax.servlet.http.HttpServletRequest;
021:
022: /**
023: * Parses a DescribeLayer request, wich consists only of a list of
024: * layer names, given by the <code>"LAYER"</code> parameter.
025: *
026: *
027: * @author Gabriel Roldan, Axios Engineering
028: * @version $Id: DescribeLayerKvpRequestReader.java 7746 2007-11-13 15:38:35Z aaime $
029: */
030: public class DescribeLayerKvpRequestReader extends WmsKvpRequestReader {
031: /** package's logger */
032: private static final Logger LOGGER = org.geotools.util.logging.Logging
033: .getLogger(DescribeLayerKvpRequestReader.class.getPackage()
034: .getName());
035:
036: /**
037: * Constructs a new DescribeLayer request parser.
038: * @param params
039: * @param service The service that handles the request
040: */
041: public DescribeLayerKvpRequestReader(Map params, WMService service) {
042: super (params, service);
043: }
044:
045: /**
046: * Does the request parsing and constructs a <code>DescribeLayerRequest</code>,
047: * wich holds the requiered layers as <code>FeatureTypeInfo</code> references.
048: *
049: * @param request the original request.
050: *
051: * @return the parsed and validated <code>DescribeLayerRequest</code>
052: *
053: * @throws ServiceException see "throws WmsException"...
054: * @throws WmsException if no layers has been requested, or
055: * one of the requested layers does not exists on this
056: * server instance.
057: */
058: public Request getRequest(HttpServletRequest request)
059: throws ServiceException {
060: DescribeLayerRequest req = new DescribeLayerRequest(
061: (WMService) service);
062: req.setHttpServletRequest(request);
063:
064: String layersParam = getValue("LAYERS");
065:
066: if (LOGGER.isLoggable(Level.FINE)) {
067: LOGGER.fine(layersParam);
068: }
069:
070: List layers = readFlat(layersParam, INNER_DELIMETER);
071:
072: if (LOGGER.isLoggable(Level.FINE)) {
073: LOGGER.fine(layers.toString());
074: }
075:
076: int layerCount = layers.size();
077:
078: if (layerCount == 0) {
079: throw new WmsException("No LAYERS has been requested",
080: getClass().getName());
081: }
082:
083: Data catalog = req.getWMS().getData();
084:
085: if (LOGGER.isLoggable(Level.FINE)) {
086: LOGGER.fine(catalog.toString());
087: }
088:
089: String layerName = null;
090: MapLayerInfo layer = null;
091:
092: for (int i = 0; i < layerCount; i++) {
093: layerName = (String) layers.get(i);
094:
095: if (LOGGER.isLoggable(Level.FINE)) {
096: LOGGER.fine(new StringBuffer("Looking for layer ")
097: .append(layerName).toString());
098: }
099:
100: try {
101: if (LOGGER.isLoggable(Level.FINE)) {
102: LOGGER.fine("looking featuretypeinfos");
103: }
104:
105: FeatureTypeInfo ftype = catalog
106: .getFeatureTypeInfo(layerName);
107: layer = new MapLayerInfo();
108: layer.setFeature(ftype);
109: req.addLayer(layer);
110: } catch (NoSuchElementException fex) {
111: try {
112: if (LOGGER.isLoggable(Level.FINE)) {
113: LOGGER.fine("looking coverageinfos");
114: }
115:
116: CoverageInfo cinfo = catalog
117: .getCoverageInfo(layerName);
118: layer = new MapLayerInfo();
119: layer.setCoverage(cinfo);
120: req.addLayer(layer);
121:
122: if (LOGGER.isLoggable(Level.FINE)) {
123: LOGGER.fine(new StringBuffer(layerName).append(
124: " found").toString());
125: }
126: } catch (NoSuchElementException cex) {
127: throw new WmsException(cex, layerName
128: + ": no such layer on this server",
129: "LayerNotDefined");
130: }
131:
132: if (LOGGER.isLoggable(Level.FINE)) {
133: LOGGER.fine(new StringBuffer(layerName).append(
134: " found").toString());
135: }
136: }
137: }
138:
139: if (LOGGER.isLoggable(Level.FINE)) {
140: LOGGER.fine(new StringBuffer("parsed request ").append(req)
141: .toString());
142: }
143:
144: return req;
145: }
146: }
|