Revision 195

View differences:

org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/test/java/org/gvsig/gpe/lib/impl/parser/GPEContentHandlerTest.java
1
package org.gvsig.gpe.lib.impl.parser;
2

  
3
import java.io.IOException;
4
import java.util.ArrayList;
5

  
6
import javax.xml.namespace.QName;
7

  
8
import org.gvsig.gpe.lib.api.parser.IAttributesIterator;
9
import org.gvsig.gpe.lib.api.parser.ICoordinateIterator;
10
import org.gvsig.gpe.lib.impl.containers.Bbox;
11
import org.gvsig.gpe.lib.impl.containers.Curve;
12
import org.gvsig.gpe.lib.impl.containers.Element;
13
import org.gvsig.gpe.lib.impl.containers.Feature;
14
import org.gvsig.gpe.lib.impl.containers.Geometry;
15
import org.gvsig.gpe.lib.impl.containers.Layer;
16
import org.gvsig.gpe.lib.impl.containers.LineString;
17
import org.gvsig.gpe.lib.impl.containers.LinearRing;
18
import org.gvsig.gpe.lib.impl.containers.MetaData;
19
import org.gvsig.gpe.lib.impl.containers.MultiCurve;
20
import org.gvsig.gpe.lib.impl.containers.MultiGeometry;
21
import org.gvsig.gpe.lib.impl.containers.MultiLineString;
22
import org.gvsig.gpe.lib.impl.containers.MultiPoint;
23
import org.gvsig.gpe.lib.impl.containers.MultiPolygon;
24
import org.gvsig.gpe.lib.impl.containers.Point;
25
import org.gvsig.gpe.lib.impl.containers.Polygon;
26
import org.gvsig.gpe.lib.impl.containers.Time;
27

  
28
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
29
 *
30
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
31
 *
32
 * This program is free software; you can redistribute it and/or
33
 * modify it under the terms of the GNU General Public License
34
 * as published by the Free Software Foundation; either version 2
