Revision 29658

View differences:

branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/ICancellable.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
 *
44
 * $Id$
45
 * $Log$
46
 * Revision 1.1  2006-05-24 16:37:34  jaume
47
 * *** empty log message ***
48
 *
49
 *
50
 */
51
package org.gvsig.remoteclient.wms;
52

  
53
/**
54
 * <p>When a task is accessing to remote data, takes an indeterminate time, and occasionally gets locked. That's
55
 * the reason a task should support to be cancelable.</p>
56
 * <p><code>ICancellable</code> interface is designed for getting information about the cancellation of a
57
 * task of downloading remote information.</p>
58
 */
59
public interface ICancellable {
60
	/**
61
	 * <p>Returns <code>true</code> if a download or a group of downloads tasks has been canceled.</p>
62
	 * 
63
	 * @return <code>true</code> if a download or a group of downloads tasks has been canceled, otherwise <code>false</code>
64
	 */
65
	public boolean isCanceled();
66
	
67
	/**
68
	 * <p>Used to cancel only a group of downloads tasks with the same identifier.</p>
69
	 * 
70
	 * @return the identifier
71
	 */
72
	public Object getID();
73
}
0 74

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/WMSExtent.java
1
package org.gvsig.remoteclient.wms;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.remoteclient.utils.CapabilitiesTags;
6
import org.kxml2.io.KXmlParser;
7
import org.xmlpull.v1.XmlPullParserException;
8

  
9
public class WMSExtent {
10
	    
11
    private String name; 
12
    /**
13
     * Indicates that the server will round off inexact dimension values
14
     * to the nearest valid value, or (if it is null or zero) it will not.
15
     */
16
    private String nearestValue; 
17
    /**
18
     * Indicates that temporal data are normally kept current and that the
19
     * request parameter TIME <b>may</b> include the keyword 'current' 
20
     * instead of an ending value. 
21
     */
22
    private String current;
23
    
24
    /**
25
     * cotains the expression for this dimension's extent.
26
     */
27
    private String extentExpression;
28
    private String extDefaultValue;
29

  
30
    public String getName() {        
31
        return name;
32
    } 
33
    
34
    /**
35
     * Tells that the temporal data are normally kept current and that
36
     * the request parameter TIME may include the keyword 'current'
37
     * instead of an ending value.
38
     *
39
     * @return <b>true</b> if the server does keep the data, <b>false</b> else.
40
     */
41
    public boolean allowsCurrentTime() {
42
        return (current!=null && !current.equals("0"));
43
    }
44
    
45
    /**
46
     * Gets the value that would be used along this dimension if a Web
47
     * request omits a value for the dimension.
48
     * 
49
     * @return Returns the defaultValue.
50
     */
51
    public String getDefaultValue() {
52
        return extDefaultValue;
53
    }
54
    
55
    /**
56
     * Returns the extent expression as it was written in the Capabilities 
57
     * document.
58
     * @return String
59
     */
60
    public String getExtentExpression() {
61
        return extentExpression;
62
    }
63
       
64

  
65
    /**
66
     * @return Returns the nearestValues.
67
     */
68
    public boolean allowsNearestValue() {
69
        return (nearestValue!=null && !nearestValue.equals("0"));
70
    }	 
71

  
72
	   /**
73
	 * Parses the EXTENT tag in the WMS capabilities, filling the Extend fills of the
74
	 * WMSDimension object and loading the data into memory to be easily accesed.
75
	 */
76
	public void parse(KXmlParser parser) throws IOException, XmlPullParserException{
77
	    parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.EXTENT);
78
	    name			 = parser.getAttributeValue("", CapabilitiesTags.DIMENSION_NAME);
79
	    extDefaultValue  = parser.getAttributeValue("", CapabilitiesTags.DEFAULT);
80
	    nearestValue    = parser.getAttributeValue("", CapabilitiesTags.EXTENT_NEAREST_VALUE);
81
	    current          = parser.getAttributeValue("", CapabilitiesTags.EXTENT_CURRENT);
82
	    extentExpression = parser.nextText();
83
	}	
84
}
0 85

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/WMSLayer.java
1
package org.gvsig.remoteclient.wms;
2

  
3
import java.io.IOException;
4
import java.util.ArrayList;
5
import java.util.Hashtable;
6
import java.util.TreeMap;
7
import java.util.Vector;
8

  
9
import org.gvsig.remoteclient.utils.BoundaryBox;
10
import org.gvsig.remoteclient.utils.CapabilitiesTags;
11
import org.kxml2.io.KXmlParser;
12
import org.xmlpull.v1.XmlPullParserException;
13

  
14
/**
15
 * <p>Abstract class that defines an WMSLayer.</p>
16
 *
17
 */
