root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / remoteclient / wfs / wfs_1_0_0 / WFSFeature1_0_0.java @ 112
History | View | Annotate | Download (8.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 |
package org.gvsig.remoteclient.wfs.wfs_1_0_0; |
25 |
|
26 |
import java.io.IOException; |
27 |
|
28 |
import org.kxml2.io.KXmlParser; |
29 |
import org.xmlpull.v1.XmlPullParserException; |
30 |
import org.gvsig.compat.CompatLocator; |
31 |
import org.gvsig.compat.lang.StringUtils; |
32 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
33 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
34 |
import org.gvsig.remoteclient.utils.Utilities; |
35 |
import org.gvsig.remoteclient.wfs.WFSFeature; |
36 |
import org.gvsig.remoteclient.wfs.WFSServiceInformation; |
37 |
import org.gvsig.remoteclient.wfs.schema.GMLTags; |
38 |
import org.gvsig.remoteclient.wfs.schema.XMLNameSpace; |
39 |
|
40 |
/**
|
41 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
42 |
*/
|
43 |
public class WFSFeature1_0_0 extends WFSFeature{ |
44 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
45 |
|
46 |
WFSFeature1_0_0(WFSServiceInformation serviceInformation) { |
47 |
super(serviceInformation);
|
48 |
} |
49 |
|
50 |
WFSFeature1_0_0(WFSServiceInformation serviceInformation, String name) {
|
51 |
super(serviceInformation, name);
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* <p>Parses the contents of the parser(WMSCapabilities)
|
56 |
* to extract the information about an WMSLayer</p>
|
57 |
* @throws IOException
|
58 |
* @throws XmlPullParserException
|
59 |
*
|
60 |
*/
|
61 |
public void parse(KXmlParser parser) throws XmlPullParserException, IOException{ |
62 |
int currentTag;
|
63 |
boolean end = false; |
64 |
|
65 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_FEATURETYPE);
|
66 |
|
67 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
68 |
String[] attName = stringUtils.split(parser.getAttributeName(i), ":"); |
69 |
if (attName.length == 2){ |
70 |
if (attName[0].compareTo(GMLTags.XML_NAMESPACE)==0){ |
71 |
XMLNameSpace nameSpace = new XMLNameSpace(attName[1],parser.getAttributeValue(i)); |
72 |
this.setNamespace(nameSpace);
|
73 |
} |
74 |
} |
75 |
} |
76 |
|
77 |
currentTag = parser.next(); |
78 |
while (!end)
|
79 |
{ |
80 |
switch(currentTag)
|
81 |
{ |
82 |
case KXmlParser.START_TAG:
|
83 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.NAME)==0) |
84 |
{ |
85 |
this.setName(parser.nextText());
|
86 |
} |
87 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.TITLE)==0) |
88 |
{ |
89 |
this.setTitle(parser.nextText());
|
90 |
} |
91 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_KEYWORDS)==0) |
92 |
{ |
93 |
String keyword = parser.nextText();
|
94 |
if ((keyword != null) || (!(keyword.equals("")))){ |
95 |
this.addKeyword(keyword);
|
96 |
} |
97 |
} |
98 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.KEYWORD)==0) |
99 |
{ |
100 |
this.addKeyword(parser.nextText());
|
101 |
} |
102 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.SRS)==0) |
103 |
{ |
104 |
String value = parser.nextText();
|
105 |
if (value != null){ |
106 |
String[] mySRSs = stringUtils.split(value, " "); |
107 |
for (int i = 0; i < mySRSs.length; i++) { |
108 |
this.addSRS(mySRSs[i]);
|
109 |
} |
110 |
|
111 |
} |
112 |
} |
113 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.LATLONGBOUNDINGBOX)==0) |
114 |
{ |
115 |
BoundaryBox bbox = new BoundaryBox();
|
116 |
// En las pruebas realizadas, mapserver ofrece en este tag el boundingbox
|
117 |
// tanto si est? en coordenadas geogr?ficas como en cartesianas
|
118 |
// y no incluye (en ninguno de los dos casos) el atributo SRS
|
119 |
// as? que, para crear el bbox, lo tomamos del tag SRS si lo hubiera.
|
120 |
if(this.getDefaultSRS()!=null){ |
121 |
bbox.setSrs(this.getDefaultSRS());
|
122 |
} else {
|
123 |
bbox.setSrs(CapabilitiesTags.EPSG_4326); |
124 |
} |
125 |
String value = parser.getAttributeValue("",CapabilitiesTags.MINX); |
126 |
if ((value != null) && (Utilities.isNumber(value))) |
127 |
bbox.setXmin(Double.parseDouble(value));
|
128 |
value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
129 |
if ((value != null) && (Utilities.isNumber(value))) |
130 |
bbox.setYmin(Double.parseDouble(value));
|
131 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
132 |
if ((value != null) && (Utilities.isNumber(value))) |
133 |
bbox.setXmax(Double.parseDouble(value));
|
134 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
135 |
if ((value != null) && (Utilities.isNumber(value))) |
136 |
bbox.setYmax(Double.parseDouble(value));
|
137 |
this.addBBox(bbox);
|
138 |
this.setLatLonBbox(bbox);
|
139 |
} |
140 |
if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0) |
141 |
{ |
142 |
BoundaryBox bbox = new BoundaryBox();
|
143 |
String value = parser.getAttributeValue("",CapabilitiesTags.SRS); |
144 |
if (value != null) |
145 |
bbox.setSrs(value); |
146 |
value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
147 |
if ((value != null) && (Utilities.isNumber(value))) |
148 |
bbox.setXmin(Double.parseDouble(value));
|
149 |
value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
150 |
if ((value != null) && (Utilities.isNumber(value))) |
151 |
bbox.setYmin(Double.parseDouble(value));
|
152 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
153 |
if ((value != null) && (Utilities.isNumber(value))) |
154 |
bbox.setXmax(Double.parseDouble(value));
|
155 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
156 |
if ((value != null) && (Utilities.isNumber(value))) |
157 |
bbox.setYmax(Double.parseDouble(value));
|
158 |
if (bbox.getSrs() != null){ |
159 |
this.addBBox(bbox);
|
160 |
this.addSRS(bbox.getSrs());
|
161 |
} |
162 |
} |
163 |
if (CapabilitiesTags.WGS84BOUNDINGBOX.equals(parser.getName())){
|
164 |
String lowerCorner = null; |
165 |
String upperCorner = null; |
166 |
parser.next(); |
167 |
String tagName = parser.getName();
|
168 |
while(!CapabilitiesTags.WGS84BOUNDINGBOX.equals(tagName)){
|
169 |
if ((CapabilitiesTags.LOWERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){
|
170 |
parser.next(); |
171 |
lowerCorner = parser.getText(); |
172 |
}else if ((CapabilitiesTags.UPPERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){ |
173 |
parser.next(); |
174 |
upperCorner = parser.getText(); |
175 |
} |
176 |
currentTag = parser.next(); |
177 |
tagName = parser.getName(); |
178 |
} |
179 |
if ((lowerCorner != null) && (upperCorner != null)){ |
180 |
BoundaryBox bbox = new BoundaryBox();
|
181 |
bbox.setSrs("EPSG:4326");
|
182 |
String[] lowerCoordinates = stringUtils.split(lowerCorner, "[! \t\r\n]"); |
183 |
if (lowerCoordinates.length >= 2){ |
184 |
try{
|
185 |
bbox.setXmin(Double.valueOf(lowerCoordinates[0]).doubleValue()); |
186 |
bbox.setYmin(Double.valueOf(lowerCoordinates[1]).doubleValue()); |
187 |
}catch(NumberFormatException e){ |
188 |
//Is not a number
|
189 |
} |
190 |
} |
191 |
String[] upperCoordinates = stringUtils.split(upperCorner, "[! \t\r\n]"); |
192 |
if (upperCoordinates.length >= 2){ |
193 |
try{
|
194 |
bbox.setXmax(Double.valueOf(upperCoordinates[0]).doubleValue()); |
195 |
bbox.setYmax(Double.valueOf(upperCoordinates[1]).doubleValue()); |
196 |
}catch(NumberFormatException e){ |
197 |
//Is not a number
|
198 |
} |
199 |
} |
200 |
bbox = BoundaryBox.clipGeodeticBBox(bbox); |
201 |
this.addBBox(bbox);
|
202 |
this.setLatLonBbox(bbox);
|
203 |
} |
204 |
} |
205 |
|
206 |
break;
|
207 |
case KXmlParser.END_TAG:
|
208 |
if (parser.getName().compareTo(CapabilitiesTags.WFS_FEATURETYPE) == 0) |
209 |
end = true;
|
210 |
break;
|
211 |
case KXmlParser.TEXT:
|
212 |
break;
|
213 |
} |
214 |
if (!end){
|
215 |
currentTag = parser.next(); |
216 |
} |
217 |
} |
218 |
} |
219 |
} |