35
 * of the License, or (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
45
 *
46
 * For more information, contact:
47
 *
48
 *  Generalitat Valenciana
49
 *   Conselleria d'Infraestructures i Transport
50
 *   Av. Blasco Ib??ez, 50
51
 *   46010 VALENCIA
52
 *   SPAIN
53
 *
54
 *      +34 963862235
55
 *   gvsig@gva.es
56
 *      www.gvsig.gva.es
57
 *
58
 *    or
59
 *
60
 *   IVER T.I. S.A
61
 *   Salamanca 50
62
 *   46005 Valencia
63
 *   Spain
64
 *
65
 *   +34 963163400
66
 *   dac@iver.es
67
 */
68
/* CVS MESSAGES:
69
 *
70
 * $Id: GPEContentHandlerTest.java 202 2007-11-27 12:00:11Z jpiera $
71
 * $Log$
72
 * Revision 1.14  2007/06/07 14:52:28  jorpiell
73
 * Add the schema support
74
 *
75
 * Revision 1.13  2007/05/15 12:09:41  jorpiell
76
 * The bbox is linked to the feature
77
 *
78
 * Revision 1.12  2007/05/15 11:54:35  jorpiell
79
 * A wrong label fixed
80
 *
81
 * Revision 1.11  2007/05/15 07:28:34  jorpiell
82
 * Children Element printed
83
 *
84
 * Revision 1.10  2007/05/14 09:29:34  jorpiell
85
 * Add some comments when an element is added
86
 *
87
 * Revision 1.9  2007/05/09 10:25:45  jorpiell
88
 * Add the multiGeometries
89
 *
90
 * Revision 1.8  2007/05/09 08:35:58  jorpiell
91
 * fixed an exception
92
 *
93
 * Revision 1.7  2007/05/02 11:46:07  jorpiell
94
 * Writing tests updated
95
 *
96
 * Revision 1.6  2007/04/26 14:39:12  jorpiell
97
 * Add some tests
98
 *
99
 * Revision 1.5  2007/04/19 07:23:20  jorpiell
100
 * Add the add methods to teh contenhandler and change the register mode
101
 *
102
 * Revision 1.4  2007/04/17 07:53:55  jorpiell
103
 * Before to start a new parsing process, the initialize method of the content handlers is throwed
104
 *
105
 * Revision 1.3  2007/04/14 16:06:35  jorpiell
106
 * Add the container classes
107
 *
108
 * Revision 1.2  2007/04/13 13:14:55  jorpiell
109
 * Created the base tests and add some methods to the content handler
110
 *
111
 * Revision 1.1  2007/04/12 17:06:42  jorpiell
112
 * First GML writing tests
113
 *
114
 *
115
 */
116
/**
117
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
118
 */
119
public class GPEContentHandlerTest extends GPEContentHandler{
120
	private String tab = "";
121
	private ArrayList layers = new ArrayList();
122

  
123
	/**
124
	 * @return the layers without parent layer
125
	 */
126
	public ArrayList getLayers() {
127
		ArrayList newLayers = new ArrayList();
128
		for (int i=0 ; i<layers.size() ; i++){
129
			if (((Layer)layers.get(i)).getParentLayer() == null){
130
				newLayers.add(layers.get(i));
131
			}
132
		}
133
		return newLayers;
134
	}
135

  
136
	public void addNameToFeature(Object feature, String name){
137
		System.out.print(tab + "Feature name changed: " + name + "\n");
138
		((Feature)feature).setName(name);
139
	}
140

  
141
	public void endFeature(Object feature) {
142
		System.out.print(tab + "End Feature\n");		
143
	}	
144

  
145
	public void initialize(){
146
		layers = new ArrayList();
147
	}
148

  
149
	public void addBboxToFeature(Object bbox, Object feature) {
150
		((Feature)feature).setBbox(bbox);
151

  
152
	}
153

  
154
	public void addBboxToLayer(Object bbox, Object layer) {
155
		Bbox box = (Bbox)bbox;
156
		System.out.print(tab + "Layer bbox Added:\n");
157
		tab = tab + "\t";
158
		System.out.print(tab + "MINX: " + box.getMinX() + "\n");
159
		System.out.print(tab + "MINY: " + box.getMinY() + "\n");
160
		System.out.print(tab + "MINZ: " + box.getMinZ() + "\n");
161
		System.out.print(tab + "MAXX: " + box.getMaxX() + "\n");
162
		System.out.print(tab + "MAXY: " + box.getMaxY() + "\n");
163
		System.out.print(tab + "MAXZ: " + box.getMaxZ() + "\n");
164
		System.out.print(tab + "SRS: " + box.getSrs() + "\n");
165
		tab = tab.substring(0, tab.length()-1);
166
		((Layer)layer).setBbox(bbox);
167
	}
168

  
169
	public void addDescriptionToLayer(String description, Object layer) {
170
		System.out.print(tab + "Layer description changed: " + description + "\n");
171
		((Layer)layer).setDescription(description);
172
	}
173

  
174
	public void addElementToFeature(Object element, Object feature) {
175
		Element elem = (Element)element;
176
		tab = tab + "\t";
177
		System.out.print(tab + "Add Element " + elem.getName() + "=" +
178
				elem.getValue() + " to Feature\n");
179
		printChildElements(elem);		
180
		tab = tab.substring(0, tab.length()-1);
181
		((Feature)feature).addElement(element);		
182
	}
183

  
184
	/**
185
	 * Print the element children 
186
	 * @param element to print
187
	 */
188
	private void printChildElements(Element element){
189
		tab = tab + "\t";
190
		for (int i=0 ; i< element.getElements().size() ; i++){
191
			Element child = element.getElementAt(i);
192
			System.out.print(tab + "- Element " + child.getName() + "=" +
193
					child.getValue() + "\n");
194
			printChildElements(child);
195
		}
196
		tab = tab.substring(0, tab.length()-1);
197
	}
198

  
199
	public void addFeatureToLayer(Object feature, Object layer) {
200
		((Layer)layer).addFeature(feature);
201

  
202
	}
203

  
204
	public void addGeometryToFeature(Object geometry, Object feature) {
205
		((Feature)feature).setGeometry(geometry);
206

  
207
	}
208

  
209
	public void addInnerPolygonToPolygon(Object innerPolygon, Object polygon) {
210
		((Polygon)polygon).addInnerBoundary(innerPolygon);
211

  
212
	}
213

  
214
	public void addNameToFeature(String name, Object feature) {
215
		((Feature)feature).setName(name);
216

  
217
	}
218

  
219
	public void addNameToLayer(String name, Object layer) {
220
		System.out.print(tab + "Layer name changed: " + name + "\n");
221
		((Layer)layer).setName(name);		
222
	}
223

  
224
	public void addParentElementToElement(Object parent, Object element) {
225
		((Element)element).setParentElement(parent);
226

  
227
	}
228

  
229
	public void addParentLayerToLayer(Object parent, Object layer) {
230
		((Layer)layer).setParentLayer(parent);
231

  
232
	}
233

  
234
	public void addSrsToLayer(String srs, Object layer) {
235
		((Layer)layer).setSrs(srs);
236

  
237
	}
238

  
239

  
240
	public Object startBbox(String id, ICoordinateIterator coords, String srs) {
241
		Bbox bbox = new Bbox(coords.getDimension());
242
		double[] min = new double[coords.getDimension()];
243
		double[] max = new double[coords.getDimension()];
244
		try {
245
			if (coords.hasNext()){
246
				coords.next(min);
247
				bbox.addCoordinate(min);
248
				if (coords.hasNext()){
249
					coords.next(max);
250
					bbox.addCoordinate(max);
251
				}
252
			}
253
		} catch (IOException e) {
254
			e.printStackTrace();
255
		}
256
		bbox.setId(id);
257
		bbox.setSrs(srs);
258
		return bbox;
259
	}
260

  
261
	public void endBbox(Object bbox) {
262
		// TODO Ap?ndice de m?todo generado autom?ticamente
263
	}
264

  
265
	public Object startElement(String namespace, String name, Object value,  IAttributesIterator iterator, Object parentElement) {
266
		Element element = new Element();
267
		element.setParentElement(parentElement);
268
		element.setName(name);
269
		element.setValue(value);		
270
		return element;
271
	}
272

  
273
	public void endElement(Object element) {
274
		// TODO Ap?ndice de m?todo generado autom?ticamente
275

  
276
	}
277

  
278
	public Object startFeature(String id, String namspace, String name, IAttributesIterator iterator, Object layer) {
279
		System.out.print(tab + "Start Feature, ID: " +  id + " NAME: " + name + "\n");
280
		Feature feature = new Feature();
281
		feature.setName(name);
282
		feature.setId(id);
283
		if (layer != null){
284
			addFeatureToLayer(feature, layer);
285
		}
286
		return feature;
287
	}
288

  
289
	public Object startInnerPolygon(String id, ICoordinateIterator coords, String srs) {
290
		tab = tab + "\t";
291
		System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n");
292
		tab = tab + "\t";
293
		Polygon inner = new Polygon();		
294
		try {
295
			while(coords.hasNext()){
296
				double[] buffer = new double[coords.getDimension()];
297
				coords.next(buffer);
298
				inner.addCoordinate(buffer);
299
				System.out.print(tab);
300
				for (int i=0 ; i<buffer.length ; i++){
301
					System.out.print(buffer[i]);
302
					if (i<buffer.length-1){
303
						System.out.print(",");
304
					}				
305
				}
306
				System.out.print("\n");
307
			}
308
		} catch (IOException e) {
309
			e.printStackTrace();
310
		}		
311
		inner.setId(id);
312
		inner.setSrs(srs);
313
		tab = tab.substring(0, tab.length()-2);
314
		return inner;
315
	}
316

  
317
	/*
318
	 * (non-Javadoc)
319
	 * @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object)
320
	 */
321
	public void endInnerPolygon(Object polygon){
322
		tab = tab + "\t";
323
		System.out.print(tab + "End InnerPolygon\n");
324
		tab = tab.substring(0, tab.length()-1);
325
	}
326

  
327

  
328
	public Object startLayer(String id, String namespace, String name, String description, String srs,  IAttributesIterator iterator, Object parentLayer, Object bBox) {
329
		System.out.print(tab + "Start Layer, ID: " +  id + " NAME: " + name + "\n");
330
		tab = tab + "\t";
331
		Layer layer = new Layer();
332
		layer.setId(id);
333
		layer.setName(name);
334
		layer.setDescription(description);
335
		layer.setSrs(srs);
336
		layer.setBbox(bBox);
337
		layer.setParentLayer(parentLayer);
338
		if (parentLayer != null){
339
			((Layer)parentLayer).addLayer(layer);
340
		}
341
		layers.add(layer);
342
		return layer;
343
	}	
344

  
345
	public void endLayer(Object layer) {
346
		tab = tab.substring(0, tab.length()-1);
347
		System.out.print(tab + "End Layer\n");		
348
	}
349

  
350
	public Object startLineString(String id, ICoordinateIterator coords, String srs) {
351
		tab = tab + "\t";
352
		System.out.print(tab + "Start LineString, SRS:" + srs + "\n");
353
		tab = tab + "\t";		
354
		LineString lineString = new LineString();		
355
		try {
356
			while(coords.hasNext()){
357
				double[] buffer = new double[coords.getDimension()];
358
				coords.next(buffer);
359
				lineString.addCoordinate(buffer);
360
				System.out.print(tab);
361
				for (int i=0 ; i<buffer.length ; i++){
362
					System.out.print(buffer[i]);
363
					if (i<buffer.length-1){
364
						System.out.print(",");
365
					}				
366
				}
367
				System.out.print("\n");
368
			}
369
		} catch (IOException e) {
370
			e.printStackTrace();
371
		}		
372
		lineString.setId(id);
373
		lineString.setSrs(srs);
374
		tab = tab.substring(0, tab.length()-2);
375
		return lineString;
376
	}
377

  
378
	public void endLineString(Object line) {
379
		System.out.print(tab + "\t"+ "End LineString:\n");
380
	}	
381

  
382
	public Object startPoint(String id, ICoordinateIterator coords, String srs) {
383
		tab = tab + "\t";
384
		System.out.print(tab + "Start Point, SRS:" + srs + "\n");
385
		tab = tab + "\t";		
386
		Point point = new Point();
387
		double[] buffer = new double[coords.getDimension()];
388
		try {
389
			if (coords.hasNext()){
390
				coords.next(buffer);
391
				point.setCoordinates(buffer);				
392
				System.out.print(tab);
393
				for (int i=0 ; i<buffer.length ; i++){
394
					System.out.print(buffer[i]);
395
					if (i<buffer.length-1){
396
						System.out.print(",");
397
					}				
398
				}
399
				System.out.print("\n");
400
			}
401
		} catch (IOException e) {
402
			e.printStackTrace();
403
		}		
404
		
405
		point.setId(id);
406
		point.setSrs(srs);
407
		tab = tab.substring(0, tab.length()-2);
408
		return point;
409
	}	
410

  
411
	public void endPoint(Object point) {
412
		System.out.print(tab + "\t" + "End Point\n");
413
	}
414

  
415
	public Object startPolygon(String id, ICoordinateIterator coords, String srs) {
416
		tab = tab + "\t";
417
		System.out.print(tab + "Start Polygon, SRS:" + srs + "\n");
418
		tab = tab + "\t";
419
		Polygon polygon = new Polygon();		
420
		try {
421
			while(coords.hasNext()){
422
				double[] buffer = new double[coords.getDimension()];
423
				coords.next(buffer);
424
				polygon.addCoordinate(buffer);
425
				System.out.print(tab);
426
				for (int i=0 ; i<buffer.length ; i++){
427
					System.out.print(buffer[i]);
428
					if (i<buffer.length-1){
429
						System.out.print(",");
430
					}				
431
				}
432
				System.out.print("\n");
433
			}
434
		} catch (IOException e) {
435
			e.printStackTrace();
436
		}		
437
		polygon.setId(id);
438
		polygon.setSrs(srs);
439
		tab = tab.substring(0, tab.length()-2);
440
		return polygon;
441
	}
442

  
443

  
444
	public void endPolygon(Object polygon) {
445
		System.out.print(tab + "\t"+ "End Polygon\n");
446
	}
447

  
448

  
449
	public Object startLinearRing(String id, ICoordinateIterator coords, String srs) {
450
		System.out.print(tab + "Start LinearRing, SRS:" + srs + "\n");
451
		tab = tab + "\t";
452
		LinearRing linearRing = new LinearRing();		
453
		try {
454
			while(coords.hasNext()){
455
				double[] buffer = new double[coords.getDimension()];
456
				coords.next(buffer);
457
				linearRing.addCoordinate(buffer);
458
				System.out.print(tab);
459
				for (int i=0 ; i<buffer.length ; i++){
460
					System.out.print(buffer[i]);
461
					if (i<buffer.length-1){
462
						System.out.print(",");
463
					}				
464
				}
465
				System.out.print("\n");
466
			}
467
		} catch (IOException e) {
468
			e.printStackTrace();
469
		}		
470
		linearRing.setId(id);
471
		linearRing.setSrs(srs);
472
		tab = tab.substring(0, tab.length()-1);
473
		return linearRing;
474
	}
475

  
476

  
477
	public void endLinearRing(Object linearRing) {
478
		System.out.print(tab + "End LinearRing\n");
479
	}
480

  
481

  
482
	public Object startMultiPoint(String id, String srs) {
483
		System.out.print(tab + "Start MultiPoint, ID: " + id + ", SRS:" + srs + "\n");
484
		tab = tab + "\t";
485
		MultiPoint multiPoint = new MultiPoint();
486
		multiPoint.setId(id);
487
		multiPoint.setSrs(srs);
488
		return multiPoint;
489
	}	
490

  
491
	public void endMultiPoint(Object multiPoint) {
492
		tab = tab.substring(0, tab.length()-1);		
493
		System.out.print(tab + "End MultiPoint\n");		
494
	}
495

  
496
	public void addPointToMultiPoint(Object point, Object multiPoint) {
497
		System.out.print(tab + "Add Point to MultiPoint");	
498
		((MultiPoint)multiPoint).addPoint((Point)point);
499
	}
500

  
501
	public Object startMultiLineString(String id, String srs) {
502
		System.out.print(tab + "Start MultiLineString, ID: " + id + ", SRS:" + srs + "\n");
503
		tab = tab + "\t";
504
		MultiLineString multiLineString = new MultiLineString();
505
		multiLineString.setId(id);
506
		multiLineString.setSrs(srs);
507
		return multiLineString;		
508
	}
509

  
510
	public void endMultiLineString(Object multiLineString) {
511
		tab = tab.substring(0, tab.length()-1);		
512
		System.out.print(tab + "End MultiLineString\n");		
513
	}	
514

  
515
	public void addLineStringToMultiLineString(Object lineString, Object multiLineString) {
516
		System.out.print(tab + "Add LineString to MultiLineString");	
517
		((MultiLineString)multiLineString).addLineString((LineString)lineString);
518
	}
519

  
520
	public Object startMultiPolygon(String id, String srs) {
521
		System.out.print(tab + "Start MultiPolygon, ID: " + id + ", SRS:" + srs + "\n");
522
		tab = tab + "\t";
523
		MultiPolygon multiPolygon = new MultiPolygon();
524
		multiPolygon.setId(id);
525
		multiPolygon.setSrs(srs);
526
		return multiPolygon;	
527
	}
528

  
529
	public void endMultiPolygon(Object multiPolygon) {
530
		tab = tab.substring(0, tab.length()-1);		
531
		System.out.print(tab + "End MultiPolygon\n");		
532
	}
533

  
534
	public void addPolygonToMultiPolygon(Object polygon, Object multiPolygon) {
535
		System.out.print(tab + "Add Polygon to MultiPolygon");	
536
		((MultiPolygon)multiPolygon).addPolygon((Polygon)polygon);
537
	}
538

  
539
	public Object startMultiGeometry(String id, String srs) {
540
		System.out.print(tab + "Start MultiGeometry, ID: " + id + ", SRS:" + srs + "\n");
541
		tab = tab + "\t";
542
		MultiGeometry multiGeometry = new MultiGeometry();
543
		multiGeometry.setId(id);
544
		multiGeometry.setSrs(srs);
545
		return multiGeometry;	
546
	}
547

  
548
	public void endMultiGeometry(Object multiGeometry) {
549
		tab = tab.substring(0, tab.length()-1);		
550
		System.out.print(tab + "End MultiGeometry\n");		
551
	}
552

  
553
	public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) {
554
		if (geometry instanceof Point){
555
			System.out.print(tab + "Add Point to MultiGeometry");
556
		}else if (geometry instanceof LineString){
557
			System.out.print(tab + "Add LineString to MultiGeometry");
558
		}else if (geometry instanceof Polygon){
559
			System.out.print(tab + "Add Polygon to MultiGeometry");
560
		}else if (geometry instanceof Curve){
561
			System.out.print(tab + "Add LineString to Curve");
562
		}else {
563
			System.out.print(tab + "Add Geometry to MultiGeometry");
564
		}		
565
		((MultiGeometry)multiGeometry).addGeometry((Geometry)geometry);
566
	}
567

  
568

  
569
	public Object startCurve(String id, ICoordinateIterator coords, String srs){
570
		tab = tab + "\t";
571
		System.out.print(tab + "Start Curve, ID: " + id + ", SRS:" + srs + "\n");
572
		tab = tab + "\t";
573
		Curve curve = new Curve();		
574
		try {
575
			while(coords.hasNext()){
576
				double[] buffer = new double[coords.getDimension()];
577
				coords.next(buffer);
578
				curve.addCoordinate(buffer);
579
				System.out.print(tab);
580
				for (int i=0 ; i<buffer.length ; i++){
581
					System.out.print(buffer[i]);
582
					if (i<buffer.length-1){
583
						System.out.print(",");
584
					}				
585
				}
586
				System.out.print("\n");
587
			}
588
		} catch (IOException e) {
589
			e.printStackTrace();
590
		}		
591
		curve.setId(id);
592
		curve.setSrs(srs);
593
		tab = tab.substring(0, tab.length()-2);
594
		return curve;
595
	}	
596

  
597
	public void endCurve(Object curve) {
598
		System.out.print(tab + "\t"+ "End Curve:\n");				
599
	}
600

  
601
	public Object startMultiCurve(String id, String srs) {
602
		System.out.print(tab + "Start MultiCurve, ID: " + id + ", SRS:" + srs + "\n");
603
		tab = tab + "\t";
604
		MultiCurve multiCurve = new MultiCurve();
605
		multiCurve.setId(id);
606
		multiCurve.setSrs(srs);
607
		return multiCurve;
608
	}
609

  
610
	public void endMultiCurve(Object multiCurve) {
611
		tab = tab.substring(0, tab.length()-1);		
612
		System.out.print(tab + "End MultiCurve\n");		
613
	}
614

  
615
	public void addCurveToMultiCurve(Object curve, Object multiCurve) {
616
		System.out.print(tab + "Add Curve to MultiCurve");	
617
		((MultiCurve)multiCurve).addCurve((Curve)curve);
618
	}
619

  
620
	public Object startMetadata(String type, String data, IAttributesIterator attributes){
621
		tab = tab + "\t";
622
		MetaData meta=null;
623
		System.out.print(tab + "Start Metadata, META: " + type + ", DATA:" + data + "\n");
624
		try {
625
			
626
			for(int i = 0; i<attributes.getNumAttributes();i++)
627
			{
628
				//String[] buffer = new String[2];
629
				QName name = attributes.nextAttributeName();
630
				Object value = attributes.nextAttribute();
631
				System.out.print(tab + name + " : " + value + "\n");
632
			}
633
		} catch (IOException e) {
634
			// TODO Auto-generated catch block
635
			e.printStackTrace();
636
		}
637
		meta = new MetaData();
638
		meta.setTagType(type);
639
		meta.setTagData(data);
640
		return meta;
641
	}
642
	
643
	public void endMetadata(Object metadata) {
644
		tab = tab.substring(0, tab.length()-1);
645
		System.out.print(tab + "\t"+ "End Metadata:\n");
646
	}
647
	
648
	public void addMetadataToFeature(Object metadata, Object feature){
649
		System.out.print(tab+tab + "Add Metadata to Feature \n");	
650
		((Feature)feature).addMetadata((MetaData)metadata);
651
	} 
652
	
653
	public void addMetadataToMetadata(Object metadata, Object parent){
654
		System.out.print(tab + "Add Metadata to Complex Metadata\n");	
655
		((MetaData)parent).addChildData((MetaData)metadata);
656
	}
657

  
658
	public void addTimeToFeature(Object time, Object feature) {
659
		System.out.print(tab + "Add Time to feature\n");	
660
		((Feature)feature).addTime(time);
661
	}
662

  
663
	public void endTime(Object time) {
664
		tab = tab.substring(0, tab.length()-1);
665
		System.out.print(tab + "\t"+ "End Time:\n");
666
	}
667

  
668
	public Object startTime(String type, String time) {
669
		tab = tab + "\t";
670
		System.out.print(tab + "Start Time, TYPE: " + type + ", DATA:" + time + "\n");
671
		Time t = new Time();
672
		t.setType(type);
673
		t.setValue(time);		
674
		return t;
675
	}
676

  
677
	public Object startTime(String name, String description, String type,
678
			String time, Time previous, Time next) 
679
	{
680
		tab = tab + "\t";
681
		System.out.print(tab + "Start Time, NAME: " + name + ", DATA:" + time + "\n");
682
		Time t = new Time();
683
		t.setType(type);
684
		t.setValue(time);	
685
		t.setDescription(description);
686
		t.setName(name);
687
		t.setPrevious(previous);
688
		t.setNext(next);
689
		return t;
690
	} 
691
}
692

  
0 693

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/test/java/org/gvsig/gpe/lib/impl/parser/GPEReaderBaseTest.java
1
package org.gvsig.gpe.lib.impl.parser;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
6
import java.io.InputStream;
7
import java.util.ArrayList;
8

  
9
import org.gvsig.gpe.lib.api.GPELocator;
10
import org.gvsig.gpe.lib.api.GPEManager;
11
import org.gvsig.gpe.lib.api.parser.IGPEContentHandler;
12
import org.gvsig.gpe.lib.api.parser.IGPEErrorHandler;
13
import org.gvsig.gpe.lib.impl.containers.Layer;
14
import org.gvsig.gpe.lib.spi.GPEProviderLocator;
15
import org.gvsig.gpe.lib.spi.GPEProviderManager;
16
import org.gvsig.gpe.lib.spi.parser.IGPEParser;
17
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
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: GPEReaderBaseTest.java 173 2007-11-06 12:10:57Z jpiera $
62
 * $Log$