18
public abstract class WMSLayer implements org.gvsig.remoteclient.ILayer {
19

  
20
    protected ArrayList children;
21
    protected WMSLayer parent;
22

  
23
    /**
24
     * <p>Layer Abstract field in the capabilities document </p>
25
     */
26
    private String layerAbstract;
27

  
28
    /**
29
     * <p>Themes provided by the WMS for the layer</p>
30
     */
31
    public ArrayList styles = new ArrayList();
32

  
33
    /**
34
     * <p>Layer name</p>
35
     */
36
    private String name;
37

  
38
    /**
39
     * <p>Layer title</p>
40
     */
41
    private String title;
42

  
43
    private ArrayList keywordList = new ArrayList();
44
    /**
45
     * <p>Layer srs.</p>
46
     */
47
    protected Vector srs = new Vector();
48

  
49
    /**
50
     * <p>extents for each srs the layer can be reproyected to</p>
51
     */
52
    private Hashtable bBoxes  = new Hashtable();
53

  
54
    /**
55
     * <p>extents that defines the bbox for the LatLon projection
56
     * It can be included in the bBoxes vector as well, because it is the most used, we keep it separeted too, according
57
     *  with the OGC WMSCapabilities specifications...
58
     */
59
    private org.gvsig.remoteclient.utils.BoundaryBox latLonBbox;
60

  
61
    /**
62
     * <p>min scale for the layer to be visible</p>
63
     */
64
    private double scaleMin;
65

  
66
    /**
67
     * <p>max scale for the layer to be visible</p>
68
     */
69
    private double scaleMax;
70

  
71
    /**
72
     * <p>Dimensions defined for the layer in the capabilities doc</p>
73
     */
74
    protected java.util.ArrayList dimensions = new ArrayList();
75

  
76
    /**
77
     * Tells if this layer accepts getFeatureInfo requests.
78
     */
79
    private boolean queryable = false;
80

  
81
    /**
82
     * Tells if this layer is opaque.
83
     */
84
    private boolean opaque = false;
85
    /**
86
     * when set to true, noSubsets indicates that the server is not able to make a map
87
     * of a geographic area other than the layer's bounding box.
88
     */
89
    private boolean m_noSubSets = false;
90

  
91
    /**
92
     * when present and non-zero fixedWidth and fixedHeight indicate that the server is not
93
     * able to produce a map of the layer at a width and height different from the fixed sizes indicated.
94
     */
95
    private int fixedWidth = 0;
96
    private int fixedHeight = 0;
97

  
98
    /**
99
     * Tells if this layer can be served with transparency.
100
     */
101
    private boolean transparency;
102

  
103
    /**
104
     * <p>Parses the LAYER tag in the WMS capabilities, filling the WMSLayer object
105
     * loading the data in memory to be easily accesed</p>
106
     *
107
     */
108
    public abstract void parse(KXmlParser parser, TreeMap layerTreeMap)
109
    throws IOException, XmlPullParserException;
110

  
111
    //public abstract ArrayList getAllDimensions();
112

  
113
    /**
114
     * add a new keyword to the keywordList.
115
     * @param key
116
     */
117
    protected void addkeyword(String key)
118
    {
119
    	keywordList.add(key);
120
    }
121
    public ArrayList getKeywords()
122
    {
123
    	return keywordList;
124
    }
125
    /**
126
     * <p>Adds a style to the styles vector</p>
127
     * @param _style
128
     */
129
    public void addStyle(org.gvsig.remoteclient.wms.WMSStyle _style) {
130
        styles.add( _style );    }
131

  
132
   /**
133
     * <p>Gets the style vector</p>
134
     * @return
135
     */
136
    public ArrayList getStyles() {
137
    	ArrayList list = new ArrayList();
138
    	if (styles != null)
139
    		list.addAll(styles);
140
    	if (this.getParent()!= null)
141
    	{
142
    		//return getAllStyles(this);
143
    		if(this.getParent().getStyles() != null)
144
    			list.addAll(this.getParent().getStyles());
145
    	}
146
        return list;
147
    }
148

  
149
    public ArrayList getAllStyles(WMSLayer layer)
150
    {
151
    	if (layer.getParent()!= null)
152
    	{
153
    		ArrayList list = getAllStyles(layer.getParent());
154
    		for(int i = 0; i < this.styles.size(); i++)
155
    		{
156
    			list.add(styles.get(i));
157
    		}
158
    		return list;
159
    	}
160
    	else
161
    	{
162
    		return styles;
163
    	}
164
    }
165
    /**
166
     * <p>Adds a bbox to the Bboxes vector</p>
167
     * @param bbox
168
     */
169
    public void addBBox(BoundaryBox bbox) {
170
        bBoxes.put(bbox.getSrs(), bbox);
171
    }
172

  
173
    /**
174
     * <p>returns the bbox with that id in the Bboxes vector</p>
175
     * @param id
176
     */
177
    public BoundaryBox getBbox(String id) {
178
    	if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0)
179
    		||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0))
