Statistics
| Revision:

root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / remoteclient / wfs / wfs_1_1_0 / WFSFeature1_1_0.java @ 112

History | View | Annotate | Download (8.85 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
package org.gvsig.remoteclient.wfs.wfs_1_1_0;
25

    
26
import java.io.IOException;
27

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

    
31
import org.gvsig.compat.CompatLocator;
32
import org.gvsig.compat.lang.StringUtils;
33
import org.gvsig.remoteclient.utils.BoundaryBox;
34
import org.gvsig.remoteclient.utils.CapabilitiesTags;
35
import org.gvsig.remoteclient.utils.Utilities;
36
import org.gvsig.remoteclient.wfs.WFSFeature;
37
import org.gvsig.remoteclient.wfs.WFSServiceInformation;
38
import org.gvsig.remoteclient.wfs.schema.GMLTags;
39
import org.gvsig.remoteclient.wfs.schema.XMLNameSpace;
40

    
41
/**
42
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
43
 */
44
public class WFSFeature1_1_0 extends WFSFeature{
45

    
46
    private static final StringUtils stringUtils = CompatLocator.getStringUtils();
47

    
48
    public WFSFeature1_1_0(WFSServiceInformation serviceInformation) {
49
        super(serviceInformation);
50
    }
51

    
52
        WFSFeature1_1_0(WFSServiceInformation serviceInformation, String name) {
53
                super(serviceInformation, name);
54
        }
55

    
56
        /**
57
         * <p>Parses the contents of the parser(WMSCapabilities)
58
         * to extract the information about an WMSLayer</p>
59
         * @throws IOException
60
         * @throws XmlPullParserException
61
         *
62
         */
63
        public void parse(KXmlParser parser) throws XmlPullParserException, IOException{
64
                int currentTag;
65
                boolean end = false;
66

    
67
                parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_FEATURETYPE);
68

    
69
                for (int i=0 ; i<parser.getAttributeCount() ; i++){
70
                        String[] attName = stringUtils.split(parser.getAttributeName(i), ":");
71
                        if (attName.length == 2){
72
                                if (attName[0].compareTo(GMLTags.XML_NAMESPACE)==0){
73
                                        XMLNameSpace nameSpace = new XMLNameSpace(attName[1],parser.getAttributeValue(i));
74
                                        this.setNamespace(nameSpace);
75
                                }
76
                        }
77
                }
78

    
79
                currentTag = parser.next();
80
                while (!end)
81
                {
82
                        switch(currentTag)
83
                        {
84
                        case KXmlParser.START_TAG:
85
                                if (parser.getName().compareToIgnoreCase(CapabilitiesTags.NAME)==0)
86
                                {
87
                                        this.setName(parser.nextText());
88
                                }else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.TITLE)==0){
89
                                        this.setTitle(parser.nextText());
90
                                }else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_KEYWORDS)==0){
91
                                        parser.nextTag();
92
                                        while (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0){
93
                                                parser.next();
94
                                                String keyword = parser.getText();
95
                                                if ((keyword != null) || (!(keyword.equals("")))){
96
                                                        this.addKeyword(keyword);
97
                                                }
98
                                                //Keyword end tag
99
                                                parser.nextTag();
100
                                                //Keyword start tag?
101
                                                parser.nextTag();
102
                                        }
103

    
104

    
105
                                } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.KEYWORD)==0){
106
                                        this.addKeyword(parser.nextText());
107
                                } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.SRS)==0
108
                                    || parser.getName().compareToIgnoreCase(CapabilitiesTags.OTHERSRS)==0){
109
                                     String value = parser.nextText();
110
                     if (value != null){
111
                         String[] mySRSs = stringUtils.split(value, " ");
112
                         for (int i = 0; i < mySRSs.length; i++) {
113
                             this.addSRS(mySRSs[i]);
114
                         }
115

    
116
                     }
117
                                } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.DEAFAULTSRS)==0){
118
                                     String value = parser.nextText();
119
                     setDefaultSRS(value.trim());
120
                                } else        if (parser.getName().compareToIgnoreCase(CapabilitiesTags.LATLONGBOUNDINGBOX)==0){
121
                                        BoundaryBox bbox = new BoundaryBox();
122
                                        // En las pruebas realizadas, mapserver ofrece en este tag el boundingbox
123
                                        // tanto si est? en coordenadas geogr?ficas como en cartesianas
124
                                        // y no incluye (en ninguno de los dos casos) el atributo SRS
125
                                        // as? que, para crear el bbox, lo tomamos del tag SRS si lo hubiera.
126
                                        if(this.getDefaultSRS()!=null){
127
                                                bbox.setSrs(this.getDefaultSRS());
128
                                        } else {
129
                                                bbox.setSrs(CapabilitiesTags.EPSG_4326);
130
                                        }
131
                    String value = parser.getAttributeValue("",CapabilitiesTags.MINX);
132
                    if ((value != null) && (Utilities.isNumber(value)))
133
                        bbox.setXmin(Double.parseDouble(value));
134
                    value = parser.getAttributeValue("",CapabilitiesTags.MINY);
135
                    if ((value != null) && (Utilities.isNumber(value)))
136
                        bbox.setYmin(Double.parseDouble(value));
137
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
138
                    if ((value != null) && (Utilities.isNumber(value)))
139
                        bbox.setXmax(Double.parseDouble(value));
140
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
141
                    if ((value != null) && (Utilities.isNumber(value)))
142
                        bbox.setYmax(Double.parseDouble(value));
143
                    this.addBBox(bbox);
144
                    this.setLatLonBbox(bbox);
145
                                } else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0){
146
                                        BoundaryBox bbox = new BoundaryBox();
147
                    String value = parser.getAttributeValue("",CapabilitiesTags.SRS);
148
                    if (value != null)
149
                        bbox.setSrs(value);
150
                    value = parser.getAttributeValue("",CapabilitiesTags.MINX);
151
                    if ((value != null) && (Utilities.isNumber(value)))
152
                        bbox.setXmin(Double.parseDouble(value));
153
                    value = parser.getAttributeValue("",CapabilitiesTags.MINY);
154
                    if ((value != null) && (Utilities.isNumber(value)))
155
                        bbox.setYmin(Double.parseDouble(value));
156
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
157
                    if ((value != null) && (Utilities.isNumber(value)))
158
                        bbox.setXmax(Double.parseDouble(value));
159
                    value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
160
                    if ((value != null) && (Utilities.isNumber(value)))
161
                        bbox.setYmax(Double.parseDouble(value));
162
                    if (bbox.getSrs() != null){
163
                            this.addBBox(bbox);
164
                            this.addSRS(bbox.getSrs());
165
                    }
166
                } else if (CapabilitiesTags.WGS84BOUNDINGBOX.equals(parser.getName())){
167
                                        String lowerCorner = null;
168
                                        String upperCorner = null;
169
                                        parser.next();
170
                                        String tagName = parser.getName();
171
                                        while(!CapabilitiesTags.WGS84BOUNDINGBOX.equals(tagName)){
172
                                                if ((CapabilitiesTags.LOWERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){
173
                                                        parser.next();
174
                                                        lowerCorner = parser.getText();
175
                                                }else if ((CapabilitiesTags.UPPERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){
176
                                                        parser.next();
177
                                                        upperCorner = parser.getText();
178
                                                }
179
                                                currentTag = parser.next();
180
                                                tagName = parser.getName();
181
                                        }
182
                                        if ((lowerCorner != null) && (upperCorner != null)){
183
                                                BoundaryBox bbox = new BoundaryBox();
184
                                                bbox.setSrs("EPSG:4326");
185
                                                String[] lowerCoordinates = stringUtils.split(lowerCorner, "[! \t\r\n]");
186
                                                if (lowerCoordinates.length >= 2){
187
                                                        try{
188
                                                                bbox.setXmin(Double.valueOf(lowerCoordinates[0]).doubleValue());
189
                                                                bbox.setYmin(Double.valueOf(lowerCoordinates[1]).doubleValue());
190
                                                        }catch(NumberFormatException e){
191
                                                                //Is not a number
192
                                                        }
193
                                                }
194
                                                String[] upperCoordinates = stringUtils.split(upperCorner, "[! \t\r\n]");
195
                                                if (upperCoordinates.length >= 2){
196
                                                        try{
197
                                                                bbox.setXmax(Double.valueOf(upperCoordinates[0]).doubleValue());
198
                                                                bbox.setYmax(Double.valueOf(upperCoordinates[1]).doubleValue());
199
                                                        }catch(NumberFormatException e){
200
                                                                //Is not a number
201
                                                        }
202
                                                }
203
                                                bbox = BoundaryBox.clipGeodeticBBox(bbox);
204
                                                this.addBBox(bbox);
205
                                                this.setLatLonBbox(bbox);
206
                                        }
207
                }
208

    
209
                                break;
210
                        case KXmlParser.END_TAG:
211
                                if (parser.getName().compareTo(CapabilitiesTags.WFS_FEATURETYPE) == 0)
212
                                        end = true;
213
                                break;
214
                        case KXmlParser.TEXT:
215
                                break;
216
                        }
217
                        if (!end){
218
                                currentTag = parser.next();
219
                        }
220
                }
221
        }
222
}