63
 * Revision 1.7  2007/05/09 06:54:07  jorpiell
64
 * Change the File by URI
65
 *
66
 * Revision 1.6  2007/04/20 12:04:10  csanchez
67
 * Actualizacion protoripo libGPE, Aรฑadidos test para el parser, parseo con XSOM
68
 *
69
 * Revision 1.5  2007/04/19 11:50:20  csanchez
70
 * Actualizacion protoripo libGPE
71
 *
72
 * Revision 1.4  2007/04/19 07:23:20  jorpiell
73
 * Add the add methods to teh contenhandler and change the register mode
74
 *
75
 * Revision 1.3  2007/04/14 16:06:35  jorpiell
76
 * Add the container classes
77
 *
78
 * Revision 1.2  2007/04/13 13:14:55  jorpiell
79
 * Created the base tests and add some methods to the content handler
80
 *
81
 * Revision 1.1  2007/04/13 07:17:54  jorpiell
82
 * Add the writting tests for the simple geometries
83
 *
84
 *
85
 */
86
/**
87
 * This class must be implementend by all the classes that
88
 * implements a GPE reader Parser. 
89
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
90
 */
91
public abstract class GPEReaderBaseTest extends AbstractLibraryAutoInitTestCase {
92
	private File file = null;
93
	private IGPEParser parser = null;
94
	private IGPEContentHandler contenHandler = null;
95
	private IGPEErrorHandler errorHandler = null;
96
	private String parserName="FORMAT VERSION";
97
	private String parserDescription="default parser description";
98
	private GPEManager gpeManager = null;
99
	private GPEProviderManager gpeProviderManager = null;
100

  
101
	protected void doSetUp() throws Exception {
102
		gpeManager = GPELocator.getGPEManager();	
103
		gpeProviderManager = GPEProviderLocator.getGPEProviderManager();
104
	}	
105
	
106
	/**
107
	 * @return the gpeManager
108
	 */
109
	public GPEManager getGpeManager() {
110
		return gpeManager;
111
	}
112
	
113
	/**
114
	 * This test parses the file and make the 
115
	 * asserts.
116
	 * @throws Exception
117
	 */
118
	public void testParse() throws Exception{
119
		System.out.println("INFO: Parser registrado");
120
		file = new File(getFile());
121
		System.out.println("INFO: Abriendo Fichero: "+file.getName());
122
		//assertEquals(gpeManager.accept(file.toURI()),true);
123
		System.out.println("INFO: Existe parser registrado para el fomato ");
124
		parser = gpeProviderManager.createParserByClass(getGPEParserClass().getName());
125
		System.out.println("INFO: Creado el parser ");
126
		assertNotNull(parser);
127
		parseFile();
128
		parseInputStream();		
129
	}
130
	
131
	/**
132
	 * Parses the file
133
	 */
134
	private void parseFile(){
135
		System.out.println("INFO: PARSING THE FILE...");
136
		parser.parse(getContenHandler() , getErrorHandler(), file.toURI());
137
		System.out.println("INFO: ??? SUCCESS !!!");
138
		makeAsserts();
139
	}
140
	
141
	/**
142
	 * Parses the file like an inputstream
143
	 * @throws FileNotFoundException
144
	 */
145
	private void parseInputStream() throws Exception{
146
		InputStream is = getInputStream();
147
		errorHandler = null;
148
		contenHandler = null;
149
		System.out.println("INFO: PARSING THE INPUTSTREAM...");
150
		parser.parse(getContenHandler() , getErrorHandler(), is);
151
		System.out.println("INFO: ??? SUCCESS !!!");
152
		makeAsserts();
153
	}	
154
	
155
	/**
156
	 * This method has to be override by the tests that use
157
	 * other InputStream (KMZ...)
158
	 * @return
159
	 * @throws FileNotFoundException
160
	 */
161
	public InputStream getInputStream() throws Exception{
162
		return new FileInputStream(new File(getFile()));
163
	}
164
	
165
	/**
166
	 * This method must be used by the subclasses
167
	 * to make the comparations. With getLayers
168
	 * it can retrieve the parsed layers
169
	 */
170
	public abstract void makeAsserts();
171
	
172
	/**
173
	 * Each test must to return its parser name
174
	 * to register it before to start the parsing
175
	 * process
176
	 */
177
	public String getGPEParserName(){
178
		return parserName;
179
	}
180
	
181
	/**
182
	 * Each test must to return its parser description
183
	 * to register it before to start the parsing
184
	 * process
185
	 */
186
	public String getGPEParserDescription(){
187
		return parserDescription ;
188
	}
189
	/**
190
	 * Each test must to return its parser name
191
	 * to register it before to start the parsing
192
	 * process
193
	 */
194
	public void setGPEParserName(String name){
195
		parserName=name;
196
	}
197
	
198
	/**
199
	 * Each test must to return its parser description
200
	 * to register it before to start the parsing
201
	 * process
202
	 */
203
	public void setGPEParserDescription(String description){
204
		parserDescription=description;
205
	}
206
	/**
207
	 * Each test must to return its parser class
208
	 * that will be used to create new parsers.
209
	 */
210
	public abstract Class getGPEParserClass();
211
	
212
	/**
213
	 * Gets the GML file to open
214
	 * @return
215
	 */
216
	public abstract String getFile();
217
	
218
	/**
219
	 * Gets a list of parsed layers
220
	 * @return
221
	 */
222
	public Layer[] getLayers(){
223
		ArrayList layers = ((GPEContentHandlerTest)parser.getContentHandler()).getLayers();
224
		Layer[] aLayers = new Layer[layers.size()];
225
		for (int i=0 ; i<layers.size() ; i++){
226
			aLayers[i] = (Layer)layers.get(i);
227
		}
228
		return aLayers;
229
	}
230
	
231
	/**
232
	 * @return the contenHandler
233
	 */
234
	public IGPEContentHandler getContenHandler() {
235
		if (contenHandler == null){
236
			contenHandler = new GPEContentHandlerTest();
237
		}
238
		return contenHandler;
239
	}
240

  
241
	/**
242
	 * @return the errorHandler
243
	 */
244
	public IGPEErrorHandler getErrorHandler() {
245
		if (errorHandler == null){
246
			errorHandler = new GPEErrorHandlerTest();
247
		}
248
		return errorHandler;
249
	}
250
	
251
}
0 252

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/test/java/org/gvsig/gpe/lib/impl/parser/GPEErrorHandlerTest.java
1
package org.gvsig.gpe.lib.impl.parser;
2

  
3

  
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id: GPEErrorHandlerTest.java 144 2007-06-07 14:53:59Z jorpiell $
48
 * $Log$