180
    	{
181
    		if (latLonBbox != null)
182
    		return (BoundaryBox)latLonBbox;
183
    	}
184
        BoundaryBox b = (BoundaryBox) bBoxes.get(id);
185
        if (b == null && parent!=null)
186
            return parent.getBbox(id);
187
        return (BoundaryBox)bBoxes.get(id);
188
    }
189

  
190
    /**
191
     * <p>Gets the bBoxes vector</p>
192
     * @return
193
     */
194
    public Hashtable getBboxes() {
195
        return bBoxes;
196
    }
197

  
198

  
199
    //Methods to manipulate the box that defines the layer extent in LatLon SRS.
200
    public BoundaryBox getLatLonBox()
201
    {
202
        return latLonBbox;
203
    }
204
    public void setLatLonBox(BoundaryBox box)
205
    {
206
        latLonBbox = box;
207
    }
208
    /**
209
     * <p>adds a new srs to the srs vector</p>
210
     */
211
    public void addSrs(String srs)
212
    {
213
    	if (!this.srs.contains(srs))
214
    		this.srs.add(srs);
215
    }
216

  
217
    public Vector getAllSrs()
218
    {
219
        Vector mySRSs = (Vector) this.srs.clone();
220
        if (parent!=null)
221
            mySRSs.addAll(parent.getAllSrs());
222
        return mySRSs;
223

  
224
//    	if (this.getParent()!= null)
225
//    	{
226
//    		Vector list = this.getParent().getAllSrs();
227
//    		for(int i = 0; i < this.srs.size(); i++)
228
//    		{
229
//    			list.add(srs.get(i));
230
//    		}
231
//    		return list;
232
//    	}
233
//    	else
234
//    	{
235
//    		return srs;
236
//    	}
237

  
238
    }
239
    /**
240
     * <p>gets the maximum scale for this layer</p>
241
     * @return
242
     */
243
    public double getScaleMax() {
244
        return scaleMax;
245
    }
246

  
247
    /**
248
     * <p>gets the minimum scale for this layer</p>
249
     * @return
250
     */
251
    public double getScaleMin() {
252
        return scaleMin;
253
    }
254

  
255
    /**
256
     * <p>sets the minimum scale for this layer to be visible.</p>
257
     *
258
     * @param scale
259
     */
260
    public void setScaleMin(double scale) {
261
        scaleMin = scale;
262
    }
263

  
264
    /**
265
     * <p>sets the maximum scale for this layer to be visible</p>
266
     * @param scale
267
     */
268
    public void setScaleMax(double scale) {
269
        scaleMax = scale;
270
    }
271

  
272
    /**
273
     * <p> gets the dimension vector defined in this layer</p>
274
     * @return
275
     */
276
    public abstract ArrayList getDimensions();
277
//    public ArrayList getDimensions() {
278
//        return dimensions;
279
//    }
280

  
281
    public WMSDimension getDimension(String name)
282
    {
283
    	for(int i = 0; i < dimensions.size(); i++ ){
284
    		if(((WMSDimension)dimensions.get(i)).getName().compareTo(name)==0)
285
    		{
286
    			return (WMSDimension)dimensions.get(i);
287
    		}
288
    	}
289
    	return null;
290
    }
291

  
292
//    /**
293
//     * <p>Sets the dimension vector defined for this layer</p>
294
//     * @param v
295
//     */
296
//    public void setDimensions(ArrayList v) {
297
//        dimensions = (ArrayList)v.clone();
298
//    }
299

  
300
    /**
301
     * <p>Adds a dimension to the dimension vector </p>
302
     * @param dimension
303
     */
304
    public void addDimension(org.gvsig.remoteclient.wms.WMSDimension dimension) {
305
        dimensions.add(dimension);
306
    }
307

  
308
    /**
309
     * <p>Gets layer name</p>
310
     * @return
311
     */
312
    public String getName() {
313
        return this.name;
314
    }
315

  
316
    /**
317
     * <p>Sets layer name</p>
318
     * @param _name
319
     */
320
    public void setName(String name) {
321
        this.name = name;
322
    }
323

  
324
    /**
325
     * <p>Gets layer title</p>
326
     * @return
327
     */
328
    public String getTitle() {
329
        return title;
330
    }
331

  
332
    /**
333
     * <p>Sets the layer title</p>
334
     * @param _title
335
     */
336
    public void setTitle(String title) {
337
        this.title = title;
338
    }
339

  
340
    /**
341
     * <p>Gets the layer abstract</p>
342
     * @return
343
     */
344
    public String getAbstract() {
345
        return layerAbstract;
346
    }
347

  
348
    /**
349
     * <p>Sets the layer abstract</p>
350
     * @param m_abstract
351
     */
352
    public void setAbstract(String _abstract) {
353
        layerAbstract = _abstract;
354
    }
355

  
356

  
357
    public ArrayList getChildren() {
358
        return children;
359
    }
