Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wms / wms_1_1_1 / WMSLayer1_1_1.java @ 40559

History | View | Annotate | Download (11.4 KB)

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_1;
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.1</p>
45
 * 
46
 */
47
public class WMSLayer1_1_1 extends org.gvsig.remoteclient.wms.WMSLayer {
48
    
49
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
50
    
51
         /**
52
     * <p>Extents defined for the layer in the capabilities doc</p>
53
     */
54
    private java.util.ArrayList extents = new ArrayList();
55
    
56
    /**
57
     * <p> gets the extent vector defined in this layer</p>
58
     * @return 
59
     */
60
    public ArrayList getExtents() {        
61
        return extents;
62
    } 
63
    
64
    public WMSExtent getExtent(String name)
65
    {
66
            for(int i = 0; i < extents.size(); i++ ){
67
                    if(((WMSExtent)extents.get(i)).getName().compareTo(name)==0)
68
                    {
69
                            return (WMSExtent)extents.get(i);
70
                    }
71
            }
72
            return null;
73
    }
74
    
75
    public ArrayList getDimensions()
76
    {   
77
        WMSDimension dimension;
78
        WMSExtent extent;
79
            for(int i = 0; i < dimensions.size(); i++)
80
            {
81
                    dimension = (WMSDimension)dimensions.get(i);
82
                    extent = getExtent(dimension.getName()); 
83
                    if(extent != null)
84
                    {                            
85
                            ((WMSDimension)dimensions.get(i)).setDimensionExpression( extent.getExtentExpression());                            
86
                    }
87
            }            
88
            
89
        WMSDimension pDimension;
90
        WMSDimension myDimension;    
91
        ArrayList myDimensions = (ArrayList) this.dimensions.clone();        
92
        ArrayList pDimensions;        
93
        if (parent!=null)
94
        {
95
                pDimensions = parent.getDimensions();
96
                for (int i= 0; i < pDimensions.size(); i++){
97
                        pDimension = (WMSDimension)pDimensions.get(i);
98
                        myDimension = getDimension(pDimension.getName());
99
                        if (myDimension != null){
100
                                pDimensions.remove(pDimension);
101
                        }
102
                }
103
                myDimensions.addAll(pDimensions);
104
        }
105
        return myDimensions;
106
    }
107
    
108
    /**
109
     * <p>Adds an extent to the extent vector </p>
110
     * @param extent 
111
     */
112
    public void addExtent(org.gvsig.remoteclient.wms.WMSExtent extent) {        
113
        extents.add(extent);
114
    }   
115
    
116
    public WMSLayer1_1_1()
117
    {
118
        children = new ArrayList();
119
    }
120
    /**
121
     * <p>Parses the contents of the parser(WMSCapabilities)
122
     * to extract the information about an WMSLayer</p>
123
     * 
124
     */
125
    public void parse(KXmlParser parser, TreeMap layerTreeMap)
126
    throws IOException, XmlPullParserException
127
    {
128
        int currentTag;
129
        boolean end = false;
130
        String value;
131
        BoundaryBox bbox;
132
        parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LAYER);
133
       
134
        readLayerAttributes(parser);
135
        currentTag = parser.nextTag();
136
        
137
        while (!end) 
138
        {
139
            switch(currentTag)
140
            {
141
                case KXmlParser.START_TAG:
142
                    if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0)
143
                    {        
144
                        WMSLayer1_1_1 lyr = new WMSLayer1_1_1();                                                
145
                        //parser.next(); 
146
                        lyr.parse(parser, layerTreeMap);
147
                        lyr.setParent(this);                       
148
                        this.children.add(lyr);
149
                        // Jaume
150
                        if (lyr.getName()!=null)
151
                            layerTreeMap.put(lyr.getName(), lyr);
152
                    }
153
                    else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION)==0){
154
                        // TODO comprobar que esto se necesite o se deseche
155
                        parser.skipSubTree();
156
                    }
157
                    else if (parser.getName().compareTo(CapabilitiesTags.NAME)==0)
158
                    {                
159
                        value = parser.nextText();
160
                        if (value != null) setName(value);                                                
161
                    }        
162
                    else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0)
163
                    {
164
                        value = parser.nextText();
165
                        if (value != null) setTitle(value);
166
                    }
167
                    else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0)
168
                    {
169
                        value = parser.nextText();
170
                        if (value != null) setAbstract(value);
171
                    }
172
                    else if (parser.getName().compareTo(CapabilitiesTags.SRS)==0)
173
                    {
174
                        value = parser.nextText();
175
                        if (value != null){
176
                            String[] mySRSs = stringUtils.split(value, " ");
177
                            for (int i = 0; i < mySRSs.length; i++) {
178
                                addSrs(mySRSs[i]);    
179
                            }                            
180
                        }
181
                    }                                        
182
                    else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0)
183
                    {
184
                        bbox = new BoundaryBox();
185
                        value = parser.getAttributeValue("",CapabilitiesTags.SRS);
186
                        if (value != null)
187
                            bbox.setSrs(value);
188
                        value = parser.getAttributeValue("",CapabilitiesTags.MINX);
189
                        if ((value != null) && (Utilities.isNumber(value)))
190
                            bbox.setXmin(Double.parseDouble(value));        
191
                        value = parser.getAttributeValue("",CapabilitiesTags.MINY);
192
                        if ((value != null) && (Utilities.isNumber(value)))
193
                            bbox.setYmin(Double.parseDouble(value));        
194
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
195
                        if ((value != null) && (Utilities.isNumber(value)))
196
                            bbox.setXmax(Double.parseDouble(value));        
197
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
198
                        if ((value != null) && (Utilities.isNumber(value)))
199
                            bbox.setYmax(Double.parseDouble(value));        
200
                        addBBox(bbox);
201
                        addSrs(bbox.getSrs());
202
                    }        
203
                    else if (parser.getName().compareTo(CapabilitiesTags.LATLONBOUNDINGBOX)==0)
204
                    {
205
                        bbox = new BoundaryBox();
206
                        bbox.setSrs(CapabilitiesTags.EPSG_4326);
207
                        value = parser.getAttributeValue("",CapabilitiesTags.MINX);
208
                        if ((value != null) && (Utilities.isNumber(value)))
209
                            bbox.setXmin(Double.parseDouble(value));        
210
                        value = parser.getAttributeValue("",CapabilitiesTags.MINY);
211
                        if ((value != null) && (Utilities.isNumber(value)))
212
                            bbox.setYmin(Double.parseDouble(value));        
213
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
214
                        if ((value != null) && (Utilities.isNumber(value)))
215
                            bbox.setXmax(Double.parseDouble(value));        
216
                        value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
217
                        if ((value != null) && (Utilities.isNumber(value)))
218
                            bbox.setYmax(Double.parseDouble(value));        
219
                        addBBox(bbox);
220
                        setLatLonBox(bbox);
221
                        addSrs(bbox.getSrs());
222
                    }                                                
223
                    else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0)
224
                    {
225
                        value = parser.getAttributeValue("",CapabilitiesTags.MIN);
226
                        if ((value != null) && (Utilities.isNumber(value)))
227
                            setScaleMin(Double.parseDouble(value));
228
                        value = parser.getAttributeValue("",CapabilitiesTags.MAX);
229
                        if ((value != null) && (Utilities.isNumber(value)))
230
                            setScaleMax(Double.parseDouble(value));                                                                                                                                        
231
                    }                                                
232
                    else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0)
233
                    {
234
                        WMSStyle1_1_1 style = new WMSStyle1_1_1();
235
                        style.parse(parser);
236
                        if ((style != null) && (style.getName() != null))
237
                        {
238
                            styles.add(style);
239
                        }
240
                    }
241
                    else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0)
242
                    {
243
                        WMSDimension dim = new WMSDimension();
244
                        dim.parse(parser);
245
                        if ((dim != null) && (dim.getName() != null))
246
                        {
247
                            addDimension(dim);
248
                        }
249
                    }
250
                    else if (parser.getName().compareTo(CapabilitiesTags.EXTENT)==0)
251
                    {                            
252
                        WMSExtent extent = new WMSExtent();
253
                        extent.parse(parser);
254
                        if ((extent != null) && (extent.getName() != null))
255
                        {
256
                            addExtent(extent);
257
                            
258
                        }
259
                    }                      
260
                    else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST)==0)
261
                    {
262
                            parseKeywordList(parser);
263
                    }                    
264
                    break;
265
                case KXmlParser.END_TAG:
266
                    if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0)
267
                        end = true;
268
                    break;
269
                case KXmlParser.TEXT:                                        
270
                    break;
271
            }
272
            if (!end)
273
                    currentTag = parser.next();
274
        }
275
        parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LAYER);
276
    }      
277
    
278
    public String toString(){
279
        return super.toString();
280
    }
281
}