49
 * Revision 1.6  2007/06/07 14:52:28  jorpiell
50
 * Add the schema support
51
 *
52
 * Revision 1.5  2007/05/16 09:27:55  jorpiell
53
 * Added two arrays to manage exceptions
54
 *
55
 * Revision 1.4  2007/04/19 07:23:20  jorpiell
56
 * Add the add methods to teh contenhandler and change the register mode
57
 *
58
 * Revision 1.3  2007/04/17 07:53:55  jorpiell
59
 * Before to start a new parsing process, the initialize method of the content handlers is throwed
60
 *
61
 * Revision 1.2  2007/04/13 13:14:55  jorpiell
62
 * Created the base tests and add some methods to the content handler
63
 *
64
 * Revision 1.1  2007/04/12 17:06:42  jorpiell
65
 * First GML writing tests
66
 *
67
 *
68
 */
69
/**
70
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
71
 */
72
public class GPEErrorHandlerTest extends GPEErrorHandler{
73

  
74
}
0 75

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/test/java/org/gvsig/gpe/lib/impl/writer/GPELayerWithChildrenTest.java
1
package org.gvsig.gpe.lib.impl.writer;
2

  
3
import org.gvsig.gpe.lib.impl.containers.Layer;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id: GPELayerWithChildrenTest.java 144 2007-06-07 14:53:59Z jorpiell $
48
 * $Log$