360

  
361

  
362
    public void setChildren(ArrayList children) {
363
        this.children = children;
364
    }
365

  
366

  
367
    public WMSLayer getParent() {
368
        return parent;
369
    }
370

  
371

  
372
    public void setParent(WMSLayer parent) {
373
        this.parent = parent;
374
    }
375

  
376
    public String toString(){
377
        return this.getTitle();
378
    }
379

  
380

  
381
    /**
382
     * Tells if this layer accepts getFeatureInfo requests.
383
     */
384
    public boolean isQueryable() {
385
        return queryable;
386
    }
387

  
388

  
389
    /**
390
     * @param queryable The queryable to set.
391
     */
392
    public void setQueryable(boolean queryable) {
393
        this.queryable = queryable;
394
    }
395

  
396
    /**
397
     * Tells if this layer is opaque.
398
     */
399
    public boolean isOpaque() {
400
        return opaque;
401
    }
402
    /**
403
     * @param opaque.
404
     */
405
    public void setOpaque(boolean opaque) {
406
        this.opaque = opaque;
407
    }
408

  
409
    /**
410
     * Tells if this layer is subsettable
411
     */
412
    public boolean noSubSets() {
413
        return this.m_noSubSets;
414
    }
415
    /**
416
     * @param set layer nosubsets attribute.
417
     */
418
    public void setNoSubSets(boolean _noSubSets) {
419
        m_noSubSets = _noSubSets;
420
    }
421

  
422
    public void setfixedWidth(int w) {
423
        fixedWidth = w;
424
    }
425

  
426
    public int getfixedWidth() {
427
        return fixedWidth;
428
    }
429

  
430
    public void setfixedHeight(int h) {
431
        fixedHeight = h;
432
    }
433

  
434
    public int getfixedHeight() {
435
        return fixedHeight;
436
    }
437

  
438
    /**
439
     * @return <b>true</b> if this layer can be served with transparency, otherwise <b>false</b>
440
     */
441
    public boolean hasTransparency() {
442
        return transparency;
443
    }
444

  
445
    //Methods to parse tags that are common to several versions of WMS.
446
    //In case there is a version which has different implemantation of one of this tags
447
    // the subclass can overwrite this method
448

  
449
    /**
450
     * Parses the keywordlist from the capabilities and fills this list in the WMSLayer.
451
     * @param parser
452
     */
453
    protected void parseKeywordList(KXmlParser parser)  throws IOException, XmlPullParserException
454
    {
455
    	int currentTag;
456
    	boolean end = false;
457
    	String value;
458

  
459
    	parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
460
    	currentTag = parser.nextTag();
461

  
462
        while (!end)
463
    	{
464
			 switch(currentTag)
465
			 {
466
				case KXmlParser.START_TAG:
467
					if (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0)
468
					{
469
						value = parser.nextText();
470
						if ((value != null) && (value.length() > 0 ))
471
							addkeyword(value);
472
					}
473
					break;
474
				case KXmlParser.END_TAG:
475
					if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0)
476
						end = true;
477
					break;
478
				case KXmlParser.TEXT:
479
					break;
480
			 }
481
			 if (!end)
482
			 {
483
				 currentTag = parser.next();
484
			 }
485
    	}
486
    	parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.KEYWORDLIST);
487
    }
488

  
489
    /**
490
     * Reads and parses the layer attributes
491
     * Maybe this method should be moved to the WMSLayer. Until now the attributes are teh same for all versions.
492
     * @param parser
493
     */
494
    protected void readLayerAttributes(KXmlParser parser)
495
    {
496
    	String value = new String();
497

  
498
        //First of all set whether the layer is Queryable reading the attribute.
499
        value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
500
        if (value != null)
501
        {
502
            if (value.compareTo("0")==0)
503
                setQueryable(false);
504
            else
505
                setQueryable(true);
506
        }
507
        value = parser.getAttributeValue("", CapabilitiesTags.OPAQUE);
508
        if (value != null)
509
        {
510
            if (value.compareTo("0")==0)
511
                setOpaque(false);
512
            else
513
                setOpaque(true);
514
        }
515
        value = parser.getAttributeValue("", CapabilitiesTags.NOSUBSETS);
516
        if (value != null)
517
        {
518
            if (value.compareTo("0")==0)
519
                setNoSubSets(false);
520
            else
521
            	setNoSubSets(true);
522
        }
523
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDWIDTH);
524
        if (value != null)
525
        {
526
        	setfixedWidth(Integer.parseInt(value));
527
        }
528
        value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
529
        if (value != null)
530
        {
531
        	setfixedHeight(Integer.parseInt(value));
532
        }
533
    }
534

  
535

  
536
    /**
537
     * <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
538
     *
539
     */
540
    protected class MetadataURL
