Revision 11247 trunk/libraries/libGPE/src-test/org/gvsig/gpe/GPEContentHandlerTest.java
GPEContentHandlerTest.java | ||
---|---|---|
5 | 5 |
import org.gvsig.gpe.containers.Feature; |
6 | 6 |
import org.gvsig.gpe.containers.Bbox; |
7 | 7 |
import org.gvsig.gpe.containers.Element; |
8 |
import org.gvsig.gpe.containers.Geometry; |
|
8 | 9 |
import org.gvsig.gpe.containers.Layer; |
9 | 10 |
import org.gvsig.gpe.containers.LineString; |
10 | 11 |
import org.gvsig.gpe.containers.Point; |
... | ... | |
54 | 55 |
* |
55 | 56 |
* $Id$ |
56 | 57 |
* $Log$ |
57 |
* Revision 1.4 2007-04-17 07:53:55 jorpiell |
|
58 |
* Revision 1.5 2007-04-19 07:23:20 jorpiell |
|
59 |
* Add the add methods to teh contenhandler and change the register mode |
|
60 |
* |
|
61 |
* Revision 1.4 2007/04/17 07:53:55 jorpiell |
|
58 | 62 |
* Before to start a new parsing process, the initialize method of the content handlers is throwed |
59 | 63 |
* |
60 | 64 |
* Revision 1.3 2007/04/14 16:06:35 jorpiell |
... | ... | |
73 | 77 |
*/ |
74 | 78 |
public class GPEContentHandlerTest extends GPEContentHandler{ |
75 | 79 |
private String tab = ""; |
76 |
private Layer currentLayer = null; |
|
77 |
private Feature currentFeature = null; |
|
78 | 80 |
private ArrayList layers = new ArrayList(); |
79 |
|
|
80 |
public Object startLayer(Object parent, Object bBox, String id, |
|
81 |
String name, String description,String srs) { |
|
82 |
System.out.print(tab + "Start Layer: " + name + "\n"); |
|
83 |
tab = tab + "\t"; |
|
84 |
Layer layer = new Layer(); |
|
85 |
layer.setParentLayer(parent); |
|
86 |
layer.setBbox(bBox); |
|
87 |
layer.setId(id); |
|
88 |
layer.setName(name); |
|
89 |
layer.setDescription(description); |
|
90 |
layer.setSrs(srs); |
|
91 |
currentLayer = layer; |
|
92 |
return layer; |
|
81 |
|
|
82 |
/** |
|
83 |
* @return the layers |
|
84 |
*/ |
|
85 |
public ArrayList getLayers() { |
|
86 |
return layers; |
|
93 | 87 |
} |
94 | 88 |
|
95 |
public void endLayer(Object layer) { |
|
96 |
tab = tab.substring(0, tab.length()-1); |
|
97 |
System.out.print(tab + "End Layer\n"); |
|
98 |
if (currentLayer != null){ |
|
99 |
if (currentLayer.getParentLayer() == null){ |
|
100 |
layers.add(currentLayer); |
|
101 |
} |
|
102 |
currentLayer = currentLayer.getParentLayer(); |
|
103 |
} |
|
89 |
public Object startFeature(String name, String id) { |
|
90 |
System.out.print(tab + "Start Feature: " + name + "\n"); |
|
91 |
Feature feature = new Feature(); |
|
92 |
feature.setName(name); |
|
93 |
feature.setId(id); |
|
94 |
return feature; |
|
104 | 95 |
} |
105 | 96 |
|
106 |
public void addNameToLayer(Object layer,String name){
|
|
107 |
System.out.print(tab + "Layer name changed: " + name + "\n");
|
|
108 |
((Layer)layer).setName(name);
|
|
97 |
public void addNameToFeature(Object feature, String name){
|
|
98 |
System.out.print(tab + "Feature name changed: " + name + "\n");
|
|
99 |
((Feature)feature).setName(name);
|
|
109 | 100 |
} |
110 |
|
|
111 |
public void addDescriptionToLayer(Object layer,String description){ |
|
101 |
|
|
102 |
public void endFeature(Object feature) { |
|
103 |
System.out.print(tab + "End Feature\n"); |
|
104 |
} |
|
105 |
|
|
106 |
public void initialize(){ |
|
107 |
layers = new ArrayList(); |
|
108 |
} |
|
109 |
|
|
110 |
public void addBboxToGeometry(Object bbox, Object geometry) { |
|
111 |
((Geometry)geometry).setBbox(bbox); |
|
112 |
|
|
113 |
} |
|
114 |
|
|
115 |
public void addBboxToLayer(Object bbox, Object layer) { |
|
116 |
((Layer)layer).setBbox(bbox); |
|
117 |
|
|
118 |
} |
|
119 |
|
|
120 |
public void addDescriptionToLayer(String description, Object layer) { |
|
112 | 121 |
System.out.print(tab + "Layer description changed: " + description + "\n"); |
113 | 122 |
((Layer)layer).setDescription(description); |
114 |
} |
|
115 |
|
|
116 |
public Object startElement(Object parent, String name, Object value, |
|
117 |
Object type) { |
|
118 |
Element element = new Element(); |
|
119 |
element.setParentElement(parent); |
|
120 |
element.setName(name); |
|
121 |
element.setValue(value); |
|
122 |
element.setType(type); |
|
123 |
if (parent == null){ |
|
124 |
currentFeature.addElement(element); |
|
125 |
} |
|
126 |
return element; |
|
127 | 123 |
} |
128 | 124 |
|
129 |
public void endElement(Object element) { |
|
130 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
125 |
public void addElementToFeature(Object element, Object feature) { |
|
126 |
((Feature)feature).addElement(element); |
|
127 |
} |
|
131 | 128 |
|
129 |
public void addFeatureToLayer(Object feature, Object layer) { |
|
130 |
((Layer)layer).addFeature(feature); |
|
131 |
|
|
132 | 132 |
} |
133 | 133 |
|
134 |
public Object startBbox(double[] x, double[] y, double[] z, String id, |
|
135 |
String srs) { |
|
134 |
public void addGeometryToFeature(Object geometry, Object feature) { |
|
135 |
((Feature)feature).setGeometry(geometry); |
|
136 |
|
|
137 |
} |
|
138 |
|
|
139 |
public void addInnerPolygonToPolygon(Object innerPolygon, Object polygon) { |
|
140 |
((Polygon)polygon).addInnerBoundary(innerPolygon); |
|
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
public void addNameToFeature(String name, Object feature) { |
|
145 |
((Feature)feature).setName(name); |
|
146 |
|
|
147 |
} |
|
148 |
|
|
149 |
public void addNameToLayer(String name, Object layer) { |
|
150 |
System.out.print(tab + "Layer name changed: " + name + "\n"); |
|
151 |
((Layer)layer).setName(name); |
|
152 |
} |
|
153 |
|
|
154 |
public void addParentElementToElement(Object parent, Object element) { |
|
155 |
((Element)element).setParentElement(parent); |
|
156 |
|
|
157 |
} |
|
158 |
|
|
159 |
public void addParentLayerToLayer(Object parent, Object layer) { |
|
160 |
((Layer)layer).setParentLayer(parent); |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
public void addSrsToLayer(String srs, Object layer) { |
|
165 |
((Layer)layer).setSrs(srs); |
|
166 |
|
|
167 |
} |
|
168 |
|
|
169 |
|
|
170 |
public Object startBbox(String id, double[] x, double[] y, double[] z, String srs) { |
|
136 | 171 |
Bbox bbox = new Bbox(); |
137 | 172 |
bbox.setX(x); |
138 | 173 |
bbox.setY(y); |
... | ... | |
144 | 179 |
|
145 | 180 |
public void endBbox(Object bbox) { |
146 | 181 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
182 |
} |
|
147 | 183 |
|
184 |
public Object startElement(String name, Object value, Object type, Object parentElement) { |
|
185 |
Element element = new Element(); |
|
186 |
element.setParentElement(parentElement); |
|
187 |
element.setName(name); |
|
188 |
element.setValue(value); |
|
189 |
element.setType(type); |
|
190 |
return element; |
|
148 | 191 |
} |
149 | 192 |
|
150 |
public Object startPoint(double x, double y, double z, String id, String srs) { |
|
151 |
System.out.print(tab + "Start Point, SRS:" + srs + "\n"); |
|
193 |
public void endElement(Object element) { |
|
194 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
195 |
|
|
196 |
} |
|
197 |
|
|
198 |
public Object startFeature(String id, String name, Object layer) { |
|
199 |
// TODO Auto-generated method stub |
|
200 |
return null; |
|
201 |
} |
|
202 |
|
|
203 |
public Object startInnerPolygon(String id, double[] x, double[] y, double[] z, String srs) { |
|
152 | 204 |
tab = tab + "\t"; |
153 |
System.out.print(tab + x + "," + y + "," + z + "\n"); |
|
205 |
System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n"); |
|
206 |
tab = tab + "\t"; |
|
207 |
for (int i=0 ; i<x.length ; i++){ |
|
208 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
|
209 |
} |
|
210 |
tab = tab.substring(0, tab.length()-2); |
|
211 |
Polygon inner = new Polygon(); |
|
212 |
inner.setX(x); |
|
213 |
inner.setY(y); |
|
214 |
inner.setZ(z); |
|
215 |
inner.setId(id); |
|
216 |
inner.setSrs(srs); |
|
217 |
return inner; |
|
218 |
} |
|
219 |
|
|
220 |
/* |
|
221 |
* (non-Javadoc) |
|
222 |
* @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object) |
|
223 |
*/ |
|
224 |
public void endInnerPolygon(Object polygon){ |
|
225 |
tab = tab + "\t"; |
|
226 |
System.out.print(tab + "End InnerPolygon\n"); |
|
154 | 227 |
tab = tab.substring(0, tab.length()-1); |
155 |
Point point = new Point(); |
|
156 |
point.setX(x); |
|
157 |
point.setY(y); |
|
158 |
point.setZ(z); |
|
159 |
point.setId(id); |
|
160 |
point.setSrs(srs); |
|
161 |
currentFeature.setGeometry(point); |
|
162 |
return point; |
|
163 | 228 |
} |
164 | 229 |
|
165 |
public void endPoint(Object point) { |
|
166 |
System.out.print(tab + "End Point\n"); |
|
230 |
|
|
231 |
public Object startLayer(String id, String name, String description, String srs, Object parentLayer, Object bBox) { |
|
232 |
System.out.print(tab + "Start Layer: " + name + "\n"); |
|
233 |
tab = tab + "\t"; |
|
234 |
Layer layer = new Layer(); |
|
235 |
layer.setId(id); |
|
236 |
layer.setName(name); |
|
237 |
layer.setDescription(description); |
|
238 |
layer.setSrs(srs); |
|
239 |
layer.setParentLayer(parentLayer); |
|
240 |
layer.setBbox(bBox); |
|
241 |
layers.add(layer); |
|
242 |
return layer; |
|
243 |
} |
|
244 |
|
|
245 |
public void endLayer(Object layer) { |
|
246 |
tab = tab.substring(0, tab.length()-1); |
|
247 |
System.out.print(tab + "End Layer\n"); |
|
167 | 248 |
} |
168 | 249 |
|
169 |
public Object startLineString(double[] x, double[] y, double[] z, String id, |
|
170 |
String srs) { |
|
250 |
public Object startLineString(String id, double[] x, double[] y, double[] z, String srs) { |
|
171 | 251 |
System.out.print(tab + "Start LineString, SRS:" + srs + "\n"); |
172 | 252 |
tab = tab + "\t"; |
173 | 253 |
for (int i=0 ; i<x.length ; i++){ |
... | ... | |
180 | 260 |
lineString.setZ(z); |
181 | 261 |
lineString.setId(id); |
182 | 262 |
lineString.setSrs(srs); |
183 |
currentFeature.setGeometry(lineString); |
|
184 | 263 |
return lineString; |
185 | 264 |
} |
186 | 265 |
|
... | ... | |
188 | 267 |
System.out.print(tab + "End LineString:\n"); |
189 | 268 |
} |
190 | 269 |
|
191 |
public Object startPolygon(double[] x, double[] y, double[] z, String id, |
|
192 |
String srs) { |
|
270 |
public Object startPoint(String id, double x, double y, double z, String srs) { |
|
271 |
System.out.print(tab + "Start Point, SRS:" + srs + "\n"); |
|
272 |
tab = tab + "\t"; |
|
273 |
System.out.print(tab + x + "," + y + "," + z + "\n"); |
|
274 |
tab = tab.substring(0, tab.length()-1); |
|
275 |
Point point = new Point(); |
|
276 |
point.setX(x); |
|
277 |
point.setY(y); |
|
278 |
point.setZ(z); |
|
279 |
point.setId(id); |
|
280 |
point.setSrs(srs); |
|
281 |
return point; |
|
282 |
} |
|
283 |
|
|
284 |
public void endPoint(Object point) { |
|
285 |
System.out.print(tab + "End Point\n"); |
|
286 |
} |
|
287 |
|
|
288 |
public Object startPolygon(String id, double[] x, double[] y, double[] z, String srs) { |
|
193 | 289 |
System.out.print(tab + "Start Polygon, SRS:" + srs + "\n"); |
194 | 290 |
tab = tab + "\t"; |
195 | 291 |
for (int i=0 ; i<x.length ; i++){ |
... | ... | |
202 | 298 |
polygon.setZ(z); |
203 | 299 |
polygon.setId(id); |
204 | 300 |
polygon.setSrs(srs); |
205 |
currentFeature.setGeometry(polygon); |
|
206 | 301 |
return polygon; |
207 | 302 |
} |
208 | 303 |
|
304 |
|
|
209 | 305 |
public void endPolygon(Object polygon) { |
210 | 306 |
System.out.print(tab + "End Polygon\n"); |
211 | 307 |
} |
212 | 308 |
|
213 |
/* |
|
214 |
* (non-Javadoc) |
|
215 |
* @see org.gvsig.gpe.IGPEContentHandler#startInnerPolygon(java.lang.Object, double[], double[], double[], java.lang.String, java.lang.String) |
|
216 |
*/ |
|
217 |
public Object startInnerPolygon(Object polygon, double[] x, double[] y, double[] z, String id, String srs){ |
|
218 |
tab = tab + "\t"; |
|
219 |
System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n"); |
|
220 |
tab = tab + "\t"; |
|
221 |
for (int i=0 ; i<x.length ; i++){ |
|
222 |
System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n"); |
|
223 |
} |
|
224 |
tab = tab.substring(0, tab.length()-2); |
|
225 |
Polygon inner = new Polygon(); |
|
226 |
inner.setX(x); |
|
227 |
inner.setY(y); |
|
228 |
inner.setZ(z); |
|
229 |
inner.setId(id); |
|
230 |
inner.setSrs(srs); |
|
231 |
((Polygon)polygon).addInnerBoundary(inner); |
|
232 |
return polygon; |
|
233 |
} |
|
234 |
|
|
235 |
/* |
|
236 |
* (non-Javadoc) |
|
237 |
* @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object) |
|
238 |
*/ |
|
239 |
public void endInnerPolygon(Object polygon){ |
|
240 |
tab = tab + "\t"; |
|
241 |
System.out.print(tab + "End InnerPolygon\n"); |
|
242 |
tab = tab.substring(0, tab.length()-1); |
|
243 |
} |
|
244 | 309 |
|
245 |
|
|
246 |
public boolean isViewInBox(Object bbox, Object view) { |
|
247 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
248 |
return false; |
|
310 |
public Object startLinearRing(String id, double[] x, double[] y, double[] z, String srs) { |
|
311 |
// TODO Auto-generated method stub |
|
312 |
return null; |
|
249 | 313 |
} |
250 | 314 |
|
251 |
public boolean isGeometryInBox(Object bbox, Object geometry) { |
|
252 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
253 |
return false; |
|
254 |
} |
|
255 | 315 |
|
256 |
public Object startFeature(String name, String id) { |
|
257 |
System.out.print(tab + "Start Feature: " + name + "\n"); |
|
258 |
Feature feature = new Feature(); |
|
259 |
feature.setName(name); |
|
260 |
feature.setId(id); |
|
261 |
currentLayer.addFeature(feature); |
|
262 |
currentFeature = feature; |
|
263 |
return feature; |
|
264 |
} |
|
265 |
|
|
266 |
public void addNameToFeature(Object feature, String name){ |
|
267 |
System.out.print(tab + "Feature name changed: " + name + "\n"); |
|
268 |
((Feature)feature).setName(name); |
|
269 |
} |
|
270 |
|
|
271 |
public void endFeature(Object feature) { |
|
272 |
System.out.print(tab + "End Feature\n"); |
|
273 |
} |
|
316 |
public void endLinearRing(Object linearRing) { |
|
317 |
// TODO Auto-generated method stub |
|
274 | 318 |
|
275 |
/** |
|
276 |
* @return the layers |
|
277 |
*/ |
|
278 |
public ArrayList getLayers() { |
|
279 |
return layers; |
|
280 | 319 |
} |
281 |
|
|
282 | 320 |
|
283 |
/* |
|
284 |
* (non-Javadoc) |
|
285 |
* @see org.gvsig.gpe.GPEContentHandler#initialize() |
|
286 |
*/ |
|
287 |
public void initialize(){ |
|
288 |
layers = new ArrayList(); |
|
289 |
currentFeature = null; |
|
290 |
} |
|
321 |
|
|
291 | 322 |
} |
292 | 323 |
|
Also available in: Unified diff