49
 * Revision 1.2  2007/06/07 14:52:28  jorpiell
50
 * Add the schema support
51
 *
52
 * Revision 1.1  2007/05/02 11:46:07  jorpiell
53
 * Writing tests updated
54
 *
55
 *
56
 */
57
/**
58
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
59
 */
60
public abstract class GPELayerWithChildrenTest extends GPEWriterBaseTest{
61
	private String layer1Id = "l1";
62
	private String layer1Name = "Layer 1";
63
	private String layer1Description = "Layer with bbox Test";
64
	private String srs = "EPSG:23030";
65
	private String layer11Id = "l1.1";
66
	private String layer11Name = "Layer 1.1";
67
	private String layer11Description = "Layer with bbox Test";
68
	private String layer111Id = "l1.1.1";
69
	private String layer111Name = "Layer 1.1.1";
70
	private String layer111Description = "Layer with bbox Test";
71
	private String layer12Id = "l1.2";
72
	private String layer12Name = "Layer 1.2";
73
	private String layer12Description = "Layer with bbox Test";
74

  
75
	/*
76
	 * (non-Javadoc)
77
	 * @see org.gvsig.gpe.writers.GPEWriterBaseTest#readObjects()
78
	 */
79
	public void readObjects() {
80
		Layer[] layers = getLayers();
81
		assertEquals(layers.length, 1);		
82
		Layer layer = layers[0];
83
		assertEquals(layer.getName(), layer1Name);
84
		
85
		assertEquals(layer.getLayers().size(),2);
86
		assertEquals(layer.getLayerAt(0).getName(), layer11Name);
87
		assertEquals(layer.getLayerAt(0).getLayers().size(),1);
88
		assertEquals(layer.getLayerAt(0).getLayerAt(0).getName(),layer111Name);
89
		assertEquals(layer.getLayerAt(1).getName(), layer12Name);
90
	}
91

  
92
	/*
93
	 * (non-Javadoc)
94
	 * @see org.gvsig.gpe.writers.GPEWriterBaseTest#writeObjects()
95
	 */
96
	public void writeObjects() {
97
		getWriterHandler().initialize();
98
		getWriterHandler().startLayer(layer1Id, null, layer1Name, layer1Description, srs);
99
		getWriterHandler().startLayer(layer11Id, null, layer11Name, layer11Description, srs);
100
		getWriterHandler().startLayer(layer111Id, null, layer111Name, layer111Description, srs);
101
		getWriterHandler().endLayer();
102
		getWriterHandler().endLayer();
103
		getWriterHandler().startLayer(layer12Id, null, layer12Name, layer12Description, srs);
104
		getWriterHandler().endLayer();
105
		getWriterHandler().endLayer();
106
		getWriterHandler().close();		
107
	}
108
}
109

  
0 110

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/test/java/org/gvsig/gpe/lib/impl/writer/GPELayerWithBboxTest.java
1
package org.gvsig.gpe.lib.impl.writer;
2

  
3
import org.gvsig.gpe.lib.impl.containers.CoordinatesSequence;
4
import org.gvsig.gpe.lib.impl.containers.GeometryAsserts;
5
import org.gvsig.gpe.lib.impl.containers.Layer;
6

  
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
/* CVS MESSAGES:
48
 *
49
 * $Id: GPELayerWithBboxTest.java 144 2007-06-07 14:53:59Z jorpiell $
50
 * $Log$
51
 * Revision 1.3  2007/06/07 14:52:28  jorpiell
52
 * Add the schema support
53
 *
54
 * Revision 1.2  2007/05/09 08:35:58  jorpiell
55
 * fixed an exception
56
 *
57
 * Revision 1.1  2007/05/02 11:46:07  jorpiell
58
 * Writing tests updated
59
 *
60
 *
61
 */
