Revision 11247
trunk/libraries/libGPE/src-test/org/gvsig/gpe/writers/GPEWriterBaseTest.java | ||
---|---|---|
60 | 60 |
* |
61 | 61 |
* $Id$ |
62 | 62 |
* $Log$ |
63 |
* Revision 1.3 2007-04-17 06:27:20 jorpiell |
|
63 |
* Revision 1.4 2007-04-19 07:23:20 jorpiell |
|
64 |
* Add the add methods to teh contenhandler and change the register mode |
|
65 |
* |
|
66 |
* Revision 1.3 2007/04/17 06:27:20 jorpiell |
|
64 | 67 |
* Changed the default filename |
65 | 68 |
* |
66 | 69 |
* Revision 1.2 2007/04/14 16:06:35 jorpiell |
... | ... | |
80 | 83 |
*/ |
81 | 84 |
public abstract class GPEWriterBaseTest extends TestCase{ |
82 | 85 |
private String filename = "testdata/FILETEMP"; |
83 |
private GPEWriterHandler handler = null;
|
|
86 |
private GPEWriterHandler writerHandler = null;
|
|
84 | 87 |
private GPEContentHandler contenHandler = null; |
85 | 88 |
private GPEErrorHandler errorHandler = null; |
86 | 89 |
private GPEParser parser = null; |
... | ... | |
91 | 94 |
*/ |
92 | 95 |
public void setUp() throws Exception{ |
93 | 96 |
GPEDefaults.setProperty(GPEDefaults.DEFAULT_FILE_NAME, filename); |
94 |
GPERegister.addGpeDriver(getGPEParserName(), |
|
95 |
new GPEContentHandlerTest(), |
|
96 |
new GPEErrorHandlerTest()); |
|
97 |
handler = GPERegister.getWriter(getFormat()); |
|
97 |
//Register the parser |
|
98 |
GPERegister.addGpeParser(getGPEParserName(), |
|
99 |
getGPEParserDescription(), |
|
100 |
getGPEParserClass()); |
|
101 |
//Register the writer |
|
102 |
GPERegister.addGpeWriterHandler(getGPEWriterHandlerName(), |
|
103 |
getGPEWriterHandlerDescription(), |
|
104 |
getGPEWriterHandlerClass()); |
|
98 | 105 |
} |
99 | 106 |
|
100 | 107 |
/** |
... | ... | |
112 | 119 |
*/ |
113 | 120 |
public void testWriter() throws Exception{ |
114 | 121 |
writeObjects(); |
115 |
File outputFile = handler.getFile(); |
|
116 |
parser = GPERegister.getParser(outputFile); |
|
117 |
parser.parse(outputFile); |
|
122 |
File outputFile = writerHandler.getOutputFile(); |
|
123 |
//The file must exist |
|
124 |
parser = GPERegister.createParser(outputFile); |
|
125 |
parser.parse(getContenHandler(),getErrorHandler() ,outputFile); |
|
118 | 126 |
readObjects(); |
119 | 127 |
} |
120 | 128 |
|
121 | 129 |
/** |
122 |
* Gets the file format |
|
123 |
* @return |
|
124 |
*/ |
|
125 |
public abstract String getFormat(); |
|
126 |
|
|
127 |
/** |
|
128 | 130 |
* This method write somo objects into the writer handler |
129 | 131 |
*/ |
130 | 132 |
public abstract void writeObjects(); |
... | ... | |
140 | 142 |
* to register it before to start the parsing |
141 | 143 |
* process |
142 | 144 |
*/ |
143 |
public abstract String getGPEParserName(); |
|
145 |
public String getGPEWriterHandlerName(){ |
|
146 |
return "FORMAT VERSION"; |
|
147 |
} |
|
144 | 148 |
|
145 | 149 |
/** |
150 |
* Each test must to return its parser description |
|
151 |
* to register it before to start the parsing |
|
152 |
* process |
|
153 |
*/ |
|
154 |
public String getGPEWriterHandlerDescription(){ |
|
155 |
return "default writer handler description"; |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Each test must to return its parser class |
|
160 |
* that will be used to create new parsers. |
|
161 |
*/ |
|
162 |
public abstract Class getGPEWriterHandlerClass(); |
|
163 |
|
|
164 |
|
|
165 |
/** |
|
166 |
* Each test must to return its parser name |
|
167 |
* to register it before to start the parsing |
|
168 |
* process |
|
169 |
*/ |
|
170 |
public String getGPEParserName(){ |
|
171 |
return "FORMAT VERSION"; |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* Each test must to return its parser description |
|
176 |
* to register it before to start the parsing |
|
177 |
* process |
|
178 |
*/ |
|
179 |
public String getGPEParserDescription(){ |
|
180 |
return "default parser description"; |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Each test must to return its parser class |
|
185 |
* that will be used to create new parsers. |
|
186 |
*/ |
|
187 |
public abstract Class getGPEParserClass(); |
|
188 |
|
|
189 |
/** |
|
190 |
* Gets the file format. The deafult writer |
|
191 |
* format will be used by default |
|
192 |
* @return |
|
193 |
*/ |
|
194 |
public String getFormat(){ |
|
195 |
return null; |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Gets the file format. The deafult writer |
|
200 |
* version will be used by default |
|
201 |
* @return |
|
202 |
*/ |
|
203 |
public String getVersion(){ |
|
204 |
return null; |
|
205 |
} |
|
206 |
/** |
|
146 | 207 |
* It creates a Random bbox coordinates. It return |
147 | 208 |
* 10 coordinates |
148 | 209 |
* @return |
... | ... | |
205 | 266 |
* @return the handler |
206 | 267 |
*/ |
207 | 268 |
public GPEWriterHandler getWriterHandler() { |
208 |
return handler; |
|
269 |
if (writerHandler == null){ |
|
270 |
try { |
|
271 |
writerHandler = GPERegister.createWriter(getGPEWriterHandlerName()); |
|
272 |
writerHandler.setFormat(getFormat()); |
|
273 |
writerHandler.setVersion(getVersion()); |
|
274 |
writerHandler.setErrorHandler(getErrorHandler()); |
|
275 |
} catch (Exception e) { |
|
276 |
//never throwed |
|
277 |
e.printStackTrace(); |
|
278 |
} |
|
279 |
} |
|
280 |
return writerHandler; |
|
209 | 281 |
} |
210 | 282 |
|
211 | 283 |
/** |
trunk/libraries/libGPE/src-test/org/gvsig/gpe/writers/GPEPointsLayerTest.java | ||
---|---|---|
3 | 3 |
import java.io.File; |
4 | 4 |
|
5 | 5 |
import org.gvsig.gpe.GPEErrorHandler; |
6 |
import org.gvsig.gpe.containers.Element; |
|
7 |
import org.gvsig.gpe.containers.Feature; |
|
6 | 8 |
import org.gvsig.gpe.containers.Layer; |
7 | 9 |
|
8 | 10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
... | ... | |
49 | 51 |
* |
50 | 52 |
* $Id$ |
51 | 53 |
* $Log$ |
52 |
* Revision 1.2 2007-04-14 16:06:35 jorpiell |
|
54 |
* Revision 1.3 2007-04-19 07:23:20 jorpiell |
|
55 |
* Add the add methods to teh contenhandler and change the register mode |
|
56 |
* |
|
57 |
* Revision 1.2 2007/04/14 16:06:35 jorpiell |
|
53 | 58 |
* Add the container classes |
54 | 59 |
* |
55 | 60 |
* Revision 1.1 2007/04/13 07:17:54 jorpiell |
... | ... | |
61 | 66 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
62 | 67 |
*/ |
63 | 68 |
public abstract class GPEPointsLayerTest extends GPEWriterBaseTest { |
69 |
private String layerId = "l1"; |
|
64 | 70 |
private String layerName = "Points Layer"; |
65 | 71 |
private String layerDescription = "This is a test of a points layer"; |
72 |
private double[] bboxX = generateRandomBBox(); |
|
73 |
private double[] bboxY = generateRandomBBox(); |
|
74 |
private double[] bboxZ = generateRandomBBox(); |
|
75 |
private String feature1Name = "New York"; |
|
76 |
private String feature1Id = "f1"; |
|
77 |
private String element1 = "POPULATION"; |
|
66 | 78 |
|
67 | 79 |
/* |
68 | 80 |
* (non-Javadoc) |
... | ... | |
75 | 87 |
Layer layer = layers[0]; |
76 | 88 |
assertEquals(layer.getName(),layerName); |
77 | 89 |
assertEquals(layer.getDescription(),layerDescription); |
90 |
// assertEquals(layer.getId(),layerId); |
|
91 |
// assertEquals(layer.getBbox().getX(),bboxX); |
|
92 |
// assertEquals(layer.getBbox().getY(),bboxY); |
|
93 |
// assertEquals(layer.getBbox().getZ(),bboxZ); |
|
94 |
assertEquals(layer.getFeatures().size(), 2); |
|
95 |
Feature feature1 = (Feature)layer.getFeatures().get(0); |
|
96 |
// assertEquals(feature1.getId(), feature1Id); |
|
97 |
assertEquals(feature1.getName(), feature1Name); |
|
98 |
Element element11 = (Element)feature1.getElements().get(0); |
|
78 | 99 |
} |
79 | 100 |
|
80 | 101 |
/* |
... | ... | |
83 | 104 |
*/ |
84 | 105 |
public void writeObjects() { |
85 | 106 |
getWriterHandler().initialize(); |
86 |
getWriterHandler().startLayer("1", layerName, layerDescription, "23030");
|
|
87 |
getWriterHandler().startBbox("bbox", generateRandomBBox(),
|
|
88 |
generateRandomBBox(),
|
|
89 |
generateRandomBBox(),
|
|
107 |
getWriterHandler().startLayer(layerId, layerName, layerDescription, "23030");
|
|
108 |
getWriterHandler().startBbox("bbox", bboxX,
|
|
109 |
bboxY,
|
|
110 |
bboxZ,
|
|
90 | 111 |
"23030"); |
91 | 112 |
getWriterHandler().endBbox(); |
92 |
getWriterHandler().startFeature("New York","1");
|
|
113 |
getWriterHandler().startFeature(feature1Name,feature1Id);
|
|
93 | 114 |
getWriterHandler().startElement("POPULATION", new Integer("300000"), Integer.class); |
94 | 115 |
getWriterHandler().endElement(); |
95 | 116 |
getWriterHandler().startPoint("p1", 2, 2, 2, "EPSG:23030"); |
trunk/libraries/libGPE/src-test/org/gvsig/gpe/GPEErrorHandlerTest.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.3 2007-04-17 07:53:55 jorpiell |
|
46 |
* Revision 1.4 2007-04-19 07:23:20 jorpiell |
|
47 |
* Add the add methods to teh contenhandler and change the register mode |
|
48 |
* |
|
49 |
* Revision 1.3 2007/04/17 07:53:55 jorpiell |
|
47 | 50 |
* Before to start a new parsing process, the initialize method of the content handlers is throwed |
48 | 51 |
* |
49 | 52 |
* Revision 1.2 2007/04/13 13:14:55 jorpiell |
... | ... | |
58 | 61 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
59 | 62 |
*/ |
60 | 63 |
public class GPEErrorHandlerTest extends GPEErrorHandler{ |
61 |
public Object badLayer(String error, Object layer) { |
|
62 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
63 |
return null; |
|
64 |
} |
|
65 |
|
|
66 |
public Object badElement(String error, Object element) { |
|
67 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
68 |
return null; |
|
69 |
} |
|
70 |
|
|
71 |
public Object badArea(String error, Object bBox) { |
|
72 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
73 |
return null; |
|
74 |
} |
|
75 |
|
|
76 |
public Object badGeometry(String error, Object geometry) { |
|
77 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
78 |
return null; |
|
79 |
} |
|
80 |
|
|
81 |
public Object badFeature(String error, Object feature) { |
|
82 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
83 |
return null; |
|
84 |
} |
|
85 |
|
|
64 |
/* |
|
65 |
* (non-Javadoc) |
|
66 |
* @see org.gvsig.gpe.IGPEErrorHandler#addError(java.lang.Throwable) |
|
67 |
*/ |
|
86 | 68 |
public void addError(Throwable e) { |
87 | 69 |
e.printStackTrace(); |
70 |
|
|
88 | 71 |
} |
89 |
|
|
72 |
|
|
90 | 73 |
/* |
91 | 74 |
* (non-Javadoc) |
92 |
* @see org.gvsig.gpe.GPEContentHandler#initialize()
|
|
75 |
* @see org.gvsig.gpe.IGPEErrorHandler#addWarning(java.lang.Throwable)
|
|
93 | 76 |
*/ |
94 |
public void initialize(){ |
|
95 |
|
|
77 |
public void addWarning(Throwable e) { |
|
78 |
// TODO Auto-generated method stub |
|
79 |
|
|
96 | 80 |
} |
81 |
|
|
97 | 82 |
} |
trunk/libraries/libGPE/src-test/org/gvsig/gpe/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 |
|
trunk/libraries/libGPE/src-test/org/gvsig/gpe/containers/Feature.java | ||
---|---|---|
46 | 46 |
* |
47 | 47 |
* $Id$ |
48 | 48 |
* $Log$ |
49 |
* Revision 1.1 2007-04-14 16:06:35 jorpiell |
|
49 |
* Revision 1.2 2007-04-19 07:23:20 jorpiell |
|
50 |
* Add the add methods to teh contenhandler and change the register mode |
|
51 |
* |
|
52 |
* Revision 1.1 2007/04/14 16:06:35 jorpiell |
|
50 | 53 |
* Add the container classes |
51 | 54 |
* |
52 | 55 |
* |
... | ... | |
71 | 74 |
public void setGeometry(Geometry geometry) { |
72 | 75 |
this.geometry = geometry; |
73 | 76 |
} |
77 |
|
|
74 | 78 |
/** |
79 |
* @param geometry the geometry to set |
|
80 |
*/ |
|
81 |
public void setGeometry(Object geometry) { |
|
82 |
if (geometry instanceof Geometry){ |
|
83 |
this.geometry = (Geometry)geometry; |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
75 | 88 |
* @return the id |
76 | 89 |
*/ |
77 | 90 |
public String getId() { |
... | ... | |
110 | 123 |
elements.add(element); |
111 | 124 |
} |
112 | 125 |
|
126 |
/** |
|
127 |
* Adds a new element |
|
128 |
* @param layer |
|
129 |
*/ |
|
130 |
public void addElement(Object element){ |
|
131 |
if (element instanceof Element){ |
|
132 |
elements.add(element); |
|
133 |
} |
|
134 |
} |
|
113 | 135 |
} |
trunk/libraries/libGPE/src-test/org/gvsig/gpe/containers/Geometry.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.1 2007-04-14 16:06:35 jorpiell |
|
46 |
* Revision 1.2 2007-04-19 07:23:20 jorpiell |
|
47 |
* Add the add methods to teh contenhandler and change the register mode |
|
48 |
* |
|
49 |
* Revision 1.1 2007/04/14 16:06:35 jorpiell |
|
47 | 50 |
* Add the container classes |
48 | 51 |
* |
49 | 52 |
* |
... | ... | |
53 | 56 |
*/ |
54 | 57 |
public class Geometry { |
55 | 58 |
private String id = null; |
59 |
private Bbox bbox = null; |
|
56 | 60 |
|
57 | 61 |
/** |
62 |
* @return the bbox |
|
63 |
*/ |
|
64 |
public Bbox getBbox() { |
|
65 |
return bbox; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @param bbox the bbox to set |
|
70 |
*/ |
|
71 |
public void setBbox(Bbox bbox) { |
|
72 |
this.bbox = bbox; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* @param bbox the bbox to set |
|
77 |
*/ |
|
78 |
public void setBbox(Object bbox) { |
|
79 |
if (bbox instanceof Bbox){ |
|
80 |
this.bbox = (Bbox)bbox; |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
58 | 85 |
* @return the id |
59 | 86 |
*/ |
60 | 87 |
public String getId() { |
trunk/libraries/libGPE/src-test/org/gvsig/gpe/containers/Layer.java | ||
---|---|---|
46 | 46 |
* |
47 | 47 |
* $Id$ |
48 | 48 |
* $Log$ |
49 |
* Revision 1.1 2007-04-14 16:06:35 jorpiell |
|
49 |
* Revision 1.2 2007-04-19 07:23:20 jorpiell |
|
50 |
* Add the add methods to teh contenhandler and change the register mode |
|
51 |
* |
|
52 |
* Revision 1.1 2007/04/14 16:06:35 jorpiell |
|
50 | 53 |
* Add the container classes |
51 | 54 |
* |
52 | 55 |
* |
... | ... | |
153 | 156 |
public void addFeature(Feature feature){ |
154 | 157 |
features.add(feature); |
155 | 158 |
} |
159 |
|
|
160 |
/** |
|
161 |
* Adds a new layer |
|
162 |
* @param layer |
|
163 |
*/ |
|
164 |
public void addFeature(Object feature){ |
|
165 |
if (feature instanceof Feature){ |
|
166 |
features.add(feature); |
|
167 |
} |
|
168 |
} |
|
156 | 169 |
|
157 | 170 |
/** |
158 | 171 |
* @return the parentLayer |
trunk/libraries/libGPE/src-test/org/gvsig/gpe/containers/Polygon.java | ||
---|---|---|
46 | 46 |
* |
47 | 47 |
* $Id$ |
48 | 48 |
* $Log$ |
49 |
* Revision 1.1 2007-04-14 16:06:35 jorpiell |
|
49 |
* Revision 1.2 2007-04-19 07:23:20 jorpiell |
|
50 |
* Add the add methods to teh contenhandler and change the register mode |
|
51 |
* |
|
52 |
* Revision 1.1 2007/04/14 16:06:35 jorpiell |
|
50 | 53 |
* Add the container classes |
51 | 54 |
* |
52 | 55 |
* |
... | ... | |
77 | 80 |
} |
78 | 81 |
|
79 | 82 |
/** |
83 |
* Adds a new layer |
|
84 |
* @param layer |
|
85 |
*/ |
|
86 |
public void addInnerBoundary(Object polygon){ |
|
87 |
if (polygon instanceof Polygon){ |
|
88 |
innerBoundary.add(polygon); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
/** |
|
80 | 94 |
* @return the srs |
81 | 95 |
*/ |
82 | 96 |
public String getSrs() { |
trunk/libraries/libGPE/src-test/org/gvsig/gpe/readers/GPEReaderBaseTest.java | ||
---|---|---|
4 | 4 |
import java.lang.reflect.InvocationTargetException; |
5 | 5 |
import java.util.ArrayList; |
6 | 6 |
|
7 |
import org.gvsig.gpe.GPEContentHandler; |
|
7 | 8 |
import org.gvsig.gpe.GPEContentHandlerTest; |
9 |
import org.gvsig.gpe.GPEErrorHandler; |
|
8 | 10 |
import org.gvsig.gpe.GPEErrorHandlerTest; |
9 | 11 |
import org.gvsig.gpe.GPEParser; |
10 | 12 |
import org.gvsig.gpe.GPERegister; |
... | ... | |
56 | 58 |
* |
57 | 59 |
* $Id$ |
58 | 60 |
* $Log$ |
59 |
* Revision 1.3 2007-04-14 16:06:35 jorpiell |
|
61 |
* Revision 1.4 2007-04-19 07:23:20 jorpiell |
|
62 |
* Add the add methods to teh contenhandler and change the register mode |
|
63 |
* |
|
64 |
* Revision 1.3 2007/04/14 16:06:35 jorpiell |
|
60 | 65 |
* Add the container classes |
61 | 66 |
* |
62 | 67 |
* Revision 1.2 2007/04/13 13:14:55 jorpiell |
... | ... | |
75 | 80 |
public abstract class GPEReaderBaseTest extends TestCase { |
76 | 81 |
private File file = null; |
77 | 82 |
private GPEParser parser = null; |
83 |
private GPEContentHandler contenHandler = null; |
|
84 |
private GPEErrorHandler errorHandler = null; |
|
78 | 85 |
|
79 | 86 |
public void setUp() throws Exception{ |
80 |
GPERegister.addGpeDriver(getGPEParserName(), |
|
81 |
new GPEContentHandlerTest(), |
|
82 |
new GPEErrorHandlerTest()); |
|
87 |
//Register the parser |
|
88 |
GPERegister.addGpeParser(getGPEParserName(), |
|
89 |
getGPEParserDescription(), |
|
90 |
getGPEParserClass()); |
|
83 | 91 |
file = new File(getFile()); |
84 | 92 |
assertEquals(GPERegister.accept(file),true); |
85 |
parser = GPERegister.getParser(file);
|
|
93 |
parser = GPERegister.createParser(getGPEParserName());
|
|
86 | 94 |
assertNotNull(parser); |
87 | 95 |
} |
88 | 96 |
|
... | ... | |
92 | 100 |
* @throws Exception |
93 | 101 |
*/ |
94 | 102 |
public void testParse() throws Exception{ |
95 |
parser.parse(file); |
|
103 |
parser.parse(getContenHandler() , getErrorHandler(), file);
|
|
96 | 104 |
makeAsserts(); |
97 | 105 |
} |
98 | 106 |
|
... | ... | |
108 | 116 |
* to register it before to start the parsing |
109 | 117 |
* process |
110 | 118 |
*/ |
111 |
public abstract String getGPEParserName(); |
|
119 |
public String getGPEParserName(){ |
|
120 |
return "FORMAT VERSION"; |
|
121 |
} |
|
112 | 122 |
|
113 | 123 |
/** |
124 |
* Each test must to return its parser description |
|
125 |
* to register it before to start the parsing |
|
126 |
* process |
|
127 |
*/ |
|
128 |
public String getGPEParserDescription(){ |
|
129 |
return "default parser description"; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Each test must to return its parser class |
|
134 |
* that will be used to create new parsers. |
|
135 |
*/ |
|
136 |
public abstract Class getGPEParserClass(); |
|
137 |
|
|
138 |
/** |
|
114 | 139 |
* Gets the GML file to open |
115 | 140 |
* @return |
116 | 141 |
*/ |
... | ... | |
129 | 154 |
return aLayers; |
130 | 155 |
} |
131 | 156 |
|
157 |
/** |
|
158 |
* @return the contenHandler |
|
159 |
*/ |
|
160 |
public GPEContentHandler getContenHandler() { |
|
161 |
if (contenHandler == null){ |
|
162 |
contenHandler = new GPEContentHandlerTest(); |
|
163 |
} |
|
164 |
return contenHandler; |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* @return the errorHandler |
|
169 |
*/ |
|
170 |
public GPEErrorHandler getErrorHandler() { |
|
171 |
if (errorHandler == null){ |
|
172 |
errorHandler = new GPEErrorHandlerTest(); |
|
173 |
} |
|
174 |
return errorHandler; |
|
175 |
} |
|
176 |
|
|
132 | 177 |
} |
trunk/libraries/libGPE/src/org/gvsig/gpe/GPEContentHandler.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.9 2007-04-18 12:48:16 jorpiell |
|
46 |
* Revision 1.10 2007-04-19 07:23:20 jorpiell |
|
47 |
* Add the add methods to teh contenhandler and change the register mode |
|
48 |
* |
|
49 |
* Revision 1.9 2007/04/18 12:48:16 jorpiell |
|
47 | 50 |
* The ID attribute is always on the first position |
48 | 51 |
* |
49 | 52 |
* Revision 1.8 2007/04/18 10:46:23 jorpiell |
... | ... | |
77 | 80 |
*/ |
78 | 81 |
public abstract class GPEContentHandler implements IGPEContentHandler { |
79 | 82 |
|
80 |
/** |
|
81 |
* It initializes the ContentHandler. It thas to |
|
82 |
* init the object attributes values before to |
|
83 |
* start a new parsing process. |
|
84 |
*/ |
|
85 |
abstract public void initialize(); |
|
83 |
public void addBboxToGeometry(Object bbox, Object geometry) { |
|
84 |
// TODO Auto-generated method stub |
|
85 |
|
|
86 |
} |
|
86 | 87 |
|
87 |
public void addDescriptionToLayer(String description) {
|
|
88 |
public void addBboxToLayer(Object bbox, Object layer) {
|
|
88 | 89 |
// TODO Auto-generated method stub |
89 | 90 |
|
90 | 91 |
} |
91 | 92 |
|
92 |
public void addNameToFeature(String name) {
|
|
93 |
public void addDescriptionToLayer(String description, Object layer) {
|
|
93 | 94 |
// TODO Auto-generated method stub |
94 | 95 |
|
95 | 96 |
} |
96 | 97 |
|
97 |
public void addNameToLayer(String name) {
|
|
98 |
public void addElementToFeature(Object element, Object feature) {
|
|
98 | 99 |
// TODO Auto-generated method stub |
99 | 100 |
|
100 | 101 |
} |
101 | 102 |
|
103 |
public void addFeatureToLayer(Object feature, Object layer) { |
|
104 |
// TODO Auto-generated method stub |
|
105 |
|
|
106 |
} |
|
107 |
|
|
108 |
public void addGeometryToFeature(Object geometry, Object feature) { |
|
109 |
// TODO Auto-generated method stub |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
public void addInnerPolygonToPolygon(Object innerPolygon, Object Polygon) { |
|
114 |
// TODO Auto-generated method stub |
|
115 |
|
|
116 |
} |
|
117 |
|
|
118 |
public void addNameToFeature(String name, Object feature) { |
|
119 |
// TODO Auto-generated method stub |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
public void addNameToLayer(String name, Object layer) { |
|
124 |
// TODO Auto-generated method stub |
|
125 |
|
|
126 |
} |
|
127 |
|
|
128 |
public void addParentElementToElement(Object parent, Object element) { |
|
129 |
// TODO Auto-generated method stub |
|
130 |
|
|
131 |
} |
|
132 |
|
|
133 |
public void addParentLayerToLayer(Object parent, Object layer) { |
|
134 |
// TODO Auto-generated method stub |
|
135 |
|
|
136 |
} |
|
137 |
|
|
138 |
public void addSrsToLayer(String srs, Object Layer) { |
|
139 |
// TODO Auto-generated method stub |
|
140 |
|
|
141 |
} |
|
142 |
|
|
102 | 143 |
public void endBbox(Object bbox) { |
103 | 144 |
// TODO Auto-generated method stub |
104 | 145 |
|
105 | 146 |
} |
106 | 147 |
|
107 |
public void endElement() { |
|
148 |
public void endElement(Object element) {
|
|
108 | 149 |
// TODO Auto-generated method stub |
109 | 150 |
|
110 | 151 |
} |
111 | 152 |
|
112 |
public void endFeature() { |
|
153 |
public void endFeature(Object feature) {
|
|
113 | 154 |
// TODO Auto-generated method stub |
114 | 155 |
|
115 | 156 |
} |
116 | 157 |
|
117 |
public void endInnerPolygon() { |
|
158 |
public void endInnerPolygon(Object innerPolygon) {
|
|
118 | 159 |
// TODO Auto-generated method stub |
119 | 160 |
|
120 | 161 |
} |
121 | 162 |
|
122 |
public void endLayer() { |
|
163 |
public void endLayer(Object layer) {
|
|
123 | 164 |
// TODO Auto-generated method stub |
124 | 165 |
|
125 | 166 |
} |
126 | 167 |
|
127 |
public void endLineString() { |
|
168 |
public void endLineString(Object lineString) {
|
|
128 | 169 |
// TODO Auto-generated method stub |
129 | 170 |
|
130 | 171 |
} |
131 | 172 |
|
132 |
public void endLinearRing() { |
|
173 |
public void endLinearRing(Object linearRing) {
|
|
133 | 174 |
// TODO Auto-generated method stub |
134 | 175 |
|
135 | 176 |
} |
136 | 177 |
|
137 |
public void endPoint() { |
|
178 |
public void endPoint(Object point) {
|
|
138 | 179 |
// TODO Auto-generated method stub |
139 | 180 |
|
140 | 181 |
} |
141 | 182 |
|
142 |
public void endPolygon() { |
|
183 |
public void endPolygon(Object Polygon) {
|
|
143 | 184 |
// TODO Auto-generated method stub |
144 | 185 |
|
145 | 186 |
} |
... | ... | |
149 | 190 |
return null; |
150 | 191 |
} |
151 | 192 |
|
152 |
public Object startElement(String name, Object value, Object type) { |
|
193 |
public Object startElement(String name, Object value, Object type, Object parentElement) {
|
|
153 | 194 |
// TODO Auto-generated method stub |
154 | 195 |
return null; |
155 | 196 |
} |
156 | 197 |
|
157 |
public Object startFeature(String id, String name) { |
|
198 |
public Object startFeature(String id, String name, Object layer) {
|
|
158 | 199 |
// TODO Auto-generated method stub |
159 | 200 |
return null; |
160 | 201 |
} |
... | ... | |
164 | 205 |
return null; |
165 | 206 |
} |
166 | 207 |
|
167 |
public Object startLayer(String id, String name, String description, String srs) { |
|
208 |
public Object startLayer(String id, String name, String description, String srs, Object parentLayer, Object bBox) {
|
|
168 | 209 |
// TODO Auto-generated method stub |
169 | 210 |
return null; |
170 | 211 |
} |
... | ... | |
189 | 230 |
return null; |
190 | 231 |
} |
191 | 232 |
|
233 |
|
|
192 | 234 |
|
193 | 235 |
|
236 |
|
|
194 | 237 |
|
195 | 238 |
|
196 | 239 |
|
trunk/libraries/libGPE/src/org/gvsig/gpe/GPEParser.java | ||
---|---|---|
50 | 50 |
* |
51 | 51 |
* $Id$ |
52 | 52 |
* $Log$ |
53 |
* Revision 1.7 2007-04-14 16:06:13 jorpiell |
|
53 |
* Revision 1.8 2007-04-19 07:23:20 jorpiell |
|
54 |
* Add the add methods to teh contenhandler and change the register mode |
|
55 |
* |
|
56 |
* Revision 1.7 2007/04/14 16:06:13 jorpiell |
|
54 | 57 |
* The writer handler has been updated |
55 | 58 |
* |
56 | 59 |
* Revision 1.6 2007/04/13 07:17:54 jorpiell |
... | ... | |
81 | 84 |
public abstract class GPEParser { |
82 | 85 |
private GPEErrorHandler errorHandler; |
83 | 86 |
private GPEContentHandler contentHandler; |
84 |
private File parserFile = null; |
|
85 |
private Object prueba; |
|
86 | 87 |
|
87 | 88 |
/** |
88 |
* |
|
89 |
* AQUI SE IMPLEMENTA LA BASE PARA PODER PARSEAR CUALQUIER FICHERO: |
|
90 |
* -COMPROBAR SI EXISTE |
|
91 |
* -COMPROBAR CODIFICACI?N DEL XML |
|
92 |
* -ABRIR EN MODO LECTURA CON LA CODIFICACI?N CORRECTA |
|
93 |
* -CREAR EL PARSER DE XML ?"XSOM"? |
|
94 |
* -DETECTAR FORMATO FICHERO Y VERSI?N ?"EST? REGISTRADO"? |
|
95 |
* -SI EXISTE, LLAMADA AL PARSER DEL FORMATO CONCRETO |
|
96 |
* |
|
89 |
* All the GPE parser must implement a constructor without |
|
90 |
* arguments. |
|
97 | 91 |
**/ |
98 |
public GPEParser(GPEContentHandler contents, GPEErrorHandler errors){ |
|
99 |
this.contentHandler = contents; |
|
100 |
this.errorHandler=errors; |
|
92 |
public GPEParser(){ |
|
93 |
|
|
101 | 94 |
} |
102 | 95 |
|
103 |
|
|
104 |
public void parse(File file) throws Exception{ |
|
105 |
|
|
106 |
// /***** para lectura en modo texto ****/ |
|
107 |
// GPEXMLReader.open(); |
|
108 |
// FileReader reader = null; |
|
109 |
// try { |
|
110 |
// reader = new FileReader(this.parserFile); |
|
111 |
// } catch (FileNotFoundException e) { |
|
112 |
// // TODO llamada a ??GPEErrorHandler?? para tratar la excepci?n o lanzamos desde aqu? |
|
113 |
// // Fichero no existe. |
|
114 |
// } |
|
115 |
// BufferedReader br = new BufferedReader(reader); |
|
116 |
// char[] buffer = new char[100]; |
|
117 |
// try { |
|
118 |
// br.read(buffer); |
|
119 |
// } catch (IOException e) { |
|
120 |
// // TODO llamada a ??GPEErrorHandler?? para tratar la excepci?n o lanzamos desde aqu? |
|
121 |
// // Error de lectura del buffer |
|
122 |
// } |
|
123 |
// StringBuffer st = new StringBuffer(new String(buffer)); |
|
124 |
// |
|
125 |
// // We find the encoding at the begining of the file |
|
126 |
// |
|
127 |
// String searchText = "encoding=\""; |
|
128 |
// int index = st.indexOf(searchText); |
|
129 |
// |
|
130 |
// // If it find the encoding, it takes the new encoding, else it takes the default encoding "UTF-8" |
|
131 |
// if (index>-1) { |
|
132 |
// st.delete(0, index+searchText.length()); |
|
133 |
// encoding = st.substring(0, st.indexOf("\"")); |
|
134 |
// } |
|
135 |
// |
|
136 |
// // make GML parser with the good enconding |
|
137 |
// XMLSchemaParser parser = new XMLSchemaParser(); |
|
138 |
// |
|
139 |
// // setImput(file,encoding): it sets the encoding to read with the KXML parser |
|
140 |
// try { |
|
141 |
// parser.setInput(new FileInputStream(m_File), encoding); |
|
142 |
// } catch (FileNotFoundException e) { |
|
143 |
// // TODO Auto-generated catch block |
|
144 |
// throw new GMLException(m_File.getName(),e); |
|
145 |
// } catch (XmlPullParserException e) { |
|
146 |
// // TODO Auto-generated catch block |
|
147 |
// throw new GMLException(m_File.getName(),e); |
|
148 |
// } |
|
149 |
// return parser; |
|
150 |
|
|
96 |
/** |
|
97 |
* Method to parse a file. It have to be implemented by all |
|
98 |
* the GPE Parsers. It cannot to throw any exception and it |
|
99 |
* cannot to return any value. In a future it could be |
|
100 |
* implemented like a independent thread |
|
101 |
* @param contents |
|
102 |
* Application ContentHandler |
|
103 |
* @param errors |
|
104 |
* Application ErrorsHandler |
|
105 |
* @param file |
|
106 |
* File to open |
|
107 |
* @throws Exception |
|
108 |
*/ |
|
109 |
public void parse(GPEContentHandler contents, GPEErrorHandler errors, File file) { |
|
110 |
this.contentHandler = contents; |
|
111 |
this.errorHandler = errors; |
|
151 | 112 |
} |
152 | 113 |
|
153 | 114 |
/** |
... | ... | |
165 | 126 |
* @return |
166 | 127 |
*/ |
167 | 128 |
public abstract String[] getFormats(); |
168 |
|
|
129 |
|
|
169 | 130 |
/** |
170 |
* Gets the writer that will be used for the consumer |
|
171 |
* application to create the outputformat |
|
172 |
* @param format |
|
173 |
* Format to create the file |
|
174 |
* @throws FileNotFoundException |
|
175 |
* If the file doesn't exist |
|
131 |
* Return an array with all the versions that the driver |
|
132 |
* is able to read/write |
|
133 |
* @return |
|
176 | 134 |
*/ |
177 |
public abstract GPEWriterHandler getWriter(String format);
|
|
135 |
public abstract String[] getVersions();
|
|
178 | 136 |
|
179 | 137 |
/** |
180 | 138 |
* @return the contentHandler |
trunk/libraries/libGPE/src/org/gvsig/gpe/IGPEErrorHandler.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.2 2007-04-12 17:06:42 jorpiell |
|
46 |
* Revision 1.3 2007-04-19 07:23:20 jorpiell |
|
47 |
* Add the add methods to teh contenhandler and change the register mode |
|
48 |
* |
|
49 |
* Revision 1.2 2007/04/12 17:06:42 jorpiell |
|
47 | 50 |
* First GML writing tests |
48 | 51 |
* |
49 | 52 |
* Revision 1.1 2007/04/11 08:46:21 csanchez |
... | ... | |
56 | 59 |
*/ |
57 | 60 |
public interface IGPEErrorHandler { |
58 | 61 |
|
59 |
public Object badLayer(String error, Object layer); |
|
60 |
|
|
61 |
public Object badElement(String error, Object element); |
|
62 |
|
|
63 |
public Object badArea(String error, Object bBox); |
|
64 |
|
|
65 |
public Object badGeometry(String error, Object geometry); |
|
66 |
|
|
67 |
public Object badFeature(String error, Object feature); |
|
68 |
|
|
69 | 62 |
public void addError(Throwable e); |
70 | 63 |
|
64 |
public void addWarning(Throwable e); |
|
65 |
|
|
71 | 66 |
} |
trunk/libraries/libGPE/src/org/gvsig/gpe/IGPEContentHandler.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
public interface IGPEContentHandler { |
7 | 7 |
|
8 |
//Bbox |
|
9 |
public Object startBbox(String id, double[] x, double[] y, double[] z, String srs); |
|
10 |
|
|
11 |
public void endBbox(Object bbox); |
|
12 |
|
|
8 | 13 |
//Layer |
9 |
public Object startLayer(String id, String name, String description, String srs); |
|
14 |
public Object startLayer(String id, String name, String description, |
|
15 |
String srs, Object parentLayer, Object bBox); |
|
10 | 16 |
|
11 |
public void endLayer(); |
|
17 |
public void endLayer(Object layer);
|
|
12 | 18 |
|
13 |
public void addNameToLayer(String name); |
|
19 |
public void addNameToLayer(String name, Object layer);
|
|
14 | 20 |
|
15 |
public void addDescriptionToLayer(String description); |
|
21 |
public void addDescriptionToLayer(String description, Object layer);
|
|
16 | 22 |
|
23 |
public void addSrsToLayer(String srs, Object Layer); |
|
24 |
|
|
25 |
public void addParentLayerToLayer(Object parent, Object layer); |
|
26 |
|
|
27 |
public void addBboxToLayer(Object bbox, Object layer); |
|
28 |
|
|
17 | 29 |
//Feature |
18 |
public Object startFeature(String id, String name); |
|
30 |
public Object startFeature(String id, String name, Object layer);
|
|
19 | 31 |
|
20 |
public void endFeature(); |
|
32 |
public void endFeature(Object feature);
|
|
21 | 33 |
|
22 |
public void addNameToFeature(String name); |
|
23 |
|
|
34 |
public void addNameToFeature(String name, Object feature); |
|
35 |
|
|
36 |
public void addFeatureToLayer(Object feature, Object layer); |
|
37 |
|
|
24 | 38 |
//Element |
25 |
public Object startElement(String name, Object value, Object type); |
|
39 |
public Object startElement(String name, Object value, Object type, Object parentElement);
|
|
26 | 40 |
|
27 |
public void endElement(); |
|
41 |
public void endElement(Object element);
|
|
28 | 42 |
|
29 |
//Bbox |
|
30 |
public Object startBbox(String id, double[] x, double[] y, double[] z, String srs); |
|
43 |
public void addParentElementToElement(Object parent, Object element); |
|
31 | 44 |
|
32 |
public void endBbox(Object bbox);
|
|
45 |
public void addElementToFeature(Object element, Object feature);
|
|
33 | 46 |
|
34 | 47 |
//Geometries |
35 | 48 |
public Object startPoint(String id, double x, double y, double z, String srs); |
36 | 49 |
|
37 |
public void endPoint(); |
|
50 |
public void endPoint(Object point);
|
|
38 | 51 |
|
39 | 52 |
public Object startLineString( String id, double[] x, double[] y, double[] z, String srs); |
40 | 53 |
|
41 |
public void endLineString(); |
|
54 |
public void endLineString(Object lineString);
|
|
42 | 55 |
|
43 | 56 |
public Object startLinearRing(String id, double[] x, double[] y, double[] z, String srs); |
44 | 57 |
|
45 |
public void endLinearRing(); |
|
58 |
public void endLinearRing(Object linearRing);
|
|
46 | 59 |
|
47 | 60 |
public Object startPolygon(String id, double[] x, double[] y, double[] z, String srs); |
48 | 61 |
|
49 |
public void endPolygon(); |
|
62 |
public void endPolygon(Object Polygon);
|
|
50 | 63 |
|
51 |
public Object startInnerPolygon( String id, double[] x, double[] y, double[] z, String srs);
|
|
64 |
public void addInnerPolygonToPolygon(Object innerPolygon, Object Polygon);
|
|
52 | 65 |
|
53 |
public void endInnerPolygon(); |
|
54 |
|
|
66 |
public Object startInnerPolygon(String id, double[] x, double[] y, double[] z, String srs); |
|
67 |
|
|
68 |
public void endInnerPolygon(Object innerPolygon); |
|
69 |
|
|
70 |
public void addBboxToGeometry(Object bbox, Object geometry); |
|
71 |
|
|
72 |
public void addGeometryToFeature(Object geometry, Object feature); |
|
55 | 73 |
} |
trunk/libraries/libGPE/src/org/gvsig/gpe/writers/GPEWriterHandler.java | ||
---|---|---|
51 | 51 |
* |
52 | 52 |
* $Id$ |
53 | 53 |
* $Log$ |
54 |
* Revision 1.3 2007-04-14 16:06:13 jorpiell |
|
54 |
* Revision 1.4 2007-04-19 07:23:20 jorpiell |
|
55 |
* Add the add methods to teh contenhandler and change the register mode |
|
56 |
* |
|
57 |
* Revision 1.3 2007/04/14 16:06:13 jorpiell |
|
55 | 58 |
* The writer handler has been updated |
56 | 59 |
* |
57 | 60 |
* Revision 1.2 2007/04/13 13:14:55 jorpiell |
... | ... | |
73 | 76 |
*/ |
74 | 77 |
public abstract class GPEWriterHandler implements IGPEWriterHandler{ |
75 | 78 |
private String format = null; |
79 |
private String version = null; |
|
76 | 80 |
private String fileName = null; |
77 |
private File file = null;
|
|
81 |
private File outputFile = null;
|
|
78 | 82 |
private GPEErrorHandler errorHandler = null; |
79 | 83 |
|
80 |
public GPEWriterHandler(String format, GPEErrorHandler errorHandler){ |
|
81 |
this.format = format; |
|
82 |
this.errorHandler = errorHandler; |
|
84 |
public GPEWriterHandler(){ |
|
85 |
|
|
83 | 86 |
} |
84 | 87 |
|
85 | 88 |
/** |
89 |
* Gets the deafult writting version |
|
90 |
* @return |
|
91 |
*/ |
|
92 |
public abstract String getDefaultVersion(); |
|
93 |
|
|
94 |
/** |
|
95 |
* Gets the deafult format |
|
96 |
* @return |
|
97 |
*/ |
|
98 |
public abstract String getDefaultFormat(); |
|
99 |
|
|
100 |
/** |
|
101 |
* Creates the output file and |
|
102 |
* @return the file |
|
103 |
*/ |
|
104 |
public File getOutputFile() { |
|
105 |
if (outputFile == null){ |
|
106 |
if (fileName == null){ |
|
107 |
fileName = GPEDefaults.getProperty(GPEDefaults.DEFAULT_FILE_NAME); |
|
108 |
} |
|
109 |
//TODO If the file ends with the format... |
|
110 |
outputFile = new File(fileName + "." + getFormat().toLowerCase()); |
|
111 |
} |
|
112 |
return outputFile; |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
/** |
|
86 | 117 |
* @return the errorHandler |
87 | 118 |
*/ |
88 | 119 |
public GPEErrorHandler getErrorHandler() { |
89 | 120 |
return errorHandler; |
90 | 121 |
} |
91 | 122 |
|
123 |
/** |
|
124 |
* @param errorHandler the errorHandler to set |
|
125 |
*/ |
|
126 |
public void setErrorHandler(GPEErrorHandler errorHandler) { |
|
127 |
this.errorHandler = errorHandler; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* @return the fileName |
|
132 |
*/ |
|
133 |
public String getFileName() { |
|
134 |
return fileName; |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* @param fileName the fileName to set |
|
139 |
*/ |
|
140 |
public void setFileName(String fileName) { |
|
141 |
this.fileName = fileName; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* @return the format |
|
146 |
*/ |
|
147 |
public String getFormat() { |
Also available in: Unified diff