Revision 7565

View differences:

org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/epsg/CrsAxisOrder.java
1
package org.gvsig.remoteclient.epsg;
2

  
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
7
import java.util.HashSet;
8

  
9
/**
10
 * <p>Utility class to get the axis order of a coordinate reference system (CRS).
11
 * It should be generalized and moved to the projection API on some future
12
 * version.</p>
13
 * 
14
 * @author Cesar Martinez Izquierdo
15
 *
16
 */
17
public class CrsAxisOrder {
18
	/*
19
	 * Set containing the EPSG codes for projections using Y-X axis order.
20
	 */
21
	private static HashSet<String> yxAxisOrder = null;
22
	
23
	/**
24
	 * Returns a set containing the EPSG codes for projections using Y-X axis
25
	 * order.
26
	 * 
27
	 * @return
28
	 */
29
	private static HashSet<String> getYxAxisOrder() {
30
		if (yxAxisOrder==null) {
31
			yxAxisOrder = new HashSet();
32
			try {
33
				InputStream is = CrsAxisOrder.class.getClassLoader().getResourceAsStream("/axisOrder/mapaxisorder.csv");
34
				if (is!=null) {
35
					BufferedReader reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
36
					// skip the first line which contains the CSV header
37
					String line = reader.readLine();
38
					// read the codes
39
					while ((line=reader.readLine())!=null) {
40
						yxAxisOrder.add(line);
41
					}
42
				}
43
			} catch (IOException e) {
44
			}
45
		}
46
		return yxAxisOrder;
47
	}
48
	
49
	/**
50
	 * <p>Returns <code>true</code> if the CRS defined by the
51
	 * provided EPSG code follows the XY axis order (i.e.
52
	 * the first coordinate corresponds to the horizontal
53
	 * axis while the second coordinate corresponds to
54
	 * the vertical axis). Returns <false> if the
55
	 * EPSG registry defines YX order.</p>
56
	 * 
57
	 * <p>Note that it will also return true for any unknown CRS</p>.
58
	 * 
59
	 * @param epsgCode The EPSG code of the CRS to check, as integer.
60
	 * @return
61
	 */
62
	public static boolean isXyAxisOrder(int epsgCode) {
63
		if (getYxAxisOrder().contains(Integer.toString(epsgCode))) {
64
			return false;
65
		}
66
		return true;
67
	}
68

  
69
	/**
70
	 * <p>Returns <code>true</code> if the CRS defined by the
71
	 * provided EPSG code follows the XY axis order (i.e.
72
	 * the first coordinate corresponds to the horizontal
73
	 * axis while the second coordinate corresponds to
74
	 * the vertical axis). Returns <false> if the
75
	 * EPSG registry defines YX order.</p>
76
	 * 
77
	 * <p>Note that it will also return true for any unknown CRS</p>.
78
	 * 
79
	 * @param epsgCode Epsg code as string, for instance "EPSG:4326" or just
80
	 * "4326".
81
	 * @return
82
	 */
83
	public static boolean isXyAxisOrder(String epsgCode) {
84
		if (epsgCode!=null) {
85
			if (epsgCode.toUpperCase().startsWith("EPSG:")) {
86
				epsgCode = epsgCode.substring(5);
87
			}
88
			if (getYxAxisOrder().contains(epsgCode)) {
89
				return false;
90
			}
91
		}
92
		return true;
93
	}
94
}
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/exceptions/WMSException.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.exceptions;
25

  
26
/**
27
 * Excepci?n provocada por el WMS.
28
 *
29
 * @author Vicente Caballero Navarro
30
 */
31
public class WMSException extends Exception 
32
{	
33
	private String wms_message = null;
34
	
35
	/**
36
	 *
37
	 */
38
	public WMSException() {
39
		super();
40
	}
41

  
42
	/**
43
	 * Crea WMSException.
44
	 *
45
	 * @param message
46
	 */
47
	public WMSException(String message) {
48
		super(message);
49
	}
50

  
51
	/**
52
	 * Crea WMSException.
53
	 *
54
	 * @param message
55
	 * @param cause
56
	 */
57
	public WMSException(String message, Throwable cause) {
58
		super(message, cause);
59
	}
60

  
61
	/**
62
	  * Crea WMSException.
63
	 *
64
	 * @param cause
65
	 */
66
	public WMSException(Throwable cause) {
67
		super(cause);
68
	}
69
	
70
	public String getWMSMessage()
71
	{
72
		if (wms_message == null)
73
			return "";
74
		else
75
			return wms_message;
76
	}
77
	
78
	public void setWMSMessage(String mes)
79
	{
80
		wms_message = mes;
81
	}
82
}
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/exceptions/WMSWrongSizeException.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.exceptions;
25

  
26
/**
27
 * La petici?n al servidor era de un tama?o equivocado.
28
 * Reconoce execepciones de algunos tipos:<br>
29
 * <li>El server http://wms.jpl.nasa.gov/wms.cgi da estos:
30
 * <pre>
31
    <?xml version='1.0' encoding="UTF-8" standalone="no" ?>
32
	<!DOCTYPE ServiceExceptionReport SYSTEM "http://www.digitalearth.gov/wmt/xml/exception_1_1_0.dtd ">
33
	<ServiceExceptionReport version="1.1.0">
34
	  <ServiceException>
35
	    Requested image is too wide, max allowed width is 4096
36
	  </ServiceException>
37
	</ServiceExceptionReport>
38
	
39
	<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
40
	<!DOCTYPE ServiceExceptionReport SYSTEM "http://www.digitalearth.gov/wmt/xml/exception_1_1_0.dtd ">
41
	<ServiceExceptionReport version="1.1.0">
42
	  <ServiceException>
43
	    Requested image is too tall, max allowed height is 4096
44
	  </ServiceException>
45
	</ServiceExceptionReport>
46
 * </pre>
47
 * <li>El server http://www.idee.es/wms/IDEE-Base/IDEE-Base da
48
 * <pre>
49
 	<ERROR Operation="GetMap Request" status="ERROR" source="Web Map Server" description="El servidor no ha podido realizar la operacion">
50
		<ERROR CODE="El tamano en pixels pedido no es valido."/>
51
		<ERROR CODE="Su valor debe ser mayor que 0 y menor que el limite de descarga: anchura = 1500, altura = 1500"/>
52
	</ERROR>
53
 * </pre>
54
 * <li>El server http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx da
55
 * <pre>
56
 	<ServiceExceptionReport version="1.1.1">
57
-
58
	<ServiceException code="InvalidFormat">
59

  
60
Par?metros erroneos:
61
prefijo = 
62
mapa =  0
63
formato = IMAGE/JPEG
64
XMin =  1.1578804698593
65
YMin =  53.5852110737936
66
XMax =  10.3
67
YMax =  53.8000038968219
68
AnchoPixels =  64
69
AltoPixels =  5023
70
Transparente = TRUE
71
Descripci?n error:
72
AltoPixels > 2000
73
</ServiceException>
74
</ServiceExceptionReport>
75
 * </pre>
76
 * 
77
 * <pre>
78
 	<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
79
<!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengeospatial.net/wms/1.1.1/exception_1_1_1.dtd">
80
<ServiceExceptionReport version="1.1.1">
81
<ServiceException>
82
msWMSLoadGetMapParams(): WMS server error. Image size out of range, WIDTH and HEIGHT must be between 1 and 2048 pixels.
83
</ServiceException>
84
</ServiceExceptionReport>
85

  
86
 * </pre>
87
 * 
88
 */