62
/**
63
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
64
 */
65
public abstract class GPELayerWithBboxTest extends GPEWriterBaseTest{
66
	private String layerId = "l1";
67
	private String srs = "EPSG:23030";
68
	private String bboxId = "bboxID";
69
	private double[] bboxX = generateRandomBBox();
70
	private double[] bboxY = generateRandomBBox();
71
	private double[] bboxZ = generateRandomBBox();
72
	/*
73
	 * (non-Javadoc)
74
	 * @see org.gvsig.gpe.writers.GPEWriterBaseTest#readObjects()
75
	 */
76
	public void readObjects() {
77
		Layer[] layers = getLayers();
78
		assertEquals(layers.length, 1);		
79
		Layer layer = layers[0];
80
		GeometryAsserts.bbox(layer.getBbox(),bboxX,bboxY,bboxZ);
81
	}
82

  
83
	/*
84
	 * (non-Javadoc)
85
	 * @see org.gvsig.gpe.writers.GPEWriterBaseTest#writeObjects()
86
	 */
87
	public void writeObjects() {
88
		getWriterHandler().initialize();
89
		getWriterHandler().startLayer(layerId, null, null, srs, null);
90
		getWriterHandler().startBbox(bboxId, new CoordinatesSequence(bboxX,	bboxY, bboxZ), srs);
91
		getWriterHandler().endBbox();
92
		getWriterHandler().endLayer();
93
		getWriterHandler().close();		
94
	}
95
}
0 96

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/test/java/org/gvsig/gpe/lib/impl/writer/GPEFeatureWithElementsTest.java
1
package org.gvsig.gpe.lib.impl.writer;
2

  
3
import java.io.File;
4

  
5
import org.gvsig.gpe.lib.impl.containers.CoordinatesSequence;
6
import org.gvsig.gpe.lib.impl.containers.Element;
7
import org.gvsig.gpe.lib.impl.containers.Feature;
8
import org.gvsig.gpe.lib.impl.containers.Layer;
9

  
10
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
11
 *
