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