89
public class WMSWrongSizeException extends WMSException 
90
{	
91
	private int height = -1;
92
	private int width = -1;
93
	
94
	/**
95
	 *
96
	 */
97
	public WMSWrongSizeException() {
98
		super();
99
	}
100

  
101
	/**
102
	 * Crea WMSException.
103
	 *
104
	 * @param message
105
	 */
106
	public WMSWrongSizeException(String message) {
107
		super(message);
108
	}
109

  
110
	/**
111
	 * Crea WMSException.
112
	 *
113
	 * @param message
114
	 * @param cause
115
	 */
116
	public WMSWrongSizeException(String message, Throwable cause) {
117
		super(message, cause);
118
	}
119

  
120
	/**
121
	  * Crea WMSException.
122
	 *
123
	 * @param cause
124
	 */
125
	public WMSWrongSizeException(Throwable cause) {
126
		super(cause);
127
	}
128
	
129
	public int getWidth()
130
	{
131
		return width; 
132
	}
133
	public int getHeight()
134
	{
135
		return height;
136
	}
137
	public void setWidth(int w)
138
	{
139
		width =w;
140
	}
141
	public void setHeight(int h)
142
	{
143
		height =h;
144
	}
145
	
146
	/**
147
	 * Checks if the argument is a WrongSizeError message, in this
148
	 * case throws a WMSWrongSizeException
149
	 * @param errorMsg El mensaje de error que pasa el server.
150
	 * @throws WMSException
151
	 */
152
	public static void check(String errorMsg) throws WMSException 
153
	{
154
		//TODO:
155
		//check the errorMsg to see if it matches with one of the 
156
		// well known string error messages.
157
	}
158
}
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/wms/WMSClient.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wms;
26

  
27
import java.awt.geom.Rectangle2D;
28
import java.io.File;
29
import java.io.IOException;
30
import java.net.ConnectException;
31
import java.net.URL;
32
import java.util.TreeMap;
33
import java.util.Vector;
34
import org.apache.commons.lang3.StringUtils;
35

  
36
import org.gvsig.compat.net.ICancellable;
37
import org.gvsig.remoteclient.exceptions.ServerErrorException;
38
import org.gvsig.remoteclient.exceptions.WMSException;
39
import org.gvsig.remoteclient.utils.BoundaryBox;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

  
43

  
44
/**
45
 * <p>Represents the class the with the necessary logic to connect to a OGCWMS and interpretate the data </p>
46
 * 
47
 */