12
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
13
 *
14
 * This program is free software; you can redistribute it and/or
15
 * modify it under the terms of the GNU General Public License
16
 * as published by the Free Software Foundation; either version 2
17
 * of the License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
27
 *
28
 * For more information, contact:
29
 *
30
 *  Generalitat Valenciana
31
 *   Conselleria d'Infraestructures i Transport
32
 *   Av. Blasco Ib??ez, 50
33
 *   46010 VALENCIA
34
 *   SPAIN
35
 *
36
 *      +34 963862235
37
 *   gvsig@gva.es
38
 *      www.gvsig.gva.es
39
 *
40
 *    or
41
 *
42
 *   IVER T.I. S.A
43
 *   Salamanca 50
44
 *   46005 Valencia
45
 *   Spain
46
 *
47
 *   +34 963163400
48
 *   dac@iver.es
49
 */
50
/* CVS MESSAGES:
51
 *
52
 * $Id: GPEFeatureWithElementsTest.java 150 2007-06-14 13:50:06Z jorpiell $
53
 * $Log$
54
 * Revision 1.4  2007/06/14 13:50:06  jorpiell
55
 * The schema jar name has been changed
56
 *
57
 * Revision 1.3  2007/06/07 14:52:28  jorpiell
58
 * Add the schema support
59
 *
60
 * Revision 1.2  2007/05/15 09:52:00  jorpiell
61
 * The namespace is deleted from the element name
62
 *
63
 * Revision 1.1  2007/05/02 11:46:07  jorpiell
64
 * Writing tests updated
65
 *
66
 *
67
 */
68
/**
69
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
70
 */
71
public abstract class GPEFeatureWithElementsTest extends GPEWriterBaseTest {
72
	private String namespace = "http://www,gvsig.org/cit";
73
	private String layerId = "l1";
74
	private String layerName = "Points Layer";
75
	private String layerDescription = "This is a test of a points layer";
76
	private String srs = "EPSG:23030";
77
	private String feature1Name = "New York";
78
	private String feature1Id = "f1";
79
	private String point1Id = "p1";
80
	private double point1X = generateRandomPoint();
81
	private double point1Y = generateRandomPoint();
82
	private double point1Z = generateRandomPoint();
83
	private String element1Name = "Population";
84
	private String element1Value = "30000";
85
	//private String element1Type = TypeUtils.getXSType(element1Value.getClass());
86
	private String element2Name = "Country";
87
	private String element2Value = "USA";
88
	//private String element2Type = TypeUtils.getXSType(element2Value.getClass());
89
	private String element3Name = "Capital";
90
	private String element3Value = "false";
91
	//private String element3Type = TypeUtils.getXSType(element3Value.getClass());
92
	
93
	/*
94
	 * (non-Javadoc)
95
	 * @see org.gvsig.gpe.writers.GPEWriterBaseTest#readObjects()
96
	 */
97
	public void readObjects() {
98
		Layer[] layers = getLayers();
99
		assertEquals(layers.length, 1);		
100
		Layer layer = layers[0];
101
	
102
		assertEquals(layer.getFeatures().size(), 1);
103
		//FEATURE 1
104
		Feature feature1 = (Feature)layer.getFeatures().get(0);
105
		Element element1 = feature1.getElementAt(0);
106
		assertEquals(element1.getName(), element1Name);
107
		assertEquals(element1.getValue(), element1Value.toString());
108
		//assertEquals(element1.getType(), element1Type);
109
		Element element2 = feature1.getElementAt(1);
110
		assertEquals(element2.getName(), element2Name);
111
		assertEquals(element2.getValue(), element2Value.toString());
112
		//assertEquals(element2.getType(), element2Type);
113
		Element element3 = feature1.getElementAt(2);
114
		assertEquals(element3.getName(), element3Name);
115
		assertEquals(element3.getValue(), element3Value.toString());
116
		//assertEquals(element3.getType(), element3Type);
117
		
118
	}
119

  
120
	/*
121
	 * (non-Javadoc)
122
	 * @see org.gvsig.gpe.writers.GPEWriterBaseTest#writeObjects()
123
	 */
124
	public void writeObjects() {
125
		getWriterHandler().initialize();
126
		getWriterHandler().startLayer(layerId, null, layerName, layerDescription, srs);
127
		getWriterHandler().startFeature(feature1Id, null, feature1Name);
128
		getWriterHandler().startPoint(point1Id, new CoordinatesSequence(point1X, point1Y, point1Z), srs);
129
		getWriterHandler().endPoint();	
130
		getWriterHandler().startElement(namespace,
131
				element1Name,
132
				element1Value);
133
		getWriterHandler().endElement();
134
		getWriterHandler().startElement(namespace,
135
				element2Name,
136
				element2Value);
137
		getWriterHandler().endElement();
138
		getWriterHandler().startElement(namespace,
139
				element3Name,
140
				element3Value);
141
		getWriterHandler().endElement();
142
		getWriterHandler().endFeature();		
143
		getWriterHandler().endLayer();
144
		getWriterHandler().close();		
145
	}
146
	
147
	/*
148
	 * (non-Javadoc)
149
	 * @see org.gvsig.gpe.writers.GPEWriterBaseTest#getSchemaPath()
150
	 */
151
	protected String getSchemaPath(){
152
		return new File("testdata/cities.xsd").getAbsolutePath();
153
	}
154
}
0 155

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/test/java/org/gvsig/gpe/lib/impl/writer/GPELayerWithIdTest.java
1
package org.gvsig.gpe.lib.impl.writer;
2

  
3
import org.gvsig.gpe.lib.impl.containers.Layer;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id: GPELayerWithIdTest.java 144 2007-06-07 14:53:59Z jorpiell $
48
 * $Log$
49
 * Revision 1.2  2007/06/07 14:52:28  jorpiell
50
 * Add the schema support
51
 *
52
 * Revision 1.1  2007/05/02 11:46:07  jorpiell
53
 * Writing tests updated
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff