Changeset 96


Ignore:
Timestamp:
07/20/2009 03:30:47 PM (4 years ago)
Author:
pajoma
Message:

removed folder bug (was due to the document element in the KML object)

Location:
spatial.streams.kml/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • spatial.streams.kml/src/main/java/org/geospatial/kml/KMLFeature.java

    r95 r96  
    3636        @XStreamAlias("LookAt") 
    3737        private LookAt lookAt; 
    38  
    3938 
    4039        @XStreamAlias("styleUrl") 
  • spatial.streams.kml/src/main/java/sapience/features/streams/factories/KMLFactory.java

    r93 r96  
    1919import sapience.annotations.model.Description; 
    2020import sapience.annotations.model.KeyValueProperty; 
     21import sapience.annotations.model.Name; 
    2122import sapience.annotations.model.contact.Address; 
    22 import sapience.annotations.model.contact.Name; 
    2323import sapience.features.Feature; 
    2424import sapience.features.FeatureCollection; 
     25import sapience.features.factories.FeatureFactory; 
    2526 
    2627 
    2728import com.vividsolutions.jts.geom.Geometry; 
    2829 
     30/** 
     31 * TODO: not finished 
     32 *  
     33 * Creates a {@link KML} object from a {@link FeatureCollection} 
     34 *  
     35 * @author pajoma 
     36 * 
     37 */ 
    2938public class KMLFactory { 
    3039 
     
    6170        public KML buildKML(FeatureCollection coll) throws IOException { 
    6271                kml = new KML(); 
    63                 kml.addDocument((Document) populateContainer(new Document(), coll)); 
     72                kml.setFeature((Document) populateContainer(new Document(), coll)); 
    6473                 
    6574                return kml; 
     
    8190                        if(fc.getAssociatedFeatureCollection() == null) { 
    8291                                Document doc = (Document) populateContainer(new Document(), fc); 
    83                                 kml.addDocument(doc); 
     92                                kml.setFeature(doc); 
    8493                                 
    8594                                // 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  
    88import org.junit.Test; 
    99 
    10 import sapience.annotations.model.contact.Name; 
     10import sapience.annotations.model.Name; 
    1111import sapience.features.FeatureCollection; 
    1212import sapience.features.streams.Streams; 
  • spatial.streams.kml/src/test/java/sapience/features/streams/kml/TestEasy.java

    r92 r96  
    11package sapience.features.streams.kml; 
    22 
    3 import java.io.File; 
     3import java.io.ByteArrayOutputStream; 
     4import java.io.FileInputStream; 
    45import java.io.IOException; 
    5 import java.util.List; 
     6import java.io.OutputStream; 
    67 
    7 import org.geospatial.kml.Document; 
    8 import org.geospatial.kml.KML; 
    9 import org.geospatial.kml.KMLFeature; 
    10 import org.junit.Assert; 
     8import junit.framework.Assert; 
     9 
     10import org.apache.commons.io.IOUtils; 
     11import org.junit.Before; 
    1112import org.junit.Test; 
    1213 
    13 import sapience.features.Feature; 
     14 
     15import sapience.annotations.model.Name; 
    1416import sapience.features.FeatureCollection; 
    1517import sapience.features.streams.Streams; 
    16 import sapience.features.streams.kml.KMLStream; 
    1718 
    1819public class TestEasy { 
    1920 
    20         String file = "samples/easy.kml"; 
     21        String in = "samples/easy.kml"; 
     22        String out = "samples/easy.out.kml"; 
    2123         
    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)); 
    4631        } 
    4732         
    4833        @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 
    4951        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                 
    5372        } 
     73         
    5474} 
  • spatial.streams.kml/src/test/java/sapience/features/streams/kml/TestMultipleStyles.java

    r95 r96  
    11package sapience.features.streams.kml; 
    22 
     3import java.io.IOException; 
     4import java.io.InputStream; 
     5 
     6import org.geospatial.kml.Document; 
     7import org.geospatial.kml.Folder; 
     8import org.geospatial.kml.KML; 
     9import org.geospatial.kml.KMLContainer; 
     10import org.geospatial.kml.KMLFeature; 
     11import org.geospatial.kml.Placemark; 
     12import org.junit.Before; 
    313import org.junit.Test; 
     14 
     15import com.thoughtworks.xstream.XStream; 
     16import com.thoughtworks.xstream.io.xml.QNameMap; 
     17import com.thoughtworks.xstream.io.xml.StaxDriver; 
    418 
    519import sapience.features.FeatureCollection; 
     
    822public class TestMultipleStyles { 
    923 
    10         String name = "samples/MultipleStyles.kml"; 
     24        String file = "samples/MultipleStyles.kml"; 
    1125         
     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        } 
    1237 
    1338        @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); 
    1741                 
    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)); 
    2245        } 
    2346 
  • spatial.streams.kml/src/test/java/sapience/features/streams/kml/TestNestedFolders.java

    r94 r96  
    22 
    33import java.io.IOException; 
     4import java.io.InputStream; 
    45 
     6import org.geospatial.kml.Document; 
     7import org.geospatial.kml.Folder; 
     8import org.geospatial.kml.KML; 
     9import org.geospatial.kml.KMLContainer; 
     10import org.geospatial.kml.KMLFeature; 
     11import org.geospatial.kml.Placemark; 
     12import org.junit.Before; 
    513import org.junit.Test; 
     14 
     15import com.thoughtworks.xstream.XStream; 
     16import com.thoughtworks.xstream.io.xml.QNameMap; 
     17import com.thoughtworks.xstream.io.xml.StaxDriver; 
    618 
    719import sapience.features.FeatureCollection; 
     
    1123 
    1224        String file = "samples/NestedFolders.kml"; 
     25        private XStream xstream; 
    1326         
     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 
    1448        @Test 
    1549        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)); 
    1855        } 
    1956} 
  • spatial.streams.kml/src/test/java/testing/Parser.java

    r95 r96  
    2323                this.configure(); 
    2424                 
    25                 InputStream is = this.getClass().getResourceAsStream("example.xml"); 
     25                InputStream is = this.getClass().getResourceAsStream("Example.xml"); 
    2626                 
    2727                Document doc = (Document) xstream.fromXML(is); 
  • spatial.streams.kml/src/test/resources/sapience/features/streams/kml/samples/NestedFolders.kml

    r94 r96  
    99                        <Placemark> 
    1010                                <name>Point A.A</name> 
    11                                 <Point> 
    12                                         <coordinates>8.922092297639281,52.28729651710943,0</coordinates> 
    13                                 </Point> 
     11 
    1412                        </Placemark> 
    1513                        <Placemark> 
    1614                                <name>Point A.B</name> 
    17                                 <Point> 
    18                                         <coordinates>9.922092297639281,52.28729651710943,0</coordinates> 
    19                                 </Point> 
     15 
    2016                        </Placemark> 
    2117 
     
    2723                        <Placemark> 
    2824                                <name>Point B.A</name> 
    29                                 <Point> 
    30                                         <coordinates>8.922092297639281,52.28729651710943,0</coordinates> 
    31                                 </Point> 
     25         
    3226                        </Placemark> 
    3327                        <Placemark> 
    3428                                <name>Point B.B</name> 
    35                                 <Point> 
    36                                         <coordinates>8.922092297639281,52.28729651710943,0</coordinates> 
    37                                 </Point> 
     29                         
    3830                        </Placemark> 
    3931                        <Placemark> 
    4032                                <name>Point A.C</name> 
    41                                 <Point> 
    42                                         <coordinates>10.922092297639281,52.28729651710943,0</coordinates> 
    43                                 </Point> 
     33                 
    4434                        </Placemark> 
    4535                        <Placemark> 
    4636                                <name>Point A.D</name> 
    47                                 <Point> 
    48                                         <coordinates>11.922092297639281,52.28729651710943,0</coordinates> 
    49                                 </Point> 
     37                         
    5038                        </Placemark> 
    5139                </Folder> 
Note: See TracChangeset for help on using the changeset viewer.