48
public class WMSClient extends org.gvsig.remoteclient.RasterClient {
49
    
50
    private static final Logger logger = LoggerFactory.getLogger(WMSClient.class);
51
    private org.gvsig.remoteclient.wms.WMSProtocolHandler handler;
52
//    private TreeMap layers = new TreeMap();
53
//    private WMSLayer rootLayer;
54
    
55
    /**
56
     * @return Returns the rootLayer.
57
     */
58
    public WMSLayer getRootLayer() {
59
        return handler.rootLayer;
60
    }
61

  
62
    /**
63
     * Constructor.
64
     * the parameter host, indicates the WMS host to connect.
65
     * */
66
    public WMSClient(String host) throws ConnectException, IOException 
67
    {
68
    	setHost(host);
69
        try {        	
70
        	handler = WMSProtocolHandlerFactory.negotiate(host);
71
        	handler.setHost(host);        
72
        } catch(ConnectException conE) {
73
                logger.warn("Can't create WMS protocol handler for host '"+host+"'.",conE);
74
        	throw conE; 
75
        } catch(IOException ioE) {
76
                logger.warn("Can't create WMS protocol handler for host '"+host+"'.",ioE);
77
        	throw ioE; 
78
        } catch(Exception e) {
79
                logger.warn("Can't create WMS protocol handler for host '"+host+"'.",e);
80
        }
81
    }
82
    
83
    public String getVersion()
84
    {
85
        return handler.getVersion();
86
    }
87
    /**
88
     * <p>One of the three interfaces that OGC WMS defines. Request a map.</p> 
89
     * @throws ServerErrorException 
90
     */
91
    public File getMap(WMSStatus status, ICancellable cancel) throws WMSException, ServerErrorException{   
92
        return handler.getMap(status, cancel);
93
    } 
94
    
95
    /**
96
     * <p>Gets the GetMap URL. The final client should download the file</p> 
97
     * @throws ServerErrorException 
98
     */
99
    public URL getGetMapURL(WMSStatus status, ICancellable cancel) throws WMSException, ServerErrorException{   
100
       return handler.getMapURL(status, cancel);
101
    } 
102
    
103
    /**
104
     * Returns the exception message if the file is a XML instead of a image.
105
     * @param file
106
     * @return
107
     * @throws IOException 
108
     */
109
    public String getExceptionMessage(File file) throws IOException {
110
    	return handler.getExceptionMessage(file);
111
    }
112
    
113
    /**
114
     * <p>One of the three interfaces defined by OGC WMS, it gets the service capabilities</p>
115
     * @param override, if true the previous downloaded data will be overridden
116
     */
117
    public void getCapabilities(WMSStatus status, boolean override, ICancellable cancel) {        
118
        handler.getCapabilities(status, override, cancel);
119
    } 
120
    
121
    /**
122
     * <p>One of the three interfaces defined by the OGC WMS, it gets the information about a feature requested</p>
123
     * @return 
124
     */
125
    public String getFeatureInfo(WMSStatus status, int x, int y, int featureCount, ICancellable cancel) throws WMSException{        
126
        return handler.getFeatureInfo(status, x, y, featureCount, cancel);
127
    } 
128
    
129
    /**
130
     * <p>One of the three interfaces defined by the OGC WMS, it gets legend of a layer</p>
131
     * @return 
132
     */
133
    public File getLegendGraphic(WMSStatus status, String layerName, ICancellable cancel) throws WMSException, ServerErrorException{        
134
        return handler.getLegendGraphic(status, layerName, cancel);
135
    } 
136
    
137
    /**
138
     * <p> Reads from the WMS Capabilities, the layers available in the service</p>
139
     * @return a TreeMap with the available layers in the WMS 
140
     */
141
    public TreeMap getLayers() {        
142
        return handler.layers;
143
    } 
144
    
145
    /**
146
     * <p>Reads from the WMS Capabilities the number if layers available in the service</p>
147
     * @return, number of layers available
148
     */
149
    public int getNumberOfLayers() {        
150
        if (handler.layers != null)
151
        {
152
            return handler.layers.size();
153
        }
154
        return 0;
155
    } 
156
    
157
    /**
158
     * <p>Gets the WMSLayer with this name</p>
159
     * 
160
     * @param _name, layer name
161
     * @return the layer with this name
162
     */
163
    public WMSLayer getLayer(String _name) {        
164
        if (handler.layers.get(_name) != null)
165
        {
166
            return (WMSLayer)handler.layers.get(_name);
167
        }
168
        
169
        return null;
170
    } 
171
    
172
    public String[] getLayerNames()
173
    {    	
174
        WMSLayer[] lyrs;
175
        
176
        lyrs = (WMSLayer[])handler.layers.values().toArray(new WMSLayer[0]);
177
        
178
        String[] names = new String[lyrs.length];
179
        
180
        for(int i = 0; i<lyrs.length; i++)
181
        {
182
            names[i] = ((WMSLayer)lyrs[i]).getName();
183
        }
184
        return names;
185
    }
186
    
187
    public String[] getLayerTitles()
188
    {    	
189
        WMSLayer[] lyrs;
190
        
191
        lyrs = (WMSLayer[])handler.layers.values().toArray(new WMSLayer[0]);
192
        
193
        String[] titles = new String[lyrs.length];
194
        
195
        for(int i = 0; i<lyrs.length; i++)
196
        {
197
            titles[i] = ((WMSLayer)lyrs[i]).getTitle();
198
        }
199
        return titles;
200
    }
201
    /**
202
     * <p>Gets the image formats available in the Service to retrieve the maps</p>
203
     * @return a vector with all the available formats
204
     */
205
    public Vector getFormats() {        
206
        return ((WMSServiceInformation)handler.getServiceInformation()).formats;         
207
    } 
208
    
209
    /**
210
     * <p>Gets the information by point formats available in the Service</p>
211
     * @return a vector with all the available formats
212
     */
213
    public Vector getInfoFormats() {        
214
        return ((WMSServiceInformation)handler.getServiceInformation()).infoformats;
215
    } 
216
    
217
    public boolean isQueryable()
218
    {
219
    	return ((WMSServiceInformation)handler.getServiceInformation()).isQueryable();  
220
    }
221
    public boolean hasLegendGraphic()
222
    {
223
    	return ((WMSServiceInformation)handler.getServiceInformation()).hasLegendGraphic();  
224
    }
225
    
226
    public void close() {        
227
        // your code here
228
    } 
229
    
230
    
231
    /**
232
     * Returns the max extent that envolves the requested layers
233
     * */
234
    public Rectangle2D getLayersExtent(String[]layerNames, String srs) {
235
        try {
236
        	if (layerNames == null) {
237
        		return null;
238
        	}
239
        	
240
            BoundaryBox bbox = null;
241
            WMSLayer layer = getLayer(layerNames[0]);
242
            
243
            bbox = layer.getBbox(srs);
244
            if (bbox == null) {
245
            	return null;
246
            }
247
            double xmin = bbox.getXmin();
248
            double xmax = bbox.getXmax();
249
            double ymin = bbox.getYmin();
250
            double ymax = bbox.getYmax();
251
            
252
            for(int i = 1; i < layerNames.length; i++) {
253
                layer = getLayer(layerNames[i]);
254
                bbox = layer.getBbox(srs);
255
                if (bbox == null) return null;
256
                if (bbox.getXmin() < xmin) {
257
                    xmin = bbox.getXmin();
258
                }
259
                if (bbox.getYmin() < ymin) {
260
                    ymin = bbox.getYmin();
261
                }
262
                if (bbox.getXmax() > xmax) {
263
                    xmax = bbox.getXmax();
264
                }
265
                if (bbox.getYmax() > ymax) {
266
                    ymax = bbox.getYmax();
267
                }
268
            }	
269
            
270
            Rectangle2D extent = new Rectangle2D.Double(xmin, ymin, Math.abs(xmax-xmin), Math.abs(ymax-ymin));
271
            return extent;
272
        } catch(Exception e) {
273
            String msg = null;
274
            try {
275
                msg = "Can't get layers extent, layers='"+StringUtils.join(layerNames, ",")+"', srs='"+srs+"'.";
276
            } catch(Exception ex) {
277
                msg = "Can't get layers extent.";
278
            }
279
            logger.warn(msg,e);
280
            return null;
281
        }
282
    }
283
    
284
    
285
    /**
286
     * Gets the Service information included in the Capabilities
287
     * */    
288
    public WMSServiceInformation getServiceInformation()
289
    {
290
        return ((WMSServiceInformation)handler.getServiceInformation());
291
    }
292
    
293
    
294
    /**
295
     * <p>Checks the connection to the remote WMS and requests its capabilities.</p>
296
     * @param override, if true the previous downloaded data will be overridden
297
     * 
298
     * @deprecated Use {@link #connect(WMSStatus, boolean, ICancellable)} instead,
299
     * as the WMSStatus is necessary when connecting in order to correct
300
     * call the getCapabilities method.
301
     */
302
    public boolean connect(boolean override, ICancellable cancel) 
303
    {
304
    	return connect(null, override, cancel);
305
    }
306
    
307
    /**
308
     * <p>Checks the connection to the remote WMS and requests its capabilities.</p>
309
     * <p>This method should probably be moved to RemoteClient interface, as the
310
     * same problem will probably happen for other protocols</p>
311
     * 
312
     * @param override, if true the previous downloaded data will be overridden
313
     */
314
    public boolean connect(WMSStatus status, boolean override, ICancellable cancel) 
315
    {
316
        String host = getHost();
317
        try {            
318
            if (handler == null)
319
            {
320
                if (host.trim().length() > 0)
321
                {					
322
                    //TODO: Implement correctly the negotiate algorithm
323
                    handler = WMSProtocolHandlerFactory.negotiate(host);
324
                    //handler = new WMSProtocolHandler1_1_1();
325
                    handler.setHost(host);
326
                }
327
                else
328
                {
329
                    //must to specify host first!!!!
330
                    return false;
331
                }                
332
            }
333
            getCapabilities(status, override, cancel);
334
            return true;
335
            
336
        } catch (Exception e) {
337
            logger.warn("Can't connect to host '"+host+"'.",e);
338
            return false;
339
        }
340
    }
341
    
342
    //TODO Check this out: Always 1 layer at first level...
343
    public WMSLayer getLayersRoot() {
344
        return handler.rootLayer;
345
    }
346

  
347
	public boolean connect(ICancellable cancel) {
348
		return connect(false, cancel);
349
	}
350
}
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/wms/wms_1_1_0/WMSLayer1_1_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wms.wms_1_1_0;
26

  
27
import java.io.IOException;
28
import java.util.ArrayList;
29
import java.util.TreeMap;
30

  
31
import org.kxml2.io.KXmlParser;
32
import org.xmlpull.v1.XmlPullParserException;
33

  
34
import org.gvsig.compat.CompatLocator;
35
import org.gvsig.compat.lang.StringUtils;
36
import org.gvsig.remoteclient.utils.BoundaryBox;
37
import org.gvsig.remoteclient.utils.CapabilitiesTags;
38
import org.gvsig.remoteclient.utils.Utilities;
39
import org.gvsig.remoteclient.wms.WMSDimension;
40
import org.gvsig.remoteclient.wms.WMSExtent;
41

  
42

  
43
/**
44
 * <p>WMS Layer for WMS 1.1.0</p>
45
 * 
46
 */