541
    {
542
    	public MetadataURL()
543
    	{
544
    		type = new String();
545
    		format = new String();
546
    		onlineResource_xlink = new String();
547
    		onlineResource_type = new String();
548
    		onlineResource_href = new String();
549
    	}
550
        public String type;
551
        public String format;
552
        public String onlineResource_xlink;
553
        public String onlineResource_type;
554
        public String onlineResource_href;
555
     }
556

  
557
    /**
558
     * <p>Inner class describing the DataURL tag in OGC specifications in WMS</p>
559
     *
560
     */
561
    protected class DataURL
562
    {
563
    	public DataURL()
564
    	{
565
    		type = new String();
566
    		format = new String();
567
    		onlineResource_xlink = new String();
568
    		onlineResource_type = new String();
569
    		onlineResource_href = new String();
570
    	}
571
        public String type;
572
        public String format;
573
        public String onlineResource_xlink;
574
        public String onlineResource_type;
575
        public String onlineResource_href;
576
     }
577
}
0 578

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/WMSClient.java
1

  
2
package org.gvsig.remoteclient.wms;
3

  
4
import java.awt.geom.Rectangle2D;
5
import java.io.File;
6
import java.io.IOException;
7
import java.net.ConnectException;
8
import java.util.TreeMap;
9
import java.util.Vector;
10

  
11
import org.gvsig.remoteclient.exceptions.ServerErrorException;
12
import org.gvsig.remoteclient.exceptions.WMSException;
13
import org.gvsig.remoteclient.utils.BoundaryBox;
14

  
15

  
16
/**
17
 * <p>Represents the class the with the necessary logic to connect to a OGCWMS and interpretate the data </p>
18
 * 
19
 */
