Changeset 918
- Timestamp:
- 08/12/08 16:19:36 (3 months ago)
- Files:
-
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/pom.xml (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfFeature.java (modified) (3 diffs)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfFeatureCollection.java (modified) (3 diffs)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeo.java (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeoFactory.java (added)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeoJSONReader.java (added)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeoJSONWriter.java (moved) (moved from sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeoJSON.java) (11 diffs)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeometry.java (modified) (3 diffs)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfFeatureCollectionTest.java (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfFeatureTest.java (modified) (2 diffs)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfGeoJSONReaderTest.java (added)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfGeoJSONWriterTest.java (moved) (moved from sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfGeoJSONTest.java) (15 diffs)
- sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfGeometryTest.java (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/server/java/print/print-lib/pom.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/pom.xml
r916 r918 106 106 </dependency> 107 107 <dependency> 108 <groupId>net.sf.json-lib</groupId> 109 <artifactId>json-lib</artifactId> 110 <version>2.2</version> 111 <classifier>jdk15</classifier> 108 <groupId>org.json</groupId> 109 <artifactId>json</artifactId> 110 <version>20080701</version> 112 111 </dependency> 113 112 <dependency> sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfFeature.java
r279 r918 18 18 */ 19 19 20 /*21 * MfFeature.java22 *23 * Created on January 21, 2008, 8:43 PM24 *25 * To change this template, choose Tools | Template Manager26 * and open the template in the editor.27 */28 29 20 package org.mapfish.geo; 30 21 31 import net.sf.json.util.JSONBuilder; 22 import org.json.JSONWriter; 23 import org.json.JSONException; 32 24 33 25 /** … … 36 28 */ 37 29 public abstract class MfFeature implements MfGeo { 38 private final GeoType geoType;39 40 30 /** 41 31 * Creates a new instance of MfFeature 42 32 */ 43 33 protected MfFeature() { 44 geoType = GeoType.FEATURE;45 34 } 46 35 47 36 public GeoType getGeoType() { 48 return geoType;37 return GeoType.FEATURE; 49 38 } 50 39 … … 57 46 * Add the "key" and "value" pairs to the provided builder. 58 47 */ 59 public abstract void toJSON(JSON Builder builder);48 public abstract void toJSON(JSONWriter builder) throws JSONException; 60 49 } sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfFeatureCollection.java
r279 r918 18 18 */ 19 19 20 /*21 * MfFeatureCollection.java22 *23 * Created on January 21, 2008, 8:56 PM24 *25 * To change this template, choose Tools | Template Manager26 * and open the template in the editor.27 */28 29 20 package org.mapfish.geo; 30 21 … … 36 27 */ 37 28 public class MfFeatureCollection implements MfGeo { 38 private final GeoType geoType;39 29 private final Collection<MfFeature> collection; 40 30 … … 43 33 */ 44 34 public MfFeatureCollection(Collection<MfFeature> collection) { 45 this.geoType = GeoType.FEATURECOLLECTION;46 35 this.collection = collection; 47 36 } 48 37 49 38 public GeoType getGeoType() { 50 return geoType;39 return GeoType.FEATURECOLLECTION; 51 40 } 52 41 sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeo.java
r279 r918 18 18 */ 19 19 20 /*21 * MfGeo.java22 *23 * Created on January 21, 2008, 8:02 PM24 *25 * To change this template, choose Tools | Template Manager26 * and open the template in the editor.27 */28 29 20 package org.mapfish.geo; 30 21 31 22 /** 23 * Base class for GeoJSON objects 32 24 * 33 25 * @author Eric Lemoine, Camptocamp. sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeoJSONWriter.java
r424 r918 40 40 import com.vividsolutions.jts.geom.Point; 41 41 import com.vividsolutions.jts.geom.Polygon; 42 import net.sf.json.JSONException;43 import net.sf.json.util.JSONBuilder;42 import org.json.JSONException; 43 import org.json.JSONWriter; 44 44 45 45 import java.util.Iterator; … … 47 47 48 48 /** 49 * This class is coded against the draft 5 versionof the spec49 * This class is coded against the version 1.0 of the spec 50 50 * on http://geojson.org. 51 51 * … … 59 59 * 60 60 */ 61 public class MfGeoJSON {62 private final JSON Builder builder;63 64 public MfGeoJSON (JSONBuilder builder) {61 public class MfGeoJSONWriter { 62 private final JSONWriter builder; 63 64 public MfGeoJSONWriter(JSONWriter builder) { 65 65 this.builder = builder; 66 66 } 67 68 public void encode(MfGeo o) {67 68 public void encode(MfGeo o) throws JSONException { 69 69 switch (o.getGeoType()) { 70 70 case FEATURE: … … 84 84 } 85 85 } 86 86 87 87 public void encodeFeatureCollection(MfFeatureCollection c) throws JSONException { 88 88 builder.object(); … … 90 90 builder.key("features"); 91 91 builder.array(); 92 92 93 93 Iterator<MfFeature> i = c.getCollection().iterator(); 94 94 while (i.hasNext()) { … … 96 96 encodeFeature(f); 97 97 } 98 99 builder.endArray(); 100 builder.endObject(); 101 } 102 98 99 builder.endArray(); 100 builder.endObject(); 101 } 102 103 103 public void encodeFeature(MfFeature f) throws JSONException { 104 104 builder.object(); … … 106 106 builder.key("id").value(f.getFeatureId()); 107 107 builder.key("geometry"); 108 108 109 109 Geometry g; 110 110 MfGeometry mfg; … … 115 115 builder.value(null); 116 116 } 117 117 118 118 builder.key("properties"); 119 119 builder.object(); … … 171 171 encodeGeomCollection((GeometryCollection) g); 172 172 } 173 174 builder.endObject(); 175 } 176 177 private void encodeGeomCollection(GeometryCollection collection) {173 174 builder.endObject(); 175 } 176 177 private void encodeGeomCollection(GeometryCollection collection) throws JSONException { 178 178 builder.array(); 179 179 builder.key("geometries"); … … 203 203 } 204 204 205 private void encodeCoordinate(Coordinate coord) {205 private void encodeCoordinate(Coordinate coord) throws JSONException { 206 206 builder.array(); 207 207 builder.value(coord.x); … … 214 214 * @param env envelope representing bounding box 215 215 */ 216 protected void encodeBoundingBox(Envelope env) {216 protected void encodeBoundingBox(Envelope env) throws JSONException { 217 217 builder.key("bbox"); 218 218 builder.array(); sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/main/java/org/mapfish/geo/MfGeometry.java
r279 r918 18 18 */ 19 19 20 /*21 * MfGeometry.java22 *23 * Created on January 21, 2008, 8:13 PM24 *25 * To change this template, choose Tools | Template Manager26 * and open the template in the editor.27 */28 29 20 package org.mapfish.geo; 30 21 … … 36 27 */ 37 28 public class MfGeometry implements MfGeo { 38 private final GeoType geoType;39 29 private final Geometry jtsGeometry; 40 30 … … 43 33 */ 44 34 public MfGeometry(Geometry jtsGeometry) { 45 this.geoType = GeoType.GEOMETRY;46 35 this.jtsGeometry = jtsGeometry; 47 36 } 48 37 49 38 public GeoType getGeoType() { 50 return geoType;39 return GeoType.GEOMETRY; 51 40 } 52 41 sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfFeatureCollectionTest.java
r279 r918 1 /* 2 * Copyright (C) 2008 Camptocamp 3 * 4 * This file is part of MapFish 5 * 6 * MapFish is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * MapFish is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with MapFish. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 20 package org.mapfish.geo; 2 21 22 import junit.framework.TestCase; 23 3 24 import java.util.LinkedList; 4 5 import junit.framework.Test;6 import junit.framework.TestCase;7 import junit.framework.TestSuite;8 9 import net.sf.json.util.JSONBuilder;10 25 11 26 /** sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfFeatureTest.java
r279 r918 1 /* 2 * Copyright (C) 2008 Camptocamp 3 * 4 * This file is part of MapFish 5 * 6 * MapFish is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * MapFish is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with MapFish. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 20 package org.mapfish.geo; 2 21 3 import junit.framework.Test;4 22 import junit.framework.TestCase; 5 import junit.framework.TestSuite;6 23 7 import net.sf.json.util.JSONBuilder;24 import org.json.JSONWriter; 8 25 9 26 /** … … 28 45 public String getFeatureId() { return null; } 29 46 public MfGeometry getMfGeometry() { return null; } 30 public void toJSON(JSON Builder builder) {}47 public void toJSON(JSONWriter builder) {} 31 48 32 49 }; sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfGeoJSONWriterTest.java
r424 r918 1 /* 2 * Copyright (C) 2008 Camptocamp 3 * 4 * This file is part of MapFish 5 * 6 * MapFish is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * MapFish is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with MapFish. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 20 package org.mapfish.geo; 2 21 22 import com.vividsolutions.jts.geom.Coordinate; 23 import com.vividsolutions.jts.geom.Geometry; 24 import com.vividsolutions.jts.geom.GeometryFactory; 25 import com.vividsolutions.jts.geom.LinearRing; 26 import junit.framework.TestCase; 27 import org.json.JSONStringer; 28 import org.json.JSONWriter; 29 import org.json.JSONException; 30 3 31 import java.util.LinkedList; 4 5 import junit.framework.Test;6 import junit.framework.TestCase;7 import junit.framework.TestSuite;8 9 import net.sf.json.util.JSONBuilder;10 import net.sf.json.util.JSONStringer;11 12 import com.vividsolutions.jts.geom.Geometry;13 import com.vividsolutions.jts.geom.LinearRing;14 import com.vividsolutions.jts.geom.GeometryFactory;15 import com.vividsolutions.jts.geom.Coordinate;16 32 17 33 /** 18 34 * Unit test for MfGeoJSON. 19 35 */ 20 public class MfGeoJSON Test extends TestCase36 public class MfGeoJSONWriterTest extends TestCase 21 37 { 22 38 /** … … 25 41 * @param testName name of the test case 26 42 */ 27 public MfGeoJSON Test(String testName) {43 public MfGeoJSONWriterTest(String testName) { 28 44 super(testName); 29 45 } … … 32 48 * Test. 33 49 */ 34 public void testMfGeoJSON() {50 public void testMfGeoJSON() throws JSONException { 35 51 JSONStringer stringer; 36 MfGeoJSON builder;52 MfGeoJSONWriter builder; 37 53 38 54 Geometry g; … … 51 67 // encodeGeometry POINT test 52 68 stringer = new JSONStringer(); 53 builder = new MfGeoJSON (stringer);69 builder = new MfGeoJSONWriter(stringer); 54 70 g = new GeometryFactory().createPoint(coord1); 55 71 geojsonExpected = … … 61 77 // encodeGeometry LINESTRING test 62 78 stringer = new JSONStringer(); 63 builder = new MfGeoJSON (stringer);79 builder = new MfGeoJSONWriter(stringer); 64 80 Coordinate[] coordArrayLS = {coord1, coord2}; 65 81 g = new GeometryFactory().createLineString(coordArrayLS); … … 72 88 // encodeGeometry POLYGON test 73 89 stringer = new JSONStringer(); 74 builder = new MfGeoJSON (stringer);90 builder = new MfGeoJSONWriter(stringer); 75 91 Coordinate[] coordArrayLR = {coord1, coord2, coord3, coord1}; 76 92 LinearRing lr = new GeometryFactory().createLinearRing(coordArrayLR); … … 84 100 // encodeFeature test 85 101 stringer = new JSONStringer(); 86 builder = new MfGeoJSON (stringer);102 builder = new MfGeoJSONWriter(stringer); 87 103 f1 = new MfFeature() { 88 104 public String getFeatureId() { … … 93 109 new GeometryFactory().createPoint(coord1)); 94 110 } 95 public void toJSON(JSON Builder builder){111 public void toJSON(JSONWriter builder) throws JSONException { 96 112 builder.key("prop_foo").value("foo"); 97 113 } … … 105 121 // encodeFeature test with null internal geometry 106 122 stringer = new JSONStringer(); 107 builder = new MfGeoJSON (stringer);123 builder = new MfGeoJSONWriter(stringer); 108 124 f1 = new MfFeature() { 109 125 public String getFeatureId() { … … 113 129 return new MfGeometry(null); 114 130 } 115 public void toJSON(JSON Builder builder){131 public void toJSON(JSONWriter builder) throws JSONException { 116 132 builder.key("prop_foo").value("foo"); 117 133 } … … 125 141 // encodeFeature test with null geometry 126 142 stringer = new JSONStringer(); 127 builder = new MfGeoJSON (stringer);143 builder = new MfGeoJSONWriter(stringer); 128 144 f1 = new MfFeature() { 129 145 public String getFeatureId() { … … 133 149 return null; 134 150 } 135 public void toJSON(JSON Builder builder){151 public void toJSON(JSONWriter builder) throws JSONException { 136 152 builder.key("prop_foo").value("foo"); 137 153 } … … 144 160 // encodeFeatureCollection test 145 161 stringer = new JSONStringer(); 146 builder = new MfGeoJSON (stringer);162 builder = new MfGeoJSONWriter(stringer); 147 163 f1 = new MfFeature() { 148 164 public String getFeatureId() { … … 153 169 new GeometryFactory().createPoint(coord1)); 154 170 } 155 public void toJSON(JSON Builder builder){171 public void toJSON(JSONWriter builder) throws JSONException { 156 172 builder.key("prop_foo").value("foo"); 157 173 } … … 165 181 new GeometryFactory().createPoint(coord2)); 166 182 } 167 public void toJSON(JSON Builder builder){183 public void toJSON(JSONWriter builder) throws JSONException { 168 184 builder.key("prop_bar").value("bar"); 169 185 } sandbox/camptocamp/MapFishUnhcr/server/java/mapfish-geo-lib/src/test/java/org/mapfish/geo/MfGeometryTest.java
r279 r918 1 /* 2 * Copyright (C) 2008 Camptocamp 3 * 4 * This file is part of MapFish 5 * 6 * MapFish is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * MapFish is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with MapFish. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 20 package org.mapfish.geo; 2 21 3 import java.util.LinkedList; 4 5 import junit.framework.Test; 6 import junit.framework.TestCase; 7 import junit.framework.TestSuite; 8 22 import com.vividsolutions.jts.geom.Coordinate; 9 23 import com.vividsolutions.jts.geom.Geometry; 10 24 import com.vividsolutions.jts.geom.GeometryFactory; 11 import com.vividsolutions.jts.geom.Coordinate;25 import junit.framework.TestCase; 12 26 13 27 /** sandbox/camptocamp/MapFishUnhcr/server/java/print/print-lib/pom.xml
r911 r918 74 74 <groupId>org.json</groupId> 75 75 <artifactId>json</artifactId> 76 <version>200 70829</version>76 <version>20080701</version> 77 77 </dependency> 78 78 <dependency>