Changeset 96
- Timestamp:
- 07/20/2009 03:30:47 PM (4 years ago)
- Location:
- spatial.streams.kml/src
- Files:
-
- 8 edited
-
main/java/org/geospatial/kml/KMLFeature.java (modified) (1 diff)
-
main/java/sapience/features/streams/factories/KMLFactory.java (modified) (3 diffs)
-
test/java/sapience/features/streams/kml/TestAnnotatedSamples.java (modified) (1 diff)
-
test/java/sapience/features/streams/kml/TestEasy.java (modified) (1 diff)
-
test/java/sapience/features/streams/kml/TestMultipleStyles.java (modified) (2 diffs)
-
test/java/sapience/features/streams/kml/TestNestedFolders.java (modified) (2 diffs)
-
test/java/testing/Parser.java (modified) (1 diff)
-
test/resources/sapience/features/streams/kml/samples/NestedFolders.kml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
spatial.streams.kml/src/main/java/org/geospatial/kml/KMLFeature.java
r95 r96 36 36 @XStreamAlias("LookAt") 37 37 private LookAt lookAt; 38 39 38 40 39 @XStreamAlias("styleUrl") -
spatial.streams.kml/src/main/java/sapience/features/streams/factories/KMLFactory.java
r93 r96 19 19 import sapience.annotations.model.Description; 20 20 import sapience.annotations.model.KeyValueProperty; 21 import sapience.annotations.model.Name; 21 22 import sapience.annotations.model.contact.Address; 22 import sapience.annotations.model.contact.Name;23 23 import sapience.features.Feature; 24 24 import sapience.features.FeatureCollection; 25 import sapience.features.factories.FeatureFactory; 25 26 26 27 27 28 import com.vividsolutions.jts.geom.Geometry; 28 29 30 /** 31 * TODO: not finished 32 * 33 * Creates a {@link KML} object from a {@link FeatureCollection} 34 * 35 * @author pajoma 36 * 37 */ 29 38 public class KMLFactory { 30 39 … … 61 70 public KML buildKML(FeatureCollection coll) throws IOException { 62 71 kml = new KML(); 63 kml. addDocument((Document) populateContainer(new Document(), coll));72 kml.setFeature((Document) populateContainer(new Document(), coll)); 64 73 65 74 return kml; … … 81 90 if(fc.getAssociatedFeatureCollection() == null) { 82 91 Document doc = (Document) populateContainer(new Document(), fc); 83 kml. addDocument(doc);92 kml.setFeature(doc); 84 93 85 94 // now we have to find all containers which have this document as container -
spatial.streams.kml/src/test/java/sapience/features/streams/kml/TestAnnotatedSamples.java
r92 r96 8 8 import org.junit.Test; 9 9 10 import sapience.annotations.model. contact.Name;10 import sapience.annotations.model.Name; 11 11 import sapience.features.FeatureCollection; 12 12 import sapience.features.streams.Streams; -
spatial.streams.kml/src/test/java/sapience/features/streams/kml/TestEasy.java
r92 r96 1 1 package sapience.features.streams.kml; 2 2 3 import java.io.File; 3 import java.io.ByteArrayOutputStream; 4 import java.io.FileInputStream; 4 5 import java.io.IOException; 5 import java. util.List;6 import java.io.OutputStream; 6 7 7 import org.geospatial.kml.Document;8 import org.geospatial.kml.KML; 9 import org. geospatial.kml.KMLFeature;10 import org.junit. Assert;8 import junit.framework.Assert; 9 10 import org.apache.commons.io.IOUtils; 11 import org.junit.Before; 11 12 import org.junit.Test; 12 13 13 import sapience.features.Feature; 14 15 import sapience.annotations.model.Name; 14 16 import sapience.features.FeatureCollection; 15 17 import sapience.features.streams.Streams; 16 import sapience.features.streams.kml.KMLStream;17 18 18 19 public class TestEasy { 19 20 20 String file = "samples/easy.kml"; 21 String in = "samples/easy.kml"; 22 String out = "samples/easy.out.kml"; 21 23 22 @Test 23 public void parseEasy() throws IOException { 24 Streams s = new KMLStream(); 25 FeatureCollection res = s.read(this.getClass().getResourceAsStream(file)); 26 27 28 29 // KML kml = parser.start(); 30 // 31 // Assert.assertNotNull(kml); 32 // 33 // List<Document> documents = kml.getDocuments(); 34 // 35 // 36 // for(Document f : documents) { 37 // List<KMLFeature> l = f.listFeaturesRecursive(); 38 // System.out.println(l.size()); 39 // 40 // for(KMLFeature kf : l) { 41 // System.out.print(kf.getClass()); 42 // System.out.print(" :: "); 43 // System.out.println(kf.getName()); 44 // } 45 // } 24 private FeatureCollection res; 25 private Streams streams; 26 27 @Before 28 public void parse() throws IOException { 29 streams = new KMLStream(); 30 res = streams.read(this.getClass().getResourceAsStream(in)); 46 31 } 47 32 48 33 @Test 34 public void testNumberOfFeatures() throws IOException { 35 // number of features 36 Assert.assertEquals(6, res.listFeaturesRecursively().size()); 37 } 38 39 @Test 40 public void testAnnotation() { 41 // name of second folder 42 // we don't which one, but one of both has to (order can change) 43 String f0 = res.getFeature(0).getAnnotation(Name.class); 44 String f1 = res.getFeature(1).getAnnotation(Name.class); 45 Assert.assertTrue(f0.equalsIgnoreCase("Folder B") || f1.equalsIgnoreCase("Folder B")); 46 47 } 48 49 // test removed, will always fail, since the order of always changes (you have to 50 // check the content, not the XML 49 51 public void writeEasy() throws IOException { 50 Streams s = new KMLStream(); 51 FeatureCollection res = s.read(this.getClass().getResourceAsStream(file)); 52 s.write(res, System.out); 52 OutputStream os = new OutputStream() { 53 StringBuffer sb = new StringBuffer(); 54 @Override 55 public void write(int b) throws IOException { 56 sb.append((char) b); 57 } 58 59 public String toString() { 60 return sb.toString(); 61 } 62 }; 63 64 streams.write(res, os); 65 66 String expected = IOUtils.toString(this.getClass().getResourceAsStream(out)); 67 String actual = os.toString(); 68 69 System.out.println(expected.trim()); 70 System.out.println(actual.trim()); 71 53 72 } 73 54 74 } -
spatial.streams.kml/src/test/java/sapience/features/streams/kml/TestMultipleStyles.java
r95 r96 1 1 package sapience.features.streams.kml; 2 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 6 import org.geospatial.kml.Document; 7 import org.geospatial.kml.Folder; 8 import org.geospatial.kml.KML; 9 import org.geospatial.kml.KMLContainer; 10 import org.geospatial.kml.KMLFeature; 11 import org.geospatial.kml.Placemark; 12 import org.junit.Before; 3 13 import org.junit.Test; 14 15 import com.thoughtworks.xstream.XStream; 16 import com.thoughtworks.xstream.io.xml.QNameMap; 17 import com.thoughtworks.xstream.io.xml.StaxDriver; 4 18 5 19 import sapience.features.FeatureCollection; … … 8 22 public class TestMultipleStyles { 9 23 10 String name = "samples/MultipleStyles.kml";24 String file = "samples/MultipleStyles.kml"; 11 25 26 private XStream xstream; 27 28 @Before 29 public void prepareParser() { 30 QNameMap qnameMap = new QNameMap(); 31 qnameMap.setDefaultNamespace("http://www.example.com/"); 32 xstream = new XStream(new StaxDriver(qnameMap)); 33 new XStreamsConfiguration().configure(xstream); 34 35 36 } 12 37 13 38 @Test 14 public void parse() throws Exception { 15 Streams parser = new KMLStream(); 16 FeatureCollection kml = parser.read(this.getClass().getResourceAsStream(name)); 39 public void parse() throws IOException { 40 InputStream is = this.getClass().getResourceAsStream(file); 17 41 18 // should have two MapStyles 19 20 // should have three Style Definitions 21 parser.write(kml, System.out); 42 KML doc = (KML) xstream.fromXML(is); 43 44 System.out.println(xstream.toXML(doc)); 22 45 } 23 46 -
spatial.streams.kml/src/test/java/sapience/features/streams/kml/TestNestedFolders.java
r94 r96 2 2 3 3 import java.io.IOException; 4 import java.io.InputStream; 4 5 6 import org.geospatial.kml.Document; 7 import org.geospatial.kml.Folder; 8 import org.geospatial.kml.KML; 9 import org.geospatial.kml.KMLContainer; 10 import org.geospatial.kml.KMLFeature; 11 import org.geospatial.kml.Placemark; 12 import org.junit.Before; 5 13 import org.junit.Test; 14 15 import com.thoughtworks.xstream.XStream; 16 import com.thoughtworks.xstream.io.xml.QNameMap; 17 import com.thoughtworks.xstream.io.xml.StaxDriver; 6 18 7 19 import sapience.features.FeatureCollection; … … 11 23 12 24 String file = "samples/NestedFolders.kml"; 25 private XStream xstream; 13 26 27 @Before 28 public void prepareParser() { 29 QNameMap qnameMap = new QNameMap(); 30 qnameMap.setDefaultNamespace("http://www.example.com/"); 31 xstream = new XStream(new StaxDriver(qnameMap)); 32 this.configure(); 33 34 35 } 36 37 private void configure() { 38 xstream.processAnnotations(KML.class); 39 40 xstream.processAnnotations(KMLContainer.class); 41 xstream.processAnnotations(Document.class); 42 xstream.processAnnotations(Folder.class); 43 xstream.processAnnotations(KMLFeature.class); 44 xstream.processAnnotations(Placemark.class); 45 46 } 47 14 48 @Test 15 49 public void parse() throws IOException { 16 Streams s = new KMLStream(); 17 FeatureCollection res = s.read(this.getClass().getResourceAsStream(file)); 50 InputStream is = this.getClass().getResourceAsStream(file); 51 52 KML doc = (KML) xstream.fromXML(is); 53 54 System.out.println(xstream.toXML(doc)); 18 55 } 19 56 } -
spatial.streams.kml/src/test/java/testing/Parser.java
r95 r96 23 23 this.configure(); 24 24 25 InputStream is = this.getClass().getResourceAsStream(" example.xml");25 InputStream is = this.getClass().getResourceAsStream("Example.xml"); 26 26 27 27 Document doc = (Document) xstream.fromXML(is); -
spatial.streams.kml/src/test/resources/sapience/features/streams/kml/samples/NestedFolders.kml
r94 r96 9 9 <Placemark> 10 10 <name>Point A.A</name> 11 <Point> 12 <coordinates>8.922092297639281,52.28729651710943,0</coordinates> 13 </Point> 11 14 12 </Placemark> 15 13 <Placemark> 16 14 <name>Point A.B</name> 17 <Point> 18 <coordinates>9.922092297639281,52.28729651710943,0</coordinates> 19 </Point> 15 20 16 </Placemark> 21 17 … … 27 23 <Placemark> 28 24 <name>Point B.A</name> 29 <Point> 30 <coordinates>8.922092297639281,52.28729651710943,0</coordinates> 31 </Point> 25 32 26 </Placemark> 33 27 <Placemark> 34 28 <name>Point B.B</name> 35 <Point> 36 <coordinates>8.922092297639281,52.28729651710943,0</coordinates> 37 </Point> 29 38 30 </Placemark> 39 31 <Placemark> 40 32 <name>Point A.C</name> 41 <Point> 42 <coordinates>10.922092297639281,52.28729651710943,0</coordinates> 43 </Point> 33 44 34 </Placemark> 45 35 <Placemark> 46 36 <name>Point A.D</name> 47 <Point> 48 <coordinates>11.922092297639281,52.28729651710943,0</coordinates> 49 </Point> 37 50 38 </Placemark> 51 39 </Folder>
Note: See TracChangeset
for help on using the changeset viewer.