20
public class WMSClient extends org.gvsig.remoteclient.RasterClient {
21
    
22
    private org.gvsig.remoteclient.wms.WMSProtocolHandler handler;
23
//    private TreeMap layers = new TreeMap();
24
//    private WMSLayer rootLayer;
25
    
26
    /**
27
     * @return Returns the rootLayer.
28
     */
29
    public WMSLayer getRootLayer() {
30
        return handler.rootLayer;
31
    }
32

  
33
    /**
34
     * Constructor.
35
     * the parameter host, indicates the WMS host to connect.
36
     * */
37
    public WMSClient(String host) throws ConnectException, IOException 
38
    {
39
    	setHost(host);
40
        try {        	
41
        	handler = WMSProtocolHandlerFactory.negotiate(host);
42
        	handler.setHost(host);        
43
        } catch(ConnectException conE) {
44
        	conE.printStackTrace();
45
        	throw conE; 
46
        } catch(IOException ioE) {
47
        	ioE.printStackTrace();
48
        	throw ioE; 
49
        } catch(Exception e) {
50
        	e.printStackTrace();       	
51
        }
52
    }
53
    
54
    public String getVersion()
55
    {
56
        return handler.getVersion();
57
    }
58
    /**
59
     * <p>One of the three interfaces that OGC WMS defines. Request a map.</p> 
60
     * @throws ServerErrorException 
61
     */
62
    public File getMap(WMSStatus status, ICancellable cancel) throws WMSException, ServerErrorException{   
63
        return handler.getMap(status, cancel);
64
    } 
65
    
66
    /**
67
     * <p>One of the three interfaces defined by OGC WMS, it gets the service capabilities</p>
68
     * @param override, if true the previous downloaded data will be overridden
69
     */
70
    public void getCapabilities(WMSStatus status, boolean override, ICancellable cancel) {        
71
        handler.getCapabilities(status, override, cancel);
72
    } 
73
    
74
    /**
75
     * <p>One of the three interfaces defined by the OGC WMS, it gets the information about a feature requested</p>
76
     * @return 
77
     */
78
    public String getFeatureInfo(WMSStatus status, int x, int y, int featureCount, ICancellable cancel) throws WMSException{        
79
        return handler.getFeatureInfo(status, x, y, featureCount, cancel);
80
    } 
81
    
82
    /**
83
     * <p>One of the three interfaces defined by the OGC WMS, it gets legend of a layer</p>
84
     * @return 
85
     */
86
    public File getLegendGraphic(WMSStatus status, String layerName, ICancellable cancel) throws WMSException, ServerErrorException{        
87
        return handler.getLegendGraphic(status, layerName, cancel);
88
    } 
89
    
90
    /**
91
     * <p> Reads from the WMS Capabilities, the layers available in the service</p>
92
     * @return a TreeMap with the available layers in the WMS 
93
     */
94
    public TreeMap getLayers() {        
95
        return handler.layers;
96
    } 
97
    
98
    /**
99
     * <p>Reads from the WMS Capabilities the number if layers available in the service</p>
100
     * @return, number of layers available
101
     */
102
    public int getNumberOfLayers() {        
103
        if (handler.layers != null)
104
        {
105
            return handler.layers.size();
106
        }
107
        return 0;
108
    } 
109
    
110
    /**
111
     * <p>Gets the WMSLayer with this name</p>
112
     * 
113
     * @param _name, layer name
114
     * @return the layer with this name
115
     */
116
    public WMSLayer getLayer(String _name) {        
117
        if (handler.layers.get(_name) != null)
118
        {
119
            return (WMSLayer)handler.layers.get(_name);
120
        }
121
        
122
        return null;
123
    } 
124
    
125
    public String[] getLayerNames()
126
    {    	
127
        WMSLayer[] lyrs;
128
        
129
        lyrs = (WMSLayer[])handler.layers.values().toArray(new WMSLayer[0]);
130
        
131
        String[] names = new String[lyrs.length];
132
        
133
        for(int i = 0; i<lyrs.length; i++)
134
        {
135
            names[i] = ((WMSLayer)lyrs[i]).getName();
136
        }
137
        return names;
138
    }
139
    
140
    public String[] getLayerTitles()
141
    {    	
142
        WMSLayer[] lyrs;
143
        
144
        lyrs = (WMSLayer[])handler.layers.values().toArray(new WMSLayer[0]);
145
        
146
        String[] titles = new String[lyrs.length];
147
        
148
        for(int i = 0; i<lyrs.length; i++)
149
        {
150
            titles[i] = ((WMSLayer)lyrs[i]).getTitle();
151
        }
152
        return titles;
153
    }
154
    /**
155
     * <p>Gets the image formats available in the Service to retrieve the maps</p>
156
     * @return a vector with all the available formats
157
     */
158
    public Vector getFormats() {        
159
        return ((WMSServiceInformation)handler.getServiceInformation()).formats;         
160
    } 
161
    
162
    public boolean isQueryable()
163
    {
164
    	return ((WMSServiceInformation)handler.getServiceInformation()).isQueryable();  
165
    }
166
    public boolean hasLegendGraphic()
167
    {
168
    	return ((WMSServiceInformation)handler.getServiceInformation()).hasLegendGraphic();  
169
    }
170
    
171
    public void close() {        
172
        // your code here
173
    } 
174
    
175
    
176
    /**
177
     * Returns the max extent that envolves the requested layers
178
     * */
179
    public Rectangle2D getLayersExtent(String[]layerNames, String srs)
180
    {
181
        try
182
        {
183
        	if (layerNames == null) return null;
184
            BoundaryBox bbox;
185
            WMSLayer layer = getLayer(layerNames[0]);
186
            
187
            bbox = layer.getBbox(srs);
188
            if (bbox == null) return null;
189
            double xmin = bbox.getXmin();
190
            double xmax = bbox.getXmax();
191
            double ymin = bbox.getYmin();
192
            double ymax = bbox.getYmax();
193
            
194
            for(int i=1; i<layerNames.length; i++)
195
            {
196
                layer = getLayer(layerNames[i]);
197
                bbox = layer.getBbox(srs);
198
                if (bbox == null) return null;
199
                if (bbox.getXmin() < xmin)
200
                {
201
                    xmin = bbox.getXmin();
202
                }
203
                if (bbox.getYmin() < ymin)
204
                {
205
                    ymin = bbox.getYmin();
206
                }
207
                if (bbox.getXmax() > xmax)
208
                {
209
                    xmax = bbox.getXmax();
210
                }
211
                if (bbox.getYmax() > ymax)
212
                {
213
                    ymax = bbox.getYmax();
214
                }
215
            }	
216
            
217
            Rectangle2D extent = new Rectangle2D.Double(xmin,ymin,Math.abs(xmax-xmin),Math.abs(ymax-ymin));
218
            return extent;
219
        }
220
        catch(Exception e)
221
        {
222
            e.printStackTrace();
223
            return null;
224
        }
225
    }
226
    
227
    
228
    /**
229
     * Gets the Service information included in the Capabilities
230
     * */    
231
    public WMSServiceInformation getServiceInformation()
232
    {
233
        return ((WMSServiceInformation)handler.getServiceInformation());
234
    }
235
    
236
    
237
    /**
238
     * <p>Checks the connection to de remote WMS and requests its capabilities.</p>
239
     * @param override, if true the previous downloaded data will be overridden
240
     */
241
    public boolean connect(boolean override, ICancellable cancel) 
242
    {
243
        try {            
244
            if (handler == null)
245
            {
246
                if (getHost().trim().length() > 0)
247
                {					
248
                    //TODO: Implement correctly the negotiate algorithm
249
                    handler = WMSProtocolHandlerFactory.negotiate(getHost());
250
                    //handler = new WMSProtocolHandler1_1_1();
251
                    handler.setHost(getHost());
252
                }
253
                else
254
                {
255
                    //must to specify host first!!!!
256
                    return false;
257
                }                
258
            }
259
            getCapabilities(null, override, cancel);
260
            return true;
261
            
262
        } catch (Exception e) {
263
            e.printStackTrace();
264
            return false;
265
        }
266
    }
267
    
268
    //TODO Check this out: Always 1 layer at first level...
269
    public WMSLayer getLayersRoot() {
270
        return handler.rootLayer;
271
    }
272

  
273
	public boolean connect(ICancellable cancel) {
274
		return connect(false, cancel);
275
	}
276
}
0 277

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/request/WMSGetFeatureInfoRequest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 Iver T.I.  {{Task}}
26
*/
27
 
28
package org.gvsig.remoteclient.wms.request;
29

  
30
import org.gvsig.remoteclient.utils.CapabilitiesTags;
31
import org.gvsig.remoteclient.wms.WMSProtocolHandler;
32
import org.gvsig.remoteclient.wms.WMSStatus;
33

  
34
/**
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public abstract class WMSGetFeatureInfoRequest extends WMSRequest {
38
	protected int x;
39
	protected int y;
40
	
41
	public WMSGetFeatureInfoRequest(WMSStatus status, WMSProtocolHandler protocolHandler, int x, int y) {
42
		super(status, protocolHandler);	
43
		this.x = x;
44
		this.y = y;
45
	}
46

  
47
	/*
48
	 * (non-Javadoc)
49
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getHttpPostRequest(java.lang.String)
50
	 */
51
	protected String getHttpPostRequest(String onlineResource) {
52
		// TODO Auto-generated method stub
53
		return null;
54
	}
55

  
56
	/*
57
	 * (non-Javadoc)
58
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getOperationCode()
59
	 */
60
	protected String getOperationName() {
61
		return CapabilitiesTags.GETFEATUREINFO;
62
	}
63

  
64
	/*
65
	 * (non-Javadoc)
66
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getTempFilePrefix()
67
	 */
68
	protected String getTempFilePrefix() {
69
		return "wms_getFeatureInfo.xml";
70
	}
71
}
72

  
73

  
0 74

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/request/WMSGetLegendGraphicRequest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 Iver T.I.  {{Task}}
26
*/
27
 
28
package org.gvsig.remoteclient.wms.request;
29

  
30
import org.gvsig.remoteclient.utils.CapabilitiesTags;
31
import org.gvsig.remoteclient.wms.WMSProtocolHandler;
32
import org.gvsig.remoteclient.wms.WMSStatus;
33

  
34
/**
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public abstract class WMSGetLegendGraphicRequest extends WMSRequest {
38
	protected String layerName = null;	
39
	
40
	public WMSGetLegendGraphicRequest(WMSStatus status, WMSProtocolHandler protocolHandler, String layerName) {
41
		super(status, protocolHandler);	
42
		this.layerName = layerName;
43
	}
44

  
45
	/*
46
	 * (non-Javadoc)
47
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getHttpPostRequest(java.lang.String)
48
	 */
49
	protected String getHttpPostRequest(String onlineResource) {
50
		// TODO Auto-generated method stub
51
		return null;
52
	}
53

  
54
	/*
55
	 * (non-Javadoc)
56
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getOperationCode()
57
	 */
58
	protected String getOperationName() {
59
		return CapabilitiesTags.GETLEGENDGRAPHIC;
60
	}
61

  
62
	/*
63
	 * (non-Javadoc)
64
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getTempFilePrefix()
65
	 */
66
	protected String getTempFilePrefix() {
67
		return "wms_getLegendGraphic.xml";
68
	}
69
}
70

  
0 71

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/request/WMSGetMapRequest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 Iver T.I.  {{Task}}
26
*/
27
 
28
package org.gvsig.remoteclient.wms.request;
29

  
30
import org.gvsig.remoteclient.utils.CapabilitiesTags;
31
import org.gvsig.remoteclient.wms.WMSProtocolHandler;
32
import org.gvsig.remoteclient.wms.WMSStatus;
33

  
34
/**
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public abstract class WMSGetMapRequest extends WMSRequest {
38
		
39
	public WMSGetMapRequest(WMSStatus status, WMSProtocolHandler protocolHandler) {
40
		super(status, protocolHandler);		
41
	}
42

  
43
	/*
44
	 * (non-Javadoc)
45
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getHttpPostRequest(java.lang.String)
46
	 */
47
	protected String getHttpPostRequest(String onlineResource) {
48
		// TODO Auto-generated method stub
49
		return null;
50
	}
51

  
52
	/*
53
	 * (non-Javadoc)
54
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getOperationCode()
55
	 */
56
	protected String getOperationName() {
57
		return CapabilitiesTags.GETMAP;
58
	}
59

  
60
	/*
61
	 * (non-Javadoc)
62
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getTempFilePrefix()
63
	 */
64
	protected String getTempFilePrefix() {
65
		return "wms_getMap.xml";
66
	}
67
}
68

  
69

  
0 70

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/request/WMSRequest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 Iver T.I.  {{Task}}
26
 */
