svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / GPEContentHandlerTest.java @ 11209
History | View | Annotate | Download (7.44 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.Layer; |
9 |
import org.gvsig.gpe.containers.LineString; |
10 |
import org.gvsig.gpe.containers.Point; |
11 |
import org.gvsig.gpe.containers.Polygon; |
12 |
|
13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
14 |
*
|
15 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
16 |
*
|
17 |
* This program is free software; you can redistribute it and/or
|
18 |
* modify it under the terms of the GNU General Public License
|
19 |
* as published by the Free Software Foundation; either version 2
|
20 |
* of the License, or (at your option) any later version.
|
21 |
*
|
22 |
* This program is distributed in the hope that it will be useful,
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
25 |
* GNU General Public License for more details.
|
26 |
*
|
27 |
* You should have received a copy of the GNU General Public License
|
28 |
* along with this program; if not, write to the Free Software
|
29 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
30 |
*
|
31 |
* For more information, contact:
|
32 |
*
|
33 |
* Generalitat Valenciana
|
34 |
* Conselleria d'Infraestructures i Transport
|
35 |
* Av. Blasco Ib??ez, 50
|
36 |
* 46010 VALENCIA
|
37 |
* SPAIN
|
38 |
*
|
39 |
* +34 963862235
|
40 |
* gvsig@gva.es
|
41 |
* www.gvsig.gva.es
|
42 |
*
|
43 |
* or
|
44 |
*
|
45 |
* IVER T.I. S.A
|
46 |
* Salamanca 50
|
47 |
* 46005 Valencia
|
48 |
* Spain
|
49 |
*
|
50 |
* +34 963163400
|
51 |
* dac@iver.es
|
52 |
*/
|
53 |
/* CVS MESSAGES:
|
54 |
*
|
55 |
* $Id: GPEContentHandlerTest.java 11209 2007-04-14 16:06:35Z jorpiell $
|
56 |
* $Log$
|
57 |
* Revision 1.3 2007-04-14 16:06:35 jorpiell
|
58 |
* Add the container classes
|
59 |
*
|
60 |
* Revision 1.2 2007/04/13 13:14:55 jorpiell
|
61 |
* Created the base tests and add some methods to the content handler
|
62 |
*
|
63 |
* Revision 1.1 2007/04/12 17:06:42 jorpiell
|
64 |
* First GML writing tests
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
/**
|
69 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
70 |
*/
|
71 |
public class GPEContentHandlerTest extends GPEContentHandler{ |
72 |
private String tab = ""; |
73 |
private Layer currentLayer = null; |
74 |
private Feature currentFeature = null; |
75 |
private ArrayList layers = new ArrayList(); |
76 |
|
77 |
public Object startLayer(Object parent, Object bBox, String id, |
78 |
String name, String description,String srs) { |
79 |
System.out.print(tab + "Start Layer: " + name + "\n"); |
80 |
tab = tab + "\t";
|
81 |
Layer layer = new Layer();
|
82 |
layer.setParentLayer(parent); |
83 |
layer.setBbox(bBox); |
84 |
layer.setId(id); |
85 |
layer.setName(name); |
86 |
layer.setDescription(description); |
87 |
layer.setSrs(srs); |
88 |
currentLayer = layer; |
89 |
return layer;
|
90 |
} |
91 |
|
92 |
public void endLayer(Object layer) { |
93 |
tab = tab.substring(0, tab.length()-1); |
94 |
System.out.print(tab + "End Layer\n"); |
95 |
if (currentLayer != null){ |
96 |
if (currentLayer.getParentLayer() == null){ |
97 |
layers.add(currentLayer); |
98 |
} |
99 |
currentLayer = currentLayer.getParentLayer(); |
100 |
} |
101 |
} |
102 |
|
103 |
public void addNameToLayer(Object layer,String name){ |
104 |
System.out.print(tab + "Layer name changed: " + name + "\n"); |
105 |
((Layer)layer).setName(name); |
106 |
} |
107 |
|
108 |
public void addDescriptionToLayer(Object layer,String description){ |
109 |
System.out.print(tab + "Layer description changed: " + description + "\n"); |
110 |
((Layer)layer).setDescription(description); |
111 |
} |
112 |
|
113 |
public Object startElement(Object parent, String name, Object value, |
114 |
Object type) {
|
115 |
Element element = new Element(); |
116 |
element.setParentElement(parent); |
117 |
element.setName(name); |
118 |
element.setValue(value); |
119 |
element.setType(type); |
120 |
if (parent == null){ |
121 |
currentFeature.addElement(element); |
122 |
} |
123 |
return element;
|
124 |
} |
125 |
|
126 |
public void endElement(Object element) { |
127 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
128 |
|
129 |
} |
130 |
|
131 |
public Object startBbox(double[] x, double[] y, double[] z, String id, |
132 |
String srs) {
|
133 |
Bbox bbox = new Bbox();
|
134 |
bbox.setX(x); |
135 |
bbox.setY(y); |
136 |
bbox.setZ(z); |
137 |
bbox.setId(id); |
138 |
bbox.setSrs(srs); |
139 |
return bbox;
|
140 |
} |
141 |
|
142 |
public void endBbox(Object bbox) { |
143 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
144 |
|
145 |
} |
146 |
|
147 |
public Object startPoint(double x, double y, double z, String id, String srs) { |
148 |
System.out.print(tab + "Start Point, SRS:" + srs + "\n"); |
149 |
tab = tab + "\t";
|
150 |
System.out.print(tab + x + "," + y + "," + z + "\n"); |
151 |
tab = tab.substring(0, tab.length()-1); |
152 |
Point point = new Point(); |
153 |
point.setX(x); |
154 |
point.setY(y); |
155 |
point.setZ(z); |
156 |
point.setId(id); |
157 |
point.setSrs(srs); |
158 |
currentFeature.setGeometry(point); |
159 |
return point;
|
160 |
} |
161 |
|
162 |
public void endPoint(Object point) { |
163 |
System.out.print(tab + "End Point\n"); |
164 |
} |
165 |
|
166 |
public Object startLineString(double[] x, double[] y, double[] z, String id, |
167 |
String srs) {
|
168 |
System.out.print(tab + "Start LineString, SRS:" + srs + "\n"); |
169 |
tab = tab + "\t";
|
170 |
for (int i=0 ; i<x.length ; i++){ |
171 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
172 |
} |
173 |
tab = tab.substring(0, tab.length()-1); |
174 |
LineString lineString = new LineString();
|
175 |
lineString.setX(x); |
176 |
lineString.setY(y); |
177 |
lineString.setZ(z); |
178 |
lineString.setId(id); |
179 |
lineString.setSrs(srs); |
180 |
currentFeature.setGeometry(lineString); |
181 |
return lineString;
|
182 |
} |
183 |
|
184 |
public void endLineString(Object line) { |
185 |
System.out.print(tab + "End LineString:\n"); |
186 |
} |
187 |
|
188 |
public Object startPolygon(double[] x, double[] y, double[] z, String id, |
189 |
String srs) {
|
190 |
System.out.print(tab + "Start Polygon, SRS:" + srs + "\n"); |
191 |
tab = tab + "\t";
|
192 |
for (int i=0 ; i<x.length ; i++){ |
193 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
194 |
} |
195 |
tab = tab.substring(0, tab.length()-1); |
196 |
Polygon polygon = new Polygon(); |
197 |
polygon.setX(x); |
198 |
polygon.setY(y); |
199 |
polygon.setZ(z); |
200 |
polygon.setId(id); |
201 |
polygon.setSrs(srs); |
202 |
currentFeature.setGeometry(polygon); |
203 |
return polygon;
|
204 |
} |
205 |
|
206 |
public void endPolygon(Object polygon) { |
207 |
System.out.print(tab + "End Polygon\n"); |
208 |
} |
209 |
|
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
* @see org.gvsig.gpe.IGPEContentHandler#startInnerPolygon(java.lang.Object, double[], double[], double[], java.lang.String, java.lang.String)
|
213 |
*/
|
214 |
public Object startInnerPolygon(Object polygon, double[] x, double[] y, double[] z, String id, String srs){ |
215 |
tab = tab + "\t";
|
216 |
System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n"); |
217 |
tab = tab + "\t";
|
218 |
for (int i=0 ; i<x.length ; i++){ |
219 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
220 |
} |
221 |
tab = tab.substring(0, tab.length()-2); |
222 |
Polygon inner = new Polygon(); |
223 |
inner.setX(x); |
224 |
inner.setY(y); |
225 |
inner.setZ(z); |
226 |
inner.setId(id); |
227 |
inner.setSrs(srs); |
228 |
((Polygon)polygon).addInnerBoundary(inner);
|
229 |
return polygon;
|
230 |
} |
231 |
|
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
* @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object)
|
235 |
*/
|
236 |
public void endInnerPolygon(Object polygon){ |
237 |
tab = tab + "\t";
|
238 |
System.out.print(tab + "End InnerPolygon\n"); |
239 |
tab = tab.substring(0, tab.length()-1); |
240 |
} |
241 |
|
242 |
|
243 |
public boolean isViewInBox(Object bbox, Object view) { |
244 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
245 |
return false; |
246 |
} |
247 |
|
248 |
public boolean isGeometryInBox(Object bbox, Object geometry) { |
249 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
250 |
return false; |
251 |
} |
252 |
|
253 |
public Object startFeature(String name, String id) { |
254 |
System.out.print(tab + "Start Feature: " + name + "\n"); |
255 |
Feature feature = new Feature();
|
256 |
feature.setName(name); |
257 |
feature.setId(id); |
258 |
currentLayer.addFeature(feature); |
259 |
currentFeature = feature; |
260 |
return feature;
|
261 |
} |
262 |
|
263 |
public void addNameToFeature(Object feature, String name){ |
264 |
System.out.print(tab + "Feature name changed: " + name + "\n"); |
265 |
((Feature)feature).setName(name); |
266 |
} |
267 |
|
268 |
public void endFeature(Object feature) { |
269 |
System.out.print(tab + "End Feature\n"); |
270 |
} |
271 |
|
272 |
/**
|
273 |
* @return the layers
|
274 |
*/
|
275 |
public ArrayList getLayers() { |
276 |
return layers;
|
277 |
} |
278 |
|
279 |
} |
280 |
|