Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / wfs_1_1_0 / WFSFeature1_1_0.java @ 34402

History | View | Annotate | Download (8.94 KB)

1
package org.gvsig.remoteclient.wfs.wfs_1_1_0;
2

    
3
import java.io.IOException;
4

    
5
import org.kxml2.io.KXmlParser;
6
import org.xmlpull.v1.XmlPullParserException;
7

    
8
import org.gvsig.compat.CompatLocator;
9
import org.gvsig.compat.lang.StringUtils;
10
import org.gvsig.remoteclient.utils.BoundaryBox;
11
import org.gvsig.remoteclient.utils.CapabilitiesTags;
12
import org.gvsig.remoteclient.utils.Utilities;
13
import org.gvsig.remoteclient.wfs.WFSFeature;
14
import org.gvsig.remoteclient.wfs.WFSServiceInformation;
15
import org.gvsig.remoteclient.wfs.schema.GMLTags;
16
import org.gvsig.remoteclient.wfs.schema.XMLNameSpace;
17

    
18
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
19
 *
20
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
21
 *
22
 * This program is free software; you can redistribute it and/or
23
 * modify it under the terms of the GNU General Public License
24
 * as published by the Free Software Foundation; either version 2
25
 * of the License, or (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
35
 *
36
 * For more information, contact:
37
 *
38
 *  Generalitat Valenciana
39
 *   Conselleria d'Infraestructures i Transport
40
 *   Av. Blasco Ib??ez, 50
41
 *   46010 VALENCIA
42
 *   SPAIN
43
 *
44
 *      +34 963862235
45
 *   gvsig@gva.es
46
 *      www.gvsig.gva.es
47
 *
48
 *    or
49
 *
50
 *   IVER T.I. S.A
51
 *   Salamanca 50
52
 *   46005 Valencia
53
 *   Spain
54
 *
55
 *   +34 963163400
56
 *   dac@iver.es
57
 */
58
/* CVS MESSAGES:
59
 *
60
 * $Id: WFSFeature1_1_0.java 34402 2011-01-13 16:47:02Z nbrodin $
61
 * $Log$
62
 * Revision 1.1  2007-02-09 14:11:01  jorpiell
63
 * Primer piloto del soporte para WFS 1.1 y para WFS-T
64
 *
65
 *
66
 */
67
/**
68
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
69
 */
70
public class WFSFeature1_1_0 extends WFSFeature{
71
    
72
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
73
    
74
    public WFSFeature1_1_0(WFSServiceInformation serviceInformation) {
75
        super(serviceInformation);
76
    }
77
        
78
        WFSFeature1_1_0(WFSServiceInformation serviceInformation, String name) {
79
                super(serviceInformation, name);                
80
        }
81

    
82
        /**
83
         * <p>Parses the contents of the parser(WMSCapabilities)
84
         * to extract the information about an WMSLayer</p>
85
         * @throws IOException 
86
         * @throws XmlPullParserException 
87
         * 
88
         */
89
        public void parse(KXmlParser parser) throws XmlPullParserException, IOException{
90
                int currentTag;
91
                boolean end = false;
92
                
93
                parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_FEATURETYPE);
94
                
95
                for (int i=0 ; i<parser.getAttributeCount() ; i++){
96
                        String[] attName = stringUtils.split(parser.getAttributeName(i), ":");
97
                        if (attName.length == 2){
98
                                if (attName[0].compareTo(GMLTags.XML_NAMESPACE)==0){
99
                                        XMLNameSpace nameSpace = new XMLNameSpace(attName[1],parser.getAttributeValue(i));
100
                                        this.setNamespace(nameSpace);
101
                                }
102
                        }
103
                }
104
                
105
                currentTag = parser.next();
106
                while (!end) 
107
                {
108
                        switch(currentTag)
109
                        {
110
                        case KXmlParser.START_TAG:
111
                                if (parser.getName().compareToIgnoreCase(CapabilitiesTags.NAME)==0)
112
                                {
113
                                        this.setName(parser.nextText());
114
                                }else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.TITLE)==0){
115
                                        this.setTitle(parser.nextText());
116
                                }else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_KEYWORDS)==0){
117
                                        parser.nextTag();
118
                                        while (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0){
119
                                                parser.next();
120
                                                String keyword = parser.getText();
121
                                                if ((keyword != null) || (!(keyword.equals("")))){
122
                                                        this.addKeyword(keyword);
123
                                                }
124
                                                //Keyword end tag
125
                                                parser.nextTag();
126
                                                //Keyword start tag?
127
                                                parser.nextTag();
128
                                        }
129
                                        
130
                                                                        
131
                                } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.KEYWORD)==0){
132
                                        this.addKeyword(parser.nextText());                                                                        
133
                                } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.SRS)==0){
134
                                     String value = parser.nextText();
135
                     if (value != null){
136
                         String[] mySRSs = stringUtils.split(value, " ");
137
                         for (int i = 0; i < mySRSs.length; i++) {
138
                             this.addSRS(mySRSs[i]);    
139
                         }
140
                         
141
                     }
142
                                } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.DEAFAULTSRS)==0){
143
                                     String value = parser.nextText();
144
                     setDefaultSRS(value.trim());                           
145
                                } else        if (parser.getName().compareToIgnoreCase(CapabilitiesTags.LATLONGBOUNDINGBOX)==0){
146
                                        BoundaryBox bbox = new BoundaryBox();
147
                                        bbox.setSrs(CapabilitiesTags.EPSG_4326);
148
                    String value = parser.getAttributeValue("",CapabilitiesTags.MINX);
149
                    if ((value != null) && (Utilities.isNumber(value)))
150
                        bbox.setXmin(Double.parseDouble(value));        
151
                    value = parser.getAttributeValue("",CapabilitiesTags.MINY);
152
                    if ((value != null) && (Utilities.isNumber(value)))
153
                        bbox.setYmin(Double.parseDouble(value));        
154
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
155
                    if ((value != null) && (Utilities.isNumber(value)))
156
                        bbox.setXmax(Double.parseDouble(value));        
157
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
158
                    if ((value != null) && (Utilities.isNumber(value)))
159
                        bbox.setYmax(Double.parseDouble(value));
160
                    this.addBBox(bbox);
161
                    this.setLatLonBbox(bbox);                                 
162
                                } else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0){
163
                                        BoundaryBox bbox = new BoundaryBox();
164
                    String value = parser.getAttributeValue("",CapabilitiesTags.SRS);
165
                    if (value != null)
166
                        bbox.setSrs(value);
167
                    value = parser.getAttributeValue("",CapabilitiesTags.MINX);
168
                    if ((value != null) && (Utilities.isNumber(value)))
169
                        bbox.setXmin(Double.parseDouble(value));        
170
                    value = parser.getAttributeValue("",CapabilitiesTags.MINY);
171
                    if ((value != null) && (Utilities.isNumber(value)))
172
                        bbox.setYmin(Double.parseDouble(value));        
173
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
174
                    if ((value != null) && (Utilities.isNumber(value)))
175
                        bbox.setXmax(Double.parseDouble(value));        
176
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
177
                    if ((value != null) && (Utilities.isNumber(value)))
178
                        bbox.setYmax(Double.parseDouble(value));        
179
                    if (bbox.getSrs() != null){
180
                            this.addBBox(bbox);
181
                            this.addSRS(bbox.getSrs());
182
                    }
183
                } else if (CapabilitiesTags.WGS84BOUNDINGBOX.equals(parser.getName())){
184
                                        String lowerCorner = null;
185
                                        String upperCorner = null;
186
                                        parser.next();
187
                                        String tagName = parser.getName();                                        
188
                                        while(!CapabilitiesTags.WGS84BOUNDINGBOX.equals(tagName)){
189
                                                if ((CapabilitiesTags.LOWERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){
190
                                                        parser.next();
191
                                                        lowerCorner = parser.getText();
192
                                                }else if ((CapabilitiesTags.UPPERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){
193
                                                        parser.next();
194
                                                        upperCorner = parser.getText();
195
                                                }
196
                                                currentTag = parser.next();
197
                                                tagName = parser.getName();                                                
198
                                        }
199
                                        if ((lowerCorner != null) && (upperCorner != null)){
200
                                                BoundaryBox bbox = new BoundaryBox();
201
                                                bbox.setSrs("EPSG:4326");
202
                                                String[] lowerCoordinates = stringUtils.split(lowerCorner, "[! \t\r\n]");
203
                                                if (lowerCoordinates.length >= 2){
204
                                                        try{
205
                                                                bbox.setXmin(Double.valueOf(lowerCoordinates[0]).doubleValue());
206
                                                                bbox.setYmin(Double.valueOf(lowerCoordinates[1]).doubleValue());
207
                                                        }catch(NumberFormatException e){
208
                                                                //Is not a number
209
                                                        }
210
                                                }
211
                                                String[] upperCoordinates = stringUtils.split(upperCorner, "[! \t\r\n]");
212
                                                if (upperCoordinates.length >= 2){
213
                                                        try{
214
                                                                bbox.setXmax(Double.valueOf(upperCoordinates[0]).doubleValue());
215
                                                                bbox.setYmax(Double.valueOf(upperCoordinates[1]).doubleValue());
216
                                                        }catch(NumberFormatException e){
217
                                                                //Is not a number
218
                                                        }
219
                                                }                                                
220
                                                this.addBBox(bbox);
221
                                                this.setLatLonBbox(bbox);            
222
                                        }
223
                }         
224
                                
225
                                break;
226
                        case KXmlParser.END_TAG:
227
                                if (parser.getName().compareTo(CapabilitiesTags.WFS_FEATURETYPE) == 0)
228
                                        end = true;
229
                                break;
230
                        case KXmlParser.TEXT:                   
231
                                break;
232
                        }
233
                        if (!end){
234
                                currentTag = parser.next();
235
                        }
236
                }    
237
        }
238
}