27

  
28
/**
29
 * This class sends a WMS request and returns the
30
 * reply in a local File. It tries if the server
31
 * supports both HTTP Get and Post requests.
32
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
33
 */
34
package org.gvsig.remoteclient.wms.request;
35

  
36
import java.util.Vector;
37

  
38
import org.gvsig.remoteclient.ogc.request.OGCRequest;
39
import org.gvsig.remoteclient.utils.Utilities;
40
import org.gvsig.remoteclient.wms.WMSProtocolHandler;
41
import org.gvsig.remoteclient.wms.WMSStatus;
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public abstract class WMSRequest extends OGCRequest{
47
	protected WMSStatus status = null;
48
	
49
	public WMSRequest(WMSStatus status,
50
			WMSProtocolHandler protocolHandler) {
51
		super(status, protocolHandler);
52
		this.status = status;
53
	}
54
	
55

  
56
	/*
57
	 * (non-Javadoc)
58
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getSchemaLocation()
59
	 */
60
	protected String getSchemaLocation() {
61
		return null;
62
	}
63
	
64
	/**
65
     * Gets the part of the OGC request that share GetMap and GetFeatureInfo
66
     * @return String request
67
     */
68
    protected String getPartialQuery(WMSStatus status)
69
    {
70
        StringBuffer req = new StringBuffer();
71
        req.append("LAYERS=" + Utilities.Vector2CS(status.getLayerNames()))
72
           .append("&SRS=" + status.getSrs())
73
           .append("&BBOX=" + status.getExtent().getMinX()+ "," )
74
           .append(status.getExtent().getMinY()+ ",")
75
           .append(status.getExtent().getMaxX()+ ",")
76
           .append(status.getExtent().getMaxY())
77
           .append("&WIDTH=" + status.getWidth())
78
           .append("&HEIGHT=" + status.getHeight())
79
           .append("&FORMAT=" + status.getFormat())
80
           .append("&STYLES=");
81
        Vector v = status.getStyles();
82
        if (v!=null && v.size()>0)
83
        	req.append(Utilities.Vector2CS(v));
84
        v = status.getDimensions();
85
        if (v!=null && v.size()>0)
86
            req.append("&" + Utilities.Vector2URLParamString(v));
87
        if (status.getTransparency()) {
88
            req.append("&TRANSPARENT=TRUE");
89
        }
90
        return req.toString();
91
    }
92
	
93
}
0 94

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wms/WMSStatus.java
1

  
2
package org.gvsig.remoteclient.wms;
3

  
4
import java.awt.geom.Rectangle2D;
5
import java.util.Vector;
6

  
7
/**
8
 * Describes the status of a WMSclient, so it adds to the Remote client status
9
 * a list of layers, a list of layer styles, the extent of the map.
10
 * Provides the functionality to modify these lists.
11
 * 
12
 */
13
public class WMSStatus extends org.gvsig.remoteclient.RemoteClientStatus {
14
	// list of layer to be retrieved by the WMS
15
    private Vector layers;
16
    // List of layer styles
17
    private Vector styles;
18
    private Vector dimensions;
19
    // extent required by the WMS client
20
    private Rectangle2D extent;
21
    private boolean transparency;
22
	private String onlineResource;
23
    public WMSStatus()
24
    {
25
    	layers = new Vector();
26
    	styles = new Vector();    	    	
27
    }
28
    
29
    // sets the list of layers required by the WMS client
30
    public void setLayerNames(Vector _layers) {        
31
        layers = _layers;
32
    } 
33

  
34
/**
35
 * <p>Retrieves the layer list required by the WMS client</p>
36
 * 
37
 * 
38
 * @return Vector, the list of layers
39
 */
40
    public Vector getLayerNames() {        
41
        return layers;
42
    } 
43

  
44
/**
45
 * <p> Adds a layer to the list of layers required by the WMS client</p>
46
 * 
47
 * 
48
 * @param _layerName, name of the layer to be added. 
49
 */
50
    public void addLayerName(String _layerName) {        
51
        layers.add(_layerName);
52
    } 
53

  
54
/**
55
 * <p>removes a layer from the layer list</p>
56
 * 
57
 * 
58
 * @param _layerName 
59
 * @return true if the layer name has been deleted from the list
60
 */
61
    public boolean removeLayerName(String _layerName) {
62
    	return layers.remove(_layerName);       
63
    } 
64

  
65
/**
66
 * <p>gets the styles list required by the WMS client</p>
67
 * 
68
 * 
69
 * @return Vector with the list of layer styles
70
 */
71
    public Vector getStyles() {        
72
        return styles;
73
    } 
74

  
75
/**
76
 * <p>sets the styles list required by the WMS client</p>
77
 * 
78
 * 
79
 * @param _styles, list to be set as the required styles.
80
 */
81
    public void setStyles(Vector _styles) {        
82
        styles = _styles;
83
    }
84
    
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff