Revision 9917 branches/v10/libraries/libRemoteServices/src/org/gvsig/remoteClient/gml/utils/GMLUtilsParser.java
GMLUtilsParser.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.geom.Point2D; |
4 | 4 |
import java.awt.geom.Rectangle2D; |
5 |
import java.awt.image.BufferStrategy; |
|
6 | 5 |
import java.io.IOException; |
7 | 6 |
|
8 |
import org.gvsig.remoteClient.gml.GMLException; |
|
9 | 7 |
import org.gvsig.remoteClient.gml.GMLTags; |
10 | 8 |
import org.gvsig.remoteClient.gml.GMLFeaturesParser.Extent; |
9 |
import org.gvsig.remoteClient.gml.exceptions.BaseException; |
|
10 |
import org.gvsig.remoteClient.gml.exceptions.GMLFileReadException; |
|
11 |
import org.gvsig.remoteClient.gml.exceptions.GMLNoGeometryException; |
|
12 |
import org.gvsig.remoteClient.gml.exceptions.GMLParserException; |
|
11 | 13 |
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory; |
12 |
import org.gvsig.remoteClient.gml.schemas.IXMLType; |
|
13 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
|
14 | 14 |
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser; |
15 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
|
16 | 15 |
import org.kxml2.io.KXmlParser; |
17 | 16 |
import org.xmlpull.v1.XmlPullParserException; |
18 | 17 |
|
... | ... | |
60 | 59 |
* |
61 | 60 |
* $Id$ |
62 | 61 |
* $Log$ |
63 |
* Revision 1.1 2006-08-10 12:00:49 jorpiell |
|
62 |
* Revision 1.1.2.1 2007-01-25 16:12:59 jorpiell |
|
63 |
* Se han sustituido las clases por las que hay en el nuevo driver de GML. |
|
64 |
* |
|
65 |
* Revision 1.3 2007/01/15 13:11:00 csanchez |
|
66 |
* Sistema de Warnings y Excepciones adaptado a BasicException |
|
67 |
* |
|
68 |
* Revision 1.2 2006/12/22 11:25:44 csanchez |
|
69 |
* Nuevo parser GML 2.x para gml's sin esquema |
|
70 |
* |
|
71 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell |
|
64 | 72 |
* Primer commit del driver de Gml |
65 | 73 |
* |
66 | 74 |
* |
67 | 75 |
*/ |
68 | 76 |
/** |
69 | 77 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
78 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es) |
|
70 | 79 |
*/ |
71 | 80 |
public class GMLUtilsParser { |
72 | 81 |
|
... | ... | |
91 | 100 |
for (int i=0 ; i<parser.getAttributeCount() ;i++){ |
92 | 101 |
if (parser.getAttributeName(i).compareTo(GMLTags.GML_SRS_NAME) == 0){ |
93 | 102 |
srs = parser.getAttributeValue(i); |
94 |
|
|
95 | 103 |
} |
96 | 104 |
} |
97 | 105 |
extent = parseBox(parser); |
... | ... | |
132 | 140 |
if (parser.getName().compareTo(GMLTags.GML_COORDINATES)==0){ |
133 | 141 |
extent = parseCoordinates(parser); |
134 | 142 |
}else if(parser.getName().compareTo(GMLTags.GML_COORD)==0){ |
135 |
if (ul != null){
|
|
143 |
if (ul == null){
|
|
136 | 144 |
ul = parsePoint(parser); |
137 | 145 |
}else{ |
138 | 146 |
br = parsePoint(parser); |
... | ... | |
164 | 172 |
* |
165 | 173 |
*/ |
166 | 174 |
private static Rectangle2D parseCoordinates(XMLSchemaParser parser) throws XmlPullParserException, IOException { |
167 |
int currentTag; |
|
168 |
boolean end = false; |
|
169 | 175 |
parser.next(); |
170 | 176 |
|
171 | 177 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
... | ... | |
207 | 213 |
case XMLSchemaParser.START_TAG: |
208 | 214 |
if (parser.getName().compareTo(GMLTags.GML_COORDINATES)==0){ |
209 | 215 |
parseCoordinates(parser); |
210 |
} |
|
211 |
break; |
|
212 |
case XMLSchemaParser.END_TAG: |
|
216 |
} |
|
213 | 217 |
if (parser.getName().compareTo(GMLTags.GML_X) == 0){ |
218 |
parser.next(); |
|
214 | 219 |
x = parser.getText(); |
215 | 220 |
}else if (parser.getName().compareTo(GMLTags.GML_Y) == 0){ |
221 |
parser.next(); |
|
216 | 222 |
y = parser.getText(); |
217 | 223 |
end = true; |
218 |
}
|
|
224 |
} |
|
219 | 225 |
break; |
226 |
case XMLSchemaParser.END_TAG: |
|
227 |
break; |
|
220 | 228 |
case XMLSchemaParser.TEXT: |
221 | 229 |
break; |
222 | 230 |
} |
... | ... | |
233 | 241 |
* @throws XmlPullParserException |
234 | 242 |
* |
235 | 243 |
*/ |
236 |
public static Object parseGeometry(XMLSchemaParser parser,String gmGeometryTag,IGeometriesFactory factory) throws GMLException {
|
|
244 |
public static Object parseGeometry(XMLSchemaParser parser,String gmGeometryTag,IGeometriesFactory factory) throws BaseException{
|
|
237 | 245 |
int currentTag; |
238 | 246 |
boolean end = false; |
239 | 247 |
|
240 | 248 |
try{ |
241 |
currentTag = parser.next();
|
|
249 |
currentTag = parser.getEventType();
|
|
242 | 250 |
while (!end){ |
243 | 251 |
switch(currentTag){ |
244 | 252 |
case KXmlParser.START_TAG: |
... | ... | |
250 | 258 |
return factory.createGeometry(getGeometryInGML(parser,parser.getName())); |
251 | 259 |
} |
252 | 260 |
}catch (Exception e){ |
253 |
throw new GMLException(GMLException.EXC_NO_GEOMETRY); |
|
261 |
//Throw a Geometry Exception if cant create the geometry |
|
262 |
throw new GMLNoGeometryException(0, e); |
|
254 | 263 |
} |
255 | 264 |
case KXmlParser.END_TAG: |
256 | 265 |
if ((parser.getName().compareTo(gmGeometryTag) == 0)) |
... | ... | |
264 | 273 |
} |
265 | 274 |
} |
266 | 275 |
}catch (XmlPullParserException e) { |
267 |
// TODO Auto-generated catch block |
|
268 |
e.printStackTrace(); |
|
269 |
throw new GMLException(GMLException.EXC_PARSE); |
|
276 |
// Captured KXML parsing Exception |
|
277 |
throw new GMLParserException(e); |
|
270 | 278 |
} catch (IOException e) { |
271 | 279 |
// TODO Auto-generated catch block |
272 |
e.printStackTrace(); |
|
273 |
throw new GMLException(GMLException.EXC_READ_FILE); |
|
280 |
throw new GMLFileReadException(e); |
|
274 | 281 |
} |
275 | 282 |
return null; |
276 | 283 |
} |
... | ... | |
281 | 288 |
* @throws XmlPullParserException |
282 | 289 |
* |
283 | 290 |
*/ |
284 |
private static Point2D parsePoint2D(XMLSchemaParser parser) throws GMLException{
|
|
291 |
private static Point2D parsePoint2D(XMLSchemaParser parser) throws BaseException{
|
|
285 | 292 |
int currentTag; |
286 | 293 |
boolean end = false; |
287 | 294 |
|
... | ... | |
310 | 317 |
} |
311 | 318 |
} |
312 | 319 |
}catch (XmlPullParserException e) { |
313 |
// TODO Auto-generated catch block |
|
314 |
e.printStackTrace(); |
|
315 |
throw new GMLException(GMLException.EXC_PARSE); |
|
320 |
//Captured KXML parsing Exception |
|
321 |
throw new GMLParserException(e); |
|
316 | 322 |
} catch (IOException e) { |
317 | 323 |
// TODO Auto-generated catch block |
318 |
e.printStackTrace(); |
|
319 |
throw new GMLException(GMLException.EXC_READ_FILE); |
|
324 |
throw new GMLFileReadException(e); |
|
320 | 325 |
} |
321 | 326 |
return null; |
322 | 327 |
} |
... | ... | |
329 | 334 |
* @throws XmlPullParserException |
330 | 335 |
* |
331 | 336 |
*/ |
332 |
private static String getGeometryInGML(XMLSchemaParser parser,String endGeometryTag) throws GMLException{
|
|
337 |
private static String getGeometryInGML(XMLSchemaParser parser,String endGeometryTag) throws BaseException{
|
|
333 | 338 |
int currentTag; |
334 | 339 |
boolean end = false; |
335 | 340 |
StringBuffer gmlString = new StringBuffer(); |
... | ... | |
339 | 344 |
while (!end){ |
340 | 345 |
switch(currentTag){ |
341 | 346 |
case KXmlParser.START_TAG: |
347 |
if (parser.getName().compareTo("geometryMember")==0){ |
|
348 |
//Esta etiqueta de gml que nos indica donde empieza y donde acaba un subelemento |
|
349 |
//de una geometria compleja, como un multipoligono no la admite el parser de Geotools |
|
350 |
//Por tanto la debemos de ignorar |
|
351 |
break; |
|
352 |
} |
|
342 | 353 |
gmlString.append("<" + parser.getName()); |
343 | 354 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
344 | 355 |
gmlString.append(" " + parser.getAttributeName(i) + |
... | ... | |
347 | 358 |
gmlString.append(">"); |
348 | 359 |
break; |
349 | 360 |
case KXmlParser.END_TAG: |
361 |
if (parser.getName().compareTo("geometryMember")==0){ |
|
362 |
//Esta etiqueta de gml que nos indica donde empieza y donde acaba un subelemento |
|
363 |
//de una geometria compleja, como un multipoligono no la admite el parser de Geotools |
|
364 |
//Por tanto la debemos de ignorar |
|
365 |
break; |
|
366 |
} |
|
350 | 367 |
if ((parser.getName().compareTo(endGeometryTag) == 0)){ |
351 | 368 |
end = true; |
352 | 369 |
} |
... | ... | |
361 | 378 |
} |
362 | 379 |
} |
363 | 380 |
}catch (XmlPullParserException e) { |
364 |
e.printStackTrace();
|
|
365 |
throw new GMLException(GMLException.EXC_PARSE);
|
|
381 |
//Captured KXML parsing Exception
|
|
382 |
throw new GMLParserException(e);
|
|
366 | 383 |
} catch (IOException e) { |
367 |
e.printStackTrace(); |
|
368 |
throw new GMLException(GMLException.EXC_READ_FILE); |
|
384 |
throw new GMLFileReadException(e); |
|
369 | 385 |
} |
370 | 386 |
return gmlString.toString(); |
371 | 387 |
} |
Also available in: Unified diff