47
public class WMSLayer1_1_0 extends org.gvsig.remoteclient.wms.WMSLayer {
48
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
49
    
50
    /**
51
     * <p>Extents defined for the layer in the capabilities doc</p>
52
     */
53
    private java.util.ArrayList extents = new ArrayList();
54
    
55
    /**
56
     * <p> gets the extent vector defined in this layer</p>
57
     * @return 
58
     */
59
    public ArrayList getExtents() {        
60
        return extents;
61
    } 
62
    
63
    public WMSExtent getExtent(String name)
64
    {
65
    	for(int i = 0; i < extents.size(); i++ ){
66
    		if(((WMSExtent)extents.get(i)).getName().compareTo(name)==0)
67
    		{
68
    			return (WMSExtent)extents.get(i);
69
    		}
70
    	}
71
    	return null;
72
    }
73
    
74
    /**
75
     * <p>Adds an extent to the extent vector </p>
76
     * @param extent 
77
     */
78
    public void addExtent(org.gvsig.remoteclient.wms.WMSExtent extent) {        
79
        extents.add(extent);
80
    }   
81
    
82
    public ArrayList getDimensions()
83
    {   
84
        WMSDimension dimension;
85
        WMSExtent extent;
86
    	for(int i = 0; i < dimensions.size(); i++)
87
    	{
88
    		dimension = (WMSDimension)dimensions.get(i);
89
    		extent = getExtent(dimension.getName()); 
90
    		if(extent != null)
91
    		{    			
92
    			((WMSDimension)dimensions.get(i)).setDimensionExpression( extent.getExtentExpression());    			
93
    		}
94
    	}    	
95
    	
96
        WMSDimension pDimension;
97
        WMSDimension myDimension;    
98
        ArrayList myDimensions = (ArrayList) this.dimensions.clone();        
99
        ArrayList pDimensions;        
100
        if (parent!=null)
101
        {
102
        	pDimensions = parent.getDimensions();
103
        	for (int i= 0; i < pDimensions.size(); i++){
104
        		pDimension = (WMSDimension)pDimensions.get(i);
105
        		myDimension = getDimension(pDimension.getName());
106
        		if (myDimension != null){
107
        			pDimensions.remove(pDimension);
108
        		}
109
        	}
110
        	myDimensions.addAll(pDimensions);
111
        }
112
        return myDimensions;
113
    }
114
    
115
    public WMSLayer1_1_0()
116
    {
117
        children = new ArrayList();
118
    }
119
    /**
120
     * <p>Parses the contents of the parser(WMSCapabilities)
121
     * to extract the information about an WMSLayer</p>
122
     * 
123
     */
124
    public void parse(KXmlParser parser, TreeMap layerTreeMap)
125
    throws IOException, XmlPullParserException
126
    {
127
        int currentTag;
128
        boolean end = false;
129
        String value;
130
        BoundaryBox bbox;
131
        parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LAYER);
132
        
133
        //First of all set whether the layer is Queryable reading the attribute.
134
        value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
135
        if (value != null)
136
        {
137
            if (value.compareTo("0")==0)
138
                setQueryable(false);
139
            else
140
                setQueryable(true);
141
        }
142
        
143
        currentTag = parser.nextTag();
144
        
145
        while (!end) 
146
        {
147
            switch(currentTag)
148
            {
149
                case KXmlParser.START_TAG:
150
                    if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0)
151
                    {	
152
                        WMSLayer1_1_0 lyr = new WMSLayer1_1_0();						
153
                        //parser.next(); 
154
                        lyr.parse(parser, layerTreeMap);
155
                        lyr.setParent(this);
156
                        this.children.add(lyr);
157
                        // Jaume
158
                        if (lyr.getName()!=null)
159
                            layerTreeMap.put(lyr.getName(), lyr);
160
                    }
161
                    else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION)==0){
162
                        // TODO comprobar que esto se necesite o se deseche
163
                        parser.skipSubTree();
164
                    }
165
                    else if (parser.getName().compareTo(CapabilitiesTags.NAME)==0)
166
                    {		
167
                        value = parser.nextText();
168
                        if (value != null) setName(value);						
169
                    }	
170
                    else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0)
171
                    {
172
                        value = parser.nextText();
173
                        if (value != null) setTitle(value);
174
                    }
175
                    else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0)
176
                    {
177
                        value = parser.nextText();
178
                        if (value != null) setAbstract(value);
179
                    }
180
                    else if (parser.getName().compareTo(CapabilitiesTags.SRS)==0)
181
                    {
182
                        value = parser.nextText();
183
                        if (value != null){
184
                            String[] mySRSs = stringUtils.split(value, " ");
185
                            for (int i = 0; i < mySRSs.length; i++) {
186
                                addSrs(mySRSs[i]);    
187
                            }
188
                            
189
                        }
190
                    }					
191
                    else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0)
192
                    {
193
                        bbox = new BoundaryBox();
194
                        value = parser.getAttributeValue("",CapabilitiesTags.SRS);
195
                        if (value != null)
196
                            bbox.setSrs(value);
197
                        value = parser.getAttributeValue("",CapabilitiesTags.MINX);
198
                        if ((value != null) && (Utilities.isNumber(value)))
199
                            bbox.setXmin(Double.parseDouble(value));	
200
                        value = parser.getAttributeValue("",CapabilitiesTags.MINY);
201
                        if ((value != null) && (Utilities.isNumber(value)))
202
                            bbox.setYmin(Double.parseDouble(value));	
203
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
204
                        if ((value != null) && (Utilities.isNumber(value)))
205
                            bbox.setXmax(Double.parseDouble(value));	
206
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
207
                        if ((value != null) && (Utilities.isNumber(value)))
208
                            bbox.setYmax(Double.parseDouble(value));	
209
                        addBBox(bbox);
210
                        addSrs(bbox.getSrs());
211
                    }	
212
                    else if (parser.getName().compareTo(CapabilitiesTags.LATLONBOUNDINGBOX)==0)
213
                    {
214
                        bbox = new BoundaryBox();
215
                        bbox.setSrs(CapabilitiesTags.EPSG_4326);
216
                        value = parser.getAttributeValue("",CapabilitiesTags.MINX);
217
                        if ((value != null) && (Utilities.isNumber(value)))
218
                            bbox.setXmin(Double.parseDouble(value));	
219
                        value = parser.getAttributeValue("",CapabilitiesTags.MINY);
220
                        if ((value != null) && (Utilities.isNumber(value)))
221
                            bbox.setYmin(Double.parseDouble(value));	
222
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
223
                        if ((value != null) && (Utilities.isNumber(value)))
224
                            bbox.setXmax(Double.parseDouble(value));	
225
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
226
                        if ((value != null) && (Utilities.isNumber(value)))
227
                            bbox.setYmax(Double.parseDouble(value));	
228
                        addBBox(bbox);
229
                        setLatLonBox(bbox);
230
                        //addSrs(bbox.getSrs());
231
                    }						
232
                    else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0)
233
                    {
234
                        value = parser.getAttributeValue("",CapabilitiesTags.MIN);
235
                        if ((value != null) && (Utilities.isNumber(value)))
236
                            setScaleMin(Double.parseDouble(value));
237
                        value = parser.getAttributeValue("",CapabilitiesTags.MAX);
238
                        if ((value != null) && (Utilities.isNumber(value)))
239
                            setScaleMax(Double.parseDouble(value));																	
240
                    }						
241
                    else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0)
242
                    {
243
                        WMSStyle1_1_0 style = new WMSStyle1_1_0();
244
                        style.parse(parser);
245
                        if ((style != null) && (style.getName() != null))
246
                        {
247
                            styles.add(style);
248
                        }
249
                    }
250
                    else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0)
251
                    {
252
                        WMSDimension dim = new WMSDimension();
253
                        dim.parse(parser);
254
                        if ((dim != null) && (dim.getName() != null))
255
                        {
256
                            addDimension(dim);
257
                        }
258
                    }
259
                    else if (parser.getName().compareTo(CapabilitiesTags.EXTENT)==0)
260
                    {                    	
261
                        WMSExtent extent = new WMSExtent();
262
                        extent.parse(parser);
263
                        if ((extent != null) && (extent.getName() != null))
264
                        {
265
                            addExtent(extent);
266
                            
267
                        }
268
                    }                      
269
                    break;
270
                case KXmlParser.END_TAG:
271
                    if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0)
272
                        end = true;
273
                    break;
274
                case KXmlParser.TEXT:					
275
                    break;
276
            }
277
            if (!end)
278
            	currentTag = parser.next();
279
        }
280
        parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LAYER);
281
    }      
282
    
283
    public String toString(){
284
        return super.toString();
285
    }
286
}
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/wms/wms_1_1_0/WMSProtocolHandler1_1_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wms.wms_1_1_0;
26

  
27
import java.io.ByteArrayInputStream;
28
import java.io.File;
29
import java.io.IOException;
30
import java.util.ArrayList;
31
import java.util.TreeMap;
32

  
33
import org.kxml2.io.KXmlParser;
34
import org.xmlpull.v1.XmlPullParserException;
35

  
36
import org.gvsig.remoteclient.utils.CapabilitiesTags;
37
import org.gvsig.remoteclient.utils.EncodingXMLParser;
38
import org.gvsig.remoteclient.utils.ExceptionTags;
39
import org.gvsig.remoteclient.wms.WMSServiceInformation;
40
import org.gvsig.remoteclient.wms.WMSStatus;
41
import org.gvsig.remoteclient.wms.request.WMSGetCapabilitiesRequest;
42
import org.gvsig.remoteclient.wms.request.WMSGetFeatureInfoRequest;
43
import org.gvsig.remoteclient.wms.request.WMSGetLegendGraphicRequest;
44
import org.gvsig.remoteclient.wms.request.WMSGetMapRequest;
45
import org.gvsig.remoteclient.wms.wms_1_1_0.request.WMSGetCapabilitiesRequest1_1_0;
46
import org.gvsig.remoteclient.wms.wms_1_1_0.request.WMSGetFeatureInfoRequest1_1_0;
47
import org.gvsig.remoteclient.wms.wms_1_1_0.request.WMSGetLegendGraphicRequest1_1_0;
48
import org.gvsig.remoteclient.wms.wms_1_1_0.request.WMSGetMapRequest1_1_0;
49
import org.gvsig.remoteclient.wms.wms_1_3_0.WMSProtocolHandler1_3_0;
50
import org.slf4j.Logger;
51
import org.slf4j.LoggerFactory;
52

  
53
/**
54
 * <p>
55
 * Describes the handler to comunicate to a WMS 1.1.0
56
 * </p>
57
 */
58
public class WMSProtocolHandler1_1_0 extends org.gvsig.remoteclient.wms.WMSProtocolHandler
59
{
60
    
61
        private static final Logger logger = LoggerFactory.getLogger(WMSProtocolHandler1_1_0.class);
62
	private WMSLayer1_1_0 fakeRootLayer;
63
    
64
	public WMSProtocolHandler1_1_0()
65
	{
66
		this.version = "1.1.0";
67
		this.name = "WMS1.1.0";
68
		this.serviceInfo = new WMSServiceInformation(); 
69
		this.layers = new TreeMap();
70
	}
71
    
72
//------------------------------------------------------------------------------
73
// Parsing methods....    
74
//------------------------------------------------------------------------------    
75

  
76

  
77
	public boolean parseCapabilities(File f)
78
    {       
79
    	rootLayer = null;
80
    	int tag;
81
    	EncodingXMLParser kxmlParser = null;
82
    	kxmlParser = new EncodingXMLParser();
83
    	try
84
    	{
85
    		kxmlParser.setInput(f);
86
    		kxmlParser.nextTag();
87
    		if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT ) 
88
    		{    		
89
    			kxmlParser.require(KXmlParser.START_TAG, null, CapabilitiesTags.CAPABILITIES_ROOT1_1_1);    			
90
    			tag = kxmlParser.nextTag();
91
				 while(tag != KXmlParser.END_DOCUMENT)
92
				 {
93
                     switch(tag)
94
					 {
95
                         
96
						case KXmlParser.START_TAG:
97
							if (kxmlParser.getName().compareTo(CapabilitiesTags.SERVICE )==0)
98
							{
99
								parseServiceTag(kxmlParser);
100
							}	
101
							else if (kxmlParser.getName().compareTo(CapabilitiesTags.CAPABILITY)==0)
102
							{
103
								parseCapabilityTag(kxmlParser);
104
							}
105
							break;
106
						case KXmlParser.END_TAG:							
107
							break;
108
						case KXmlParser.TEXT:
109
												
110
						break;
111
					 }
112
    				 tag = kxmlParser.next();
113
    			 }
114

  
115
    			kxmlParser.require(KXmlParser.END_DOCUMENT, null, null);
116
    		}
117
    	}
118
    	catch(XmlPullParserException parser_ex){
119
                logger.warn("Error parsing capabilites.",parser_ex);
120
    		return false;
121
    	}
122
   		catch (IOException ioe) {			
123
                        logger.warn("Error parsing capabilites.",ioe);
124
   			return false;
125
		} finally {
126
            return true;
127
        }
128
    } 
129
    
130
    /**
131
     * <p>Parses the Service Information </p>
132
     */    
133
    private void parseServiceTag(KXmlParser parser) throws IOException, XmlPullParserException 
134
    {
135
    	int currentTag;
136
    	boolean end = false;
137
    	
138
    	parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.SERVICE);
139
    	currentTag = parser.next();
140
    	
141
    	while (!end) 
142
    	{
143
			 switch(currentTag)
144
			 {
145
				case KXmlParser.START_TAG:
146
					if (parser.getName().compareTo(CapabilitiesTags.NAME)==0)
147
					{
148
						serviceInfo.name = parser.nextText(); 
149
					}	
150
					else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0)
151
					{
152
						serviceInfo.title = parser.nextText(); 
153
					}
154
					else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0)
155
					{
156
						serviceInfo.abstr = parser.nextText(); 
157
					}
158
					else if (parser.getName().compareTo(CapabilitiesTags.ONLINERESOURCE)==0)
159
					{
160
				    	String value = null;
161
				        value = parser.getAttributeValue("", CapabilitiesTags.XLINK_HREF);
162
				        if (value != null){
163
				        	serviceInfo.online_resource = value;
164
				        }
165
					}					
166
					else if ((parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST)==0) ||
167
							(parser.getName().compareTo(CapabilitiesTags.CONTACTINFORMATION)==0))
168
					{
169
						parser.skipSubTree();
170
					}					
171
					break;
172
				case KXmlParser.END_TAG:
173
					if (parser.getName().compareTo(CapabilitiesTags.SERVICE) == 0)
174
						end = true;
175
					break;
176
				case KXmlParser.TEXT:					
177
				break;
178
			 }
179
             if (!end)
180
                 currentTag = parser.next();
181
    	}
182
    	parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.SERVICE);
183
    }
184
    
185
    /**
186
     * <p>Parses the Capability Tag </p>
187
     */    
188
    private void parseCapabilityTag(KXmlParser parser) throws IOException, XmlPullParserException
189
    { 	
190
    	int currentTag;
191
    	boolean end = false;
192
    	
193
    	parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.CAPABILITY);
194
    	currentTag = parser.next();
195
    	
196
    	while (!end) 
197
    	{
198
			 switch(currentTag)
199
			 {
200
				case KXmlParser.START_TAG:
201
					if (parser.getName().compareTo(CapabilitiesTags.REQUEST)==0)
202
					{
203
						parseRequestTag(parser); 
204
					}	
205
					else if (parser.getName().compareTo(CapabilitiesTags.EXCEPTION)==0)
206
					{
207
						// TODO:
208
						// add the exception formats supported.
209
					}
210
					else if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0)
211
					{
212
						WMSLayer1_1_0 lyr = new WMSLayer1_1_0();
213
                        if (rootLayer == null)
214
                            rootLayer = lyr;
215
                        else {
216
                            // Handles when there is no general root layer, will use
217
                            // a fake non-queryable one.
218
                            if (!rootLayer.equals(getFakeRootLayer())){
219
                                WMSLayer1_1_0 aux = (WMSLayer1_1_0) rootLayer;
220
                                rootLayer  = getFakeRootLayer();
221
                                rootLayer.getChildren().add(aux);
222
                            }
223
                            rootLayer.getChildren().add(lyr);
224
                        }
225
						lyr.parse(parser, layers);
226
						
227
                        if (lyr.getName()!=null)
228
						    layers.put(lyr.getName(), lyr); 													
229
					}
230
					else if ((parser.getName().compareTo(CapabilitiesTags.VENDORSPECIFICCAPABILITIES)==0) ||
231
							(parser.getName().compareTo(CapabilitiesTags.USERDEFINEDSYMBOLIZATION )==0))
232
                            
233
					{
234
						parser.skipSubTree();
235
					}					
236
					break;
237
				case KXmlParser.END_TAG:
238
					if (parser.getName().compareTo(CapabilitiesTags.CAPABILITY) == 0)
239
						end = true;
240
					break;
241
				case KXmlParser.TEXT:					
242
				break;
243
			 }
244
			 if (!end)
245
			 currentTag = parser.next();
246
    	}
247
    	//parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.CAPABILITY);    	
248
    }   
249
    
250
    
251
    private WMSLayer1_1_0 getFakeRootLayer(){
252
        if (fakeRootLayer == null){
253
            fakeRootLayer = new WMSLayer1_1_0();
254
            fakeRootLayer.setTitle(serviceInfo.title);
255
            fakeRootLayer.setQueryable(false);
256
            fakeRootLayer.setName(null);
257
        }
258
        return fakeRootLayer;
259
    }
260
    
261
    protected String parseException(byte[] data) {
262
        ArrayList errors = new ArrayList();
263
        KXmlParser kxmlParser = new KXmlParser();
264
        
265
        try
266
        {
267
            kxmlParser.setInput(new ByteArrayInputStream(data), encoding);        
268
            kxmlParser.nextTag();
269
            int tag;
270
            if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT ) 
271
            { 
272
                kxmlParser.require(KXmlParser.START_TAG, null, ExceptionTags.EXCEPTION_ROOT);             
273
                tag = kxmlParser.nextTag();
274
                 while(tag != KXmlParser.END_DOCUMENT)
275
                 {
276
                     switch(tag)
277
                     {
278
                        case KXmlParser.START_TAG:
279
                            if (kxmlParser.getName().compareTo(ExceptionTags.SERVICE_EXCEPTION)==0){
280
                                String errorCode = kxmlParser.getAttributeValue("", ExceptionTags.CODE);
281
                                errorCode = (errorCode != null) ? "["+errorCode+"] " : "";
282
                                String errorMessage = kxmlParser.nextText();
283
                                errors.add(errorCode+errorMessage);
284
                            }
285
                            break;
286
                        case KXmlParser.END_TAG:                            
287
                            break;
288
                        
289
                     }
290
                     tag = kxmlParser.nextTag();
291
                 }
292
                 //kxmlParser.require(KXmlParser.END_DOCUMENT, null, null);
293
            }
294
        }
295
        catch(XmlPullParserException parser_ex){
296
            logger.warn("",parser_ex);
297
        }
298
        catch (IOException ioe) {           
299
            logger.warn("",ioe);
300
        }
301
        String message = errors.size()>0? "" : null;
302
        for (int i = 0; i < errors.size(); i++) {
303
            message += (String) errors.get(i)+"\n";
304
        }
305
        return message;
306
    }
307

  
308
	protected WMSGetFeatureInfoRequest createGetFeatureInfoRequest(
309
			WMSStatus status, int x, int y) {
310
		return new WMSGetFeatureInfoRequest1_1_0(status, this, x, y);
311
	}
312

  
313
	protected WMSGetMapRequest createGetMapRequest(WMSStatus status) {
314
		return new WMSGetMapRequest1_1_0(status, this);
315
	}
316

  
317
	protected WMSGetLegendGraphicRequest createGetLegendGraphicRequest(
318
			WMSStatus status, String layerName) {
319
		return new WMSGetLegendGraphicRequest1_1_0(status, this, layerName);
320
	}
321

  
322
	protected WMSGetCapabilitiesRequest createGetCapabilitiesRequest(
323
			WMSStatus status) {
324
		return new WMSGetCapabilitiesRequest1_1_0(status, this);
325
	}
326
    
327
  }
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/wms/wms_1_1_0/WMSStyle1_1_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.wms.wms_1_1_0;
26

  
27
import java.io.IOException;
28

  
29
import org.kxml2.io.KXmlParser;
30
import org.xmlpull.v1.XmlPullParserException;
31

  
32
import org.gvsig.remoteclient.utils.CapabilitiesTags;
33

  
34
/**
35
 * <p>Represents the layer style defined by the OGC Specifications for WMS 1.1.0</p>
36
 * 
37
 */
38
public class WMSStyle1_1_0 extends org.gvsig.remoteclient.wms.WMSStyle {
39

  
40
/**
41
 * <p>URL pointing to the legend for a layer with this style</p>
42
 */
43

  
44
/**
45
 * <p>Parses the STYLE TAG according with the OGC Specifications for the WMS 1.1.1</p>
46
 */
47
    public void parse(KXmlParser parser) throws IOException, XmlPullParserException
48
    {        
49
    	int currentTag;
50
    	boolean end = false;
51
    	
52
    	parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.STYLE);
53
    	currentTag = parser.nextTag();
54
    	
55
    	while (!end) 
56
    	{
57
			 switch(currentTag)
58
			 {
59
				case KXmlParser.START_TAG:
60
					if (parser.getName().compareTo(CapabilitiesTags.NAME)==0)
61
					{						
62
						setName(parser.nextText());						
63
					}	
64
					else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0)
65
					{
66
						setTitle(parser.nextText());
67
					}
68
					else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0)
69
					{
70
						setAbstract(parser.nextText());
71
					}	
72
					else if (parser.getName().compareTo(CapabilitiesTags.LEGENDURL)==0)
73
					break;
74
				case KXmlParser.END_TAG:
75
					if (parser.getName().compareTo(CapabilitiesTags.STYLE) == 0)
76
						end = true;
77
					break;
78
				case KXmlParser.TEXT:					
79
					break;
80
			 }
81
			 if (!end)
82
			 {
83
				 currentTag = parser.next();
84
			 }
85
    	}
86
    	parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.STYLE);
87
    } 
88
 }
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.58/org.gvsig.raster.wms.remoteclient/src/main/java/org/gvsig/remoteclient/wms/wms_1_1_0/request/WMSGetFeatureInfoRequest1_1_0.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
 
25
package org.gvsig.remoteclient.wms.wms_1_1_0.request;
26

  
27
import org.gvsig.compat.CompatLocator;
28
import org.gvsig.compat.lang.StringUtils;
29
import org.gvsig.remoteclient.utils.CapabilitiesTags;
30
import org.gvsig.remoteclient.utils.Utilities;
31
import org.gvsig.remoteclient.wms.WMSProtocolHandler;
32
import org.gvsig.remoteclient.wms.WMSStatus;
33
import org.gvsig.remoteclient.wms.request.WMSGetFeatureInfoRequest;
34

  
35
/**
36
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
37
 */
38
public class WMSGetFeatureInfoRequest1_1_0 extends WMSGetFeatureInfoRequest{
39
    
40
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
41
	
42
    public WMSGetFeatureInfoRequest1_1_0(WMSStatus status,
43
			WMSProtocolHandler protocolHandler, int x, int y) {
44
		super(status, protocolHandler, x, y);		
45
	}
46

  
47
	/*
48
	 * (non-Javadoc)
49
	 * @see org.gvsig.remoteClient.ogc.request.OGCRequest#getHttpGetRequest(java.lang.String)
50
	 */
51
	protected String getHttpGetRequest(String onlineResource) {
52
		StringBuffer req = new StringBuffer();
53
		req.append(onlineResource);
54
		req.append("REQUEST=GetFeatureInfo&SERVICE=WMS&");
55
		req.append("QUERY_LAYERS=").append(Utilities.Vector2CS(status.getLayerNames()));
56
		//req.append("&VERSION=").append(protocolHandler.getVersion()).append("&INFO_FORMAT=application/vnd.ogc.gml&");
57
		req.append("&VERSION=").append(protocolHandler.getVersion()).append("&INFO_FORMAT=" + status.getInfoFormat() + "&");
58
		req.append(getPartialQuery(status)).append("&x="+ x + "&y=" + y);
59
		//this parameter sets the max number of features per layer to be returned.
60
		//we set it to avoid the bug in mapserver that takes this number like max number of total features.
61
		req.append("&FEATURE_COUNT=10000");
62
		req.append("&EXCEPTIONS=" + getExceptionsFormat());  
63
		return req.toString();
64
	}
65
	
66
	/**
67
	 * @return the exceptions format
68
	 */
69
	protected String getExceptionsFormat(){
70
		return CapabilitiesTags.EXCEPTIONS_1_1_x;
71
	}
72

  
73
}
74

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff