001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.wms.request;
017:
018: import java.io.UnsupportedEncodingException;
019: import java.net.URL;
020: import java.net.URLEncoder;
021: import java.util.Iterator;
022: import java.util.Set;
023: import java.util.TreeSet;
024:
025: import org.geotools.data.ows.AbstractRequest;
026: import org.geotools.data.ows.Layer;
027:
028: /**
029: * A base class for GetFeatureInfoRequests that provides some
030: * functionality.
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wms/src/main/java/org/geotools/data/wms/request/AbstractGetFeatureInfoRequest.java $
032: */
033: public abstract class AbstractGetFeatureInfoRequest extends
034: AbstractWMSRequest implements GetFeatureInfoRequest {
035: /** A set of type Layer, each of which is to be queried in the request */
036: private Set queryLayers;
037:
038: /**
039: * Constructs a GetFeatureInfoRequest. It will set the REQUEST and VERSION
040: * parameters, over-writing and values set there previously.
041: *
042: * @param onlineResource the URL pointing to the place to execute a GetFeatureInfo request
043: * @param request a previously configured GetMapRequest that the query will be executed on
044: */
045: public AbstractGetFeatureInfoRequest(URL onlineResource,
046: GetMapRequest request) {
047: super (onlineResource, request.getProperties());
048:
049: queryLayers = new TreeSet();
050: }
051:
052: /**
053: * @see org.geotools.data.wms.request.Request#getFinalURL()
054: */
055: public URL getFinalURL() {
056: Iterator iter = queryLayers.iterator();
057: String initialQueryLayerString = properties
058: .getProperty(QUERY_LAYERS) == null ? "" : properties.getProperty(QUERY_LAYERS); //$NON-NLS-1$
059: String queryLayerString = properties.getProperty(QUERY_LAYERS) == null ? "" : properties.getProperty(QUERY_LAYERS); //$NON-NLS-1$
060:
061: while (iter.hasNext()) {
062: Layer layer = (Layer) iter.next();
063: try {
064: queryLayerString = queryLayerString
065: + URLEncoder.encode(layer.getName(), "UTF-8"); //$NON-NLS-1$
066: } catch (UnsupportedEncodingException e) {
067: queryLayerString = queryLayerString + layer.getName();
068: }
069:
070: if (iter.hasNext()) {
071: queryLayerString = queryLayerString + ","; //$NON-NLS-1$
072: }
073: }
074:
075: setProperty(QUERY_LAYERS, queryLayerString);
076: //need to add the querylayers to the LAYERS tag as well.
077: setProperty(GetMapRequest.LAYERS, queryLayerString);
078: URL url = super .getFinalURL();
079:
080: setProperty(QUERY_LAYERS, initialQueryLayerString);
081:
082: return url;
083: }
084:
085: /**
086: * @see org.geotools.data.wms.request.GetFeatureInfoRequest#addQueryLayer(org.geotools.data.ows.Layer)
087: */
088: public void addQueryLayer(Layer layer) {
089: queryLayers.add(layer);
090: }
091:
092: /**
093: * @see org.geotools.data.wms.request.GetFeatureInfoRequest#setQueryLayers(java.util.Set)
094: */
095: public void setQueryLayers(Set layers) {
096: queryLayers = layers;
097: }
098:
099: /**
100: * @see org.geotools.data.wms.request.GetFeatureInfoRequest#setInfoFormat(java.lang.String)
101: */
102: public void setInfoFormat(String infoFormat) {
103: setProperty(INFO_FORMAT, infoFormat);
104: }
105:
106: /**
107: * @see org.geotools.data.wms.request.GetFeatureInfoRequest#setFeatureCount(java.lang.String)
108: */
109: public void setFeatureCount(String featureCount) {
110: setProperty(FEATURE_COUNT, featureCount);
111: }
112:
113: /**
114: * @see org.geotools.data.wms.request.GetFeatureInfoRequest#setFeatureCount(int)
115: */
116: public void setFeatureCount(int featureCount) {
117: setFeatureCount(Integer.toString(featureCount));
118: }
119:
120: /**
121: * @see org.geotools.data.wms.request.GetFeatureInfoRequest#setQueryPoint(int, int)
122: */
123: public void setQueryPoint(int x, int y) {
124: setProperty(getQueryX(), Integer.toString(x));
125: setProperty(getQueryY(), Integer.toString(y));
126: }
127:
128: /**
129: * Created because the 1.3.0 spec changes this parameter name.
130: * The 1.3.0 spec should over-ride this method.
131: * @return a String representing the x-axis query point
132: */
133: protected String getQueryX() {
134: return QUERY_X;
135: }
136:
137: /**
138: * Created because the 1.3.0 spec changes this parameter name.
139: * The 1.3.0 spec should over-ride this method.
140: * @return a String representing the y-axis query point
141: */
142: protected String getQueryY() {
143: return QUERY_Y;
144: }
145:
146: protected void initRequest() {
147: setProperty(REQUEST, "feature_info"); //$NON-NLS-1$
148: }
149:
150: protected abstract void initVersion();
151: }
|