svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / GPEContentHandlerTest.java @ 19579
History | View | Annotate | Download (15.4 KB)
1 |
package org.gvsig.gpe; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.gvsig.gpe.containers.Bbox; |
6 |
import org.gvsig.gpe.containers.Curve; |
7 |
import org.gvsig.gpe.containers.Element; |
8 |
import org.gvsig.gpe.containers.Feature; |
9 |
import org.gvsig.gpe.containers.Geometry; |
10 |
import org.gvsig.gpe.containers.Layer; |
11 |
import org.gvsig.gpe.containers.LineString; |
12 |
import org.gvsig.gpe.containers.LinearRing; |
13 |
import org.gvsig.gpe.containers.MultiCurve; |
14 |
import org.gvsig.gpe.containers.MultiGeometry; |
15 |
import org.gvsig.gpe.containers.MultiLineString; |
16 |
import org.gvsig.gpe.containers.MultiPoint; |
17 |
import org.gvsig.gpe.containers.MultiPolygon; |
18 |
import org.gvsig.gpe.containers.Point; |
19 |
import org.gvsig.gpe.containers.Polygon; |
20 |
import org.gvsig.gpe.parser.GPEContentHandler; |
21 |
|
22 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
23 |
*
|
24 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
25 |
*
|
26 |
* This program is free software; you can redistribute it and/or
|
27 |
* modify it under the terms of the GNU General Public License
|
28 |
* as published by the Free Software Foundation; either version 2
|
29 |
* of the License, or (at your option) any later version.
|
30 |
*
|
31 |
* This program is distributed in the hope that it will be useful,
|
32 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
33 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
34 |
* GNU General Public License for more details.
|
35 |
*
|
36 |
* You should have received a copy of the GNU General Public License
|
37 |
* along with this program; if not, write to the Free Software
|
38 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
39 |
*
|
40 |
* For more information, contact:
|
41 |
*
|
42 |
* Generalitat Valenciana
|
43 |
* Conselleria d'Infraestructures i Transport
|
44 |
* Av. Blasco Ib??ez, 50
|
45 |
* 46010 VALENCIA
|
46 |
* SPAIN
|
47 |
*
|
48 |
* +34 963862235
|
49 |
* gvsig@gva.es
|
50 |
* www.gvsig.gva.es
|
51 |
*
|
52 |
* or
|
53 |
*
|
54 |
* IVER T.I. S.A
|
55 |
* Salamanca 50
|
56 |
* 46005 Valencia
|
57 |
* Spain
|
58 |
*
|
59 |
* +34 963163400
|
60 |
* dac@iver.es
|
61 |
*/
|
62 |
/* CVS MESSAGES:
|
63 |
*
|
64 |
* $Id: GPEContentHandlerTest.java 202 2007-11-27 12:00:11Z jpiera $
|
65 |
* $Log$
|
66 |
* Revision 1.14 2007/06/07 14:52:28 jorpiell
|
67 |
* Add the schema support
|
68 |
*
|
69 |
* Revision 1.13 2007/05/15 12:09:41 jorpiell
|
70 |
* The bbox is linked to the feature
|
71 |
*
|
72 |
* Revision 1.12 2007/05/15 11:54:35 jorpiell
|
73 |
* A wrong label fixed
|
74 |
*
|
75 |
* Revision 1.11 2007/05/15 07:28:34 jorpiell
|
76 |
* Children Element printed
|
77 |
*
|
78 |
* Revision 1.10 2007/05/14 09:29:34 jorpiell
|
79 |
* Add some comments when an element is added
|
80 |
*
|
81 |
* Revision 1.9 2007/05/09 10:25:45 jorpiell
|
82 |
* Add the multiGeometries
|
83 |
*
|
84 |
* Revision 1.8 2007/05/09 08:35:58 jorpiell
|
85 |
* fixed an exception
|
86 |
*
|
87 |
* Revision 1.7 2007/05/02 11:46:07 jorpiell
|
88 |
* Writing tests updated
|
89 |
*
|
90 |
* Revision 1.6 2007/04/26 14:39:12 jorpiell
|
91 |
* Add some tests
|
92 |
*
|
93 |
* Revision 1.5 2007/04/19 07:23:20 jorpiell
|
94 |
* Add the add methods to teh contenhandler and change the register mode
|
95 |
*
|
96 |
* Revision 1.4 2007/04/17 07:53:55 jorpiell
|
97 |
* Before to start a new parsing process, the initialize method of the content handlers is throwed
|
98 |
*
|
99 |
* Revision 1.3 2007/04/14 16:06:35 jorpiell
|
100 |
* Add the container classes
|
101 |
*
|
102 |
* Revision 1.2 2007/04/13 13:14:55 jorpiell
|
103 |
* Created the base tests and add some methods to the content handler
|
104 |
*
|
105 |
* Revision 1.1 2007/04/12 17:06:42 jorpiell
|
106 |
* First GML writing tests
|
107 |
*
|
108 |
*
|
109 |
*/
|
110 |
/**
|
111 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
112 |
*/
|
113 |
public class GPEContentHandlerTest extends GPEContentHandler{ |
114 |
private String tab = ""; |
115 |
private ArrayList layers = new ArrayList(); |
116 |
|
117 |
/**
|
118 |
* @return the layers without parent layer
|
119 |
*/
|
120 |
public ArrayList getLayers() { |
121 |
ArrayList newLayers = new ArrayList(); |
122 |
for (int i=0 ; i<layers.size() ; i++){ |
123 |
if (((Layer)layers.get(i)).getParentLayer() == null){ |
124 |
newLayers.add(layers.get(i)); |
125 |
} |
126 |
} |
127 |
return newLayers;
|
128 |
} |
129 |
|
130 |
public void addNameToFeature(Object feature, String name){ |
131 |
System.out.print(tab + "Feature name changed: " + name + "\n"); |
132 |
((Feature)feature).setName(name); |
133 |
} |
134 |
|
135 |
public void endFeature(Object feature) { |
136 |
System.out.print(tab + "End Feature\n"); |
137 |
} |
138 |
|
139 |
public void initialize(){ |
140 |
layers = new ArrayList(); |
141 |
} |
142 |
|
143 |
public void addBboxToFeature(Object bbox, Object feature) { |
144 |
((Feature)feature).setBbox(bbox); |
145 |
|
146 |
} |
147 |
|
148 |
public void addBboxToLayer(Object bbox, Object layer) { |
149 |
Bbox box = (Bbox)bbox; |
150 |
System.out.print(tab + "Layer bbox Added:\n"); |
151 |
tab = tab + "\t";
|
152 |
System.out.print(tab + "MINX: " + box.getX()[0] + "\n"); |
153 |
System.out.print(tab + "MINY: " + box.getY()[0] + "\n"); |
154 |
System.out.print(tab + "MINZ: " + box.getZ()[0] + "\n"); |
155 |
System.out.print(tab + "MAXX: " + box.getX()[1] + "\n"); |
156 |
System.out.print(tab + "MAXY: " + box.getY()[1] + "\n"); |
157 |
System.out.print(tab + "MAXZ: " + box.getZ()[1] + "\n"); |
158 |
System.out.print(tab + "SRS: " + box.getSrs() + "\n"); |
159 |
tab = tab.substring(0, tab.length()-1); |
160 |
((Layer)layer).setBbox(bbox); |
161 |
} |
162 |
|
163 |
public void addDescriptionToLayer(String description, Object layer) { |
164 |
System.out.print(tab + "Layer description changed: " + description + "\n"); |
165 |
((Layer)layer).setDescription(description); |
166 |
} |
167 |
|
168 |
public void addElementToFeature(Object element, Object feature) { |
169 |
Element elem = (Element)element; |
170 |
tab = tab + "\t";
|
171 |
System.out.print(tab + "Add Element " + elem.getName() + "=" + |
172 |
elem.getValue() + " to Feature\n");
|
173 |
printChildElements(elem); |
174 |
tab = tab.substring(0, tab.length()-1); |
175 |
((Feature)feature).addElement(element); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* Print the element children
|
180 |
* @param element to print
|
181 |
*/
|
182 |
private void printChildElements(Element element){ |
183 |
tab = tab + "\t";
|
184 |
for (int i=0 ; i< element.getElements().size() ; i++){ |
185 |
Element child = element.getElementAt(i);
|
186 |
System.out.print(tab + "- Element " + child.getName() + "=" + |
187 |
child.getValue() + "\n");
|
188 |
printChildElements(child); |
189 |
} |
190 |
tab = tab.substring(0, tab.length()-1); |
191 |
} |
192 |
|
193 |
public void addFeatureToLayer(Object feature, Object layer) { |
194 |
((Layer)layer).addFeature(feature); |
195 |
|
196 |
} |
197 |
|
198 |
public void addGeometryToFeature(Object geometry, Object feature) { |
199 |
((Feature)feature).setGeometry(geometry); |
200 |
|
201 |
} |
202 |
|
203 |
public void addInnerPolygonToPolygon(Object innerPolygon, Object polygon) { |
204 |
((Polygon)polygon).addInnerBoundary(innerPolygon);
|
205 |
|
206 |
} |
207 |
|
208 |
public void addNameToFeature(String name, Object feature) { |
209 |
((Feature)feature).setName(name); |
210 |
|
211 |
} |
212 |
|
213 |
public void addNameToLayer(String name, Object layer) { |
214 |
System.out.print(tab + "Layer name changed: " + name + "\n"); |
215 |
((Layer)layer).setName(name); |
216 |
} |
217 |
|
218 |
public void addParentElementToElement(Object parent, Object element) { |
219 |
((Element)element).setParentElement(parent);
|
220 |
|
221 |
} |
222 |
|
223 |
public void addParentLayerToLayer(Object parent, Object layer) { |
224 |
((Layer)layer).setParentLayer(parent); |
225 |
|
226 |
} |
227 |
|
228 |
public void addSrsToLayer(String srs, Object layer) { |
229 |
((Layer)layer).setSrs(srs); |
230 |
|
231 |
} |
232 |
|
233 |
|
234 |
public Object startBbox(String id, double[] x, double[] y, double[] z, String srs) { |
235 |
Bbox bbox = new Bbox();
|
236 |
bbox.setX(x); |
237 |
bbox.setY(y); |
238 |
bbox.setZ(z); |
239 |
bbox.setId(id); |
240 |
bbox.setSrs(srs); |
241 |
return bbox;
|
242 |
} |
243 |
|
244 |
public void endBbox(Object bbox) { |
245 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
246 |
} |
247 |
|
248 |
public Object startElement(String name, Object value, String xsElementName, Object parentElement) { |
249 |
Element element = new Element(); |
250 |
element.setParentElement(parentElement); |
251 |
element.setName(name); |
252 |
element.setValue(value); |
253 |
element.setType(xsElementName); |
254 |
return element;
|
255 |
} |
256 |
|
257 |
public void endElement(Object element) { |
258 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
259 |
|
260 |
} |
261 |
|
262 |
public Object startFeature(String id, String name, String xsElementName, Object layer) { |
263 |
System.out.print(tab + "Start Feature, ID: " + id + " NAME: " + name + "\n"); |
264 |
Feature feature = new Feature();
|
265 |
feature.setName(name); |
266 |
feature.setId(id); |
267 |
if (layer != null){ |
268 |
addFeatureToLayer(feature, layer); |
269 |
} |
270 |
return feature;
|
271 |
} |
272 |
|
273 |
public Object startInnerPolygon(String id, double[] x, double[] y, double[] z, String srs) { |
274 |
tab = tab + "\t";
|
275 |
System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n"); |
276 |
tab = tab + "\t";
|
277 |
for (int i=0 ; i<x.length ; i++){ |
278 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
279 |
} |
280 |
tab = tab.substring(0, tab.length()-2); |
281 |
Polygon inner = new Polygon(); |
282 |
inner.setX(x); |
283 |
inner.setY(y); |
284 |
inner.setZ(z); |
285 |
inner.setId(id); |
286 |
inner.setSrs(srs); |
287 |
return inner;
|
288 |
} |
289 |
|
290 |
/*
|
291 |
* (non-Javadoc)
|
292 |
* @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object)
|
293 |
*/
|
294 |
public void endInnerPolygon(Object polygon){ |
295 |
tab = tab + "\t";
|
296 |
System.out.print(tab + "End InnerPolygon\n"); |
297 |
tab = tab.substring(0, tab.length()-1); |
298 |
} |
299 |
|
300 |
|
301 |
public Object startLayer(String id, String name, String description, String srs, Object parentLayer, Object bBox, String xsElementName) { |
302 |
System.out.print(tab + "Start Layer, ID: " + id + " NAME: " + name + "\n"); |
303 |
tab = tab + "\t";
|
304 |
Layer layer = new Layer();
|
305 |
layer.setId(id); |
306 |
layer.setName(name); |
307 |
layer.setDescription(description); |
308 |
layer.setSrs(srs); |
309 |
layer.setBbox(bBox); |
310 |
layer.setParentLayer(parentLayer); |
311 |
if (parentLayer != null){ |
312 |
((Layer)parentLayer).addLayer(layer); |
313 |
} |
314 |
layers.add(layer); |
315 |
return layer;
|
316 |
} |
317 |
|
318 |
public void endLayer(Object layer) { |
319 |
tab = tab.substring(0, tab.length()-1); |
320 |
System.out.print(tab + "End Layer\n"); |
321 |
} |
322 |
|
323 |
public Object startLineString(String id, double[] x, double[] y, double[] z, String srs) { |
324 |
tab = tab + "\t";
|
325 |
System.out.print(tab + "Start LineString, SRS:" + srs + "\n"); |
326 |
tab = tab + "\t";
|
327 |
for (int i=0 ; i<x.length ; i++){ |
328 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
329 |
} |
330 |
tab = tab.substring(0, tab.length()-2); |
331 |
LineString lineString = new LineString();
|
332 |
lineString.setX(x); |
333 |
lineString.setY(y); |
334 |
lineString.setZ(z); |
335 |
lineString.setId(id); |
336 |
lineString.setSrs(srs); |
337 |
return lineString;
|
338 |
} |
339 |
|
340 |
public void endLineString(Object line) { |
341 |
System.out.print(tab + "\t"+ "End LineString:\n"); |
342 |
} |
343 |
|
344 |
public Object startPoint(String id, double x, double y, double z, String srs) { |
345 |
tab = tab + "\t";
|
346 |
System.out.print(tab + "Start Point, SRS:" + srs + "\n"); |
347 |
tab = tab + "\t";
|
348 |
System.out.print(tab + x + "," + y + "," + z + "\n"); |
349 |
tab = tab.substring(0, tab.length()-2); |
350 |
Point point = new Point(); |
351 |
point.setX(x); |
352 |
point.setY(y); |
353 |
point.setZ(z); |
354 |
point.setId(id); |
355 |
point.setSrs(srs); |
356 |
return point;
|
357 |
} |
358 |
|
359 |
public void endPoint(Object point) { |
360 |
System.out.print(tab + "\t" + "End Point\n"); |
361 |
} |
362 |
|
363 |
public Object startPolygon(String id, double[] x, double[] y, double[] z, String srs) { |
364 |
tab = tab + "\t";
|
365 |
System.out.print(tab + "Start Polygon, SRS:" + srs + "\n"); |
366 |
tab = tab + "\t";
|
367 |
for (int i=0 ; i<x.length ; i++){ |
368 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
369 |
} |
370 |
tab = tab.substring(0, tab.length()-2); |
371 |
Polygon polygon = new Polygon(); |
372 |
polygon.setX(x); |
373 |
polygon.setY(y); |
374 |
polygon.setZ(z); |
375 |
polygon.setId(id); |
376 |
polygon.setSrs(srs); |
377 |
return polygon;
|
378 |
} |
379 |
|
380 |
|
381 |
public void endPolygon(Object polygon) { |
382 |
System.out.print(tab + "\t"+ "End Polygon\n"); |
383 |
} |
384 |
|
385 |
|
386 |
public Object startLinearRing(String id, double[] x, double[] y, double[] z, String srs) { |
387 |
System.out.print(tab + "Start LinearRing, SRS:" + srs + "\n"); |
388 |
tab = tab + "\t";
|
389 |
for (int i=0 ; i<x.length ; i++){ |
390 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
391 |
} |
392 |
tab = tab.substring(0, tab.length()-1); |
393 |
LinearRing linearRing = new LinearRing();
|
394 |
linearRing.setX(x); |
395 |
linearRing.setY(y); |
396 |
linearRing.setZ(z); |
397 |
linearRing.setId(id); |
398 |
linearRing.setSrs(srs); |
399 |
return linearRing;
|
400 |
} |
401 |
|
402 |
|
403 |
public void endLinearRing(Object linearRing) { |
404 |
System.out.print(tab + "End LinearRing\n"); |
405 |
} |
406 |
|
407 |
|
408 |
public Object startMultiPoint(String id, String srs) { |
409 |
System.out.print(tab + "Start MultiPoint, ID: " + id + ", SRS:" + srs + "\n"); |
410 |
tab = tab + "\t";
|
411 |
MultiPoint multiPoint = new MultiPoint();
|
412 |
multiPoint.setId(id); |
413 |
multiPoint.setSrs(srs); |
414 |
return multiPoint;
|
415 |
} |
416 |
|
417 |
public void endMultiPoint(Object multiPoint) { |
418 |
tab = tab.substring(0, tab.length()-1); |
419 |
System.out.print(tab + "End MultiPoint\n"); |
420 |
} |
421 |
|
422 |
public void addPointToMultiPoint(Object point, Object multiPoint) { |
423 |
System.out.print(tab + "Add Point to MultiPoint"); |
424 |
((MultiPoint)multiPoint).addPoint((Point)point);
|
425 |
} |
426 |
|
427 |
public Object startMultiLineString(String id, String srs) { |
428 |
System.out.print(tab + "Start MultiLineString, ID: " + id + ", SRS:" + srs + "\n"); |
429 |
tab = tab + "\t";
|
430 |
MultiLineString multiLineString = new MultiLineString();
|
431 |
multiLineString.setId(id); |
432 |
multiLineString.setSrs(srs); |
433 |
return multiLineString;
|
434 |
} |
435 |
|
436 |
public void endMultiLineString(Object multiLineString) { |
437 |
tab = tab.substring(0, tab.length()-1); |
438 |
System.out.print(tab + "End MultiLineString\n"); |
439 |
} |
440 |
|
441 |
public void addLineStringToMultiLineString(Object lineString, Object multiLineString) { |
442 |
System.out.print(tab + "Add LineString to MultiLineString"); |
443 |
((MultiLineString)multiLineString).addLineString((LineString)lineString); |
444 |
} |
445 |
|
446 |
public Object startMultiPolygon(String id, String srs) { |
447 |
System.out.print(tab + "Start MultiPolygon, ID: " + id + ", SRS:" + srs + "\n"); |
448 |
tab = tab + "\t";
|
449 |
MultiPolygon multiPolygon = new MultiPolygon();
|
450 |
multiPolygon.setId(id); |
451 |
multiPolygon.setSrs(srs); |
452 |
return multiPolygon;
|
453 |
} |
454 |
|
455 |
public void endMultiPolygon(Object multiPolygon) { |
456 |
tab = tab.substring(0, tab.length()-1); |
457 |
System.out.print(tab + "End MultiPolygon\n"); |
458 |
} |
459 |
|
460 |
public void addPolygonToMultiPolygon(Object polygon, Object multiPolygon) { |
461 |
System.out.print(tab + "Add Polygon to MultiPolygon"); |
462 |
((MultiPolygon)multiPolygon).addPolygon((Polygon)polygon);
|
463 |
} |
464 |
|
465 |
public Object startMultiGeometry(String id, String srs) { |
466 |
System.out.print(tab + "Start MultiGeometry, ID: " + id + ", SRS:" + srs + "\n"); |
467 |
tab = tab + "\t";
|
468 |
MultiGeometry multiGeometry = new MultiGeometry();
|
469 |
multiGeometry.setId(id); |
470 |
multiGeometry.setSrs(srs); |
471 |
return multiGeometry;
|
472 |
} |
473 |
|
474 |
public void endMultiGeometry(Object multiGeometry) { |
475 |
tab = tab.substring(0, tab.length()-1); |
476 |
System.out.print(tab + "End MultiGeometry\n"); |
477 |
} |
478 |
|
479 |
public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) { |
480 |
if (geometry instanceof Point){ |
481 |
System.out.print(tab + "Add Point to MultiGeometry"); |
482 |
}else if (geometry instanceof LineString){ |
483 |
System.out.print(tab + "Add LineString to MultiGeometry"); |
484 |
}else if (geometry instanceof Polygon){ |
485 |
System.out.print(tab + "Add Polygon to MultiGeometry"); |
486 |
}else if (geometry instanceof Curve){ |
487 |
System.out.print(tab + "Add LineString to Curve"); |
488 |
}else {
|
489 |
System.out.print(tab + "Add Geometry to MultiGeometry"); |
490 |
} |
491 |
((MultiGeometry)multiGeometry).addGeometry((Geometry)geometry); |
492 |
} |
493 |
|
494 |
|
495 |
public Object startCurve(String id, double[] x, double[] y, double[] z, String srs){ |
496 |
tab = tab + "\t";
|
497 |
System.out.print(tab + "Start Curve, ID: " + id + ", SRS:" + srs + "\n"); |
498 |
for (int i=0 ; i<x.length ; i++){ |
499 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
500 |
} |
501 |
tab = tab.substring(0, tab.length()-2); |
502 |
Curve curve = new Curve();
|
503 |
curve.setId(id); |
504 |
curve.setSrs(srs); |
505 |
curve.setX(x); |
506 |
curve.setY(y); |
507 |
curve.setZ(z);; |
508 |
return curve;
|
509 |
} |
510 |
|
511 |
public void endCurve(Object curve) { |
512 |
System.out.print(tab + "\t"+ "End Curve:\n"); |
513 |
} |
514 |
|
515 |
public Object startMultiCurve(String id, String srs) { |
516 |
System.out.print(tab + "Start MultiCurve, ID: " + id + ", SRS:" + srs + "\n"); |
517 |
tab = tab + "\t";
|
518 |
MultiCurve multiCurve = new MultiCurve();
|
519 |
multiCurve.setId(id); |
520 |
multiCurve.setSrs(srs); |
521 |
return multiCurve;
|
522 |
} |
523 |
|
524 |
public void endMultiCurve(Object multiCurve) { |
525 |
tab = tab.substring(0, tab.length()-1); |
526 |
System.out.print(tab + "End MultiCurve\n"); |
527 |
} |
528 |
|
529 |
public void addCurveToMultiCurve(Object curve, Object multiCurve) { |
530 |
System.out.print(tab + "Add Curve to MultiCurve"); |
531 |
((MultiCurve)multiCurve).addCurve((Curve)curve); |
532 |
} |
533 |
} |
534 |
|