Changeset 97


Ignore:
Timestamp:
07/20/2009 03:31:03 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:
3 edited

Legend:

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

    r95 r97  
    2222@XStreamAlias("Document") 
    2323public class Document extends KMLContainer { 
    24      
    2524 
    26          
    27          
    2825        @XStreamImplicit 
    2926        private List<StyleSelector> styles = null; 
    3027         
    31   
    3228 
    33  
    34          
    3529        /** 
    3630         * Shared Styles for this document. 
  • spatial.streams.kml/src/main/java/org/geospatial/kml/KML.java

    r93 r97  
    99 
    1010 
     11/** 
     12 * The root element of a KML file. This element is required. It follows  
     13 * the xml declaration at the beginning of the file.  
     14 *  
     15 * @author pajoma 
     16 * @see http://code.google.com/apis/kml/documentation/kmlreference.html#kml 
     17 * 
     18 */ 
    1119@XStreamAlias("kml") 
    1220public class KML { 
    1321         
    14         @XStreamAlias("Document") 
     22        /* A basic <kml> element contains 0 or 1 Feature  
     23         * and 0 or 1 NetworkLinkControl: 
     24         */ 
     25         
    1526        @XStreamImplicit 
    16         private List<Document> documents; 
     27        private List<KMLFeature> documents; 
    1728 
    1829        /** 
    19          * Returns the first document 
     30         * Returns the first feature 
    2031         * @return 
    2132         */ 
    22         public List<Document> getDocuments() { 
     33        public List<KMLFeature> listFeatures() { 
    2334                if (documents == null) { 
    24                         documents = new ArrayList<Document>();   
     35                        documents = new ArrayList<KMLFeature>();         
    2536                } 
    2637                return documents; 
     
    2839         
    2940        /** 
    30          * Convenience method, if only one document exists (which should be the normal case),  
    31          * it will return it. Otherwise you get a  @see MultipleFeaturesException 
     41         * Returns the feature as Document. A KML file can only contain one feature  
     42         * (or a network link), we assume this feature is a document (we throw an exception 
     43         * otherwise) 
     44         *  
    3245         * @return 
    3346         * @throws MultipleFeaturesException  
    3447         */ 
    3548        public Document getDocument() throws IOException { 
    36                 if(getDocuments().size()==1) return getDocuments().get(0); 
     49                if(listFeatures().size()==1) { 
     50                        KMLFeature f = this.getFeature(); 
     51                        if(f instanceof Document) return (Document) f; 
     52                         
     53                        // TODO: throw an exception which states that this is a network link 
     54                         
     55                        else throw new IOException("Not a Document"); 
     56                } 
    3757                else throw new IOException("Multiple Documents in this KML"); 
    3858        } 
    3959         
    40         public void addDocument(Document doc) { 
    41                 this.getDocuments().add(doc); 
     60        /** 
     61         * Returns the feature A KML file can only contain one feature  
     62         * (usually a Document or a network link), this method returns it. 
     63         *  
     64         *  
     65         * @return 
     66         * @throws MultipleFeaturesException  
     67         */ 
     68        public KMLFeature getFeature() throws IOException { 
     69                if(listFeatures().size()==0) throw new IOException("No Feature in this KML"); 
     70                if(listFeatures().size()>1) throw new IOException("Multiple Features in this KML"); 
     71                         
     72                return listFeatures().get(0); 
     73 
     74        } 
     75         
     76        /** 
     77         * Sets the feature of this KML object. Note: only one feature per KML is allowed,  
     78         * which means adding a second feature will overwrite the first.  
     79         * @param doc 
     80         */ 
     81        public void setFeature(KMLFeature doc) { 
     82                this.documents = null; 
     83                this.listFeatures().add(doc); 
    4284        } 
    4385 
  • spatial.streams.kml/src/test/resources/sapience/features/streams/kml/samples/easy.out.kml

    r81 r97  
    1 <?xml version="1.0" ?> 
    2 <kml xmlns="http://www.opengis.net/kml/2.2"> 
    3         <Document> 
    4                 <name>Easy Testing of Recursive Containers</name> 
    5                 <Folder> 
    6                         <name>Folder B</name> 
    7                         <Placemark> 
    8                                 <name>Point A.C</name> 
    9                                 <Point> 
    10                                         <coordinates>52.28729651710943,10.922092297639281,0.0 </coordinates> 
    11                                 </Point> 
    12                         </Placemark> 
    13                         <Placemark> 
    14                                 <name>Point B.B</name> 
    15                                 <Point> 
    16                                         <coordinates>52.28729651710943,8.922092297639281,0.0 </coordinates> 
    17                                 </Point> 
    18                         </Placemark> 
    19                         <Placemark> 
    20                                 <name>Point A.D</name> 
    21                                 <Point> 
    22                                         <coordinates>52.28729651710943,11.922092297639281,0.0 </coordinates> 
    23                                 </Point> 
    24                         </Placemark> 
    25                         <Placemark> 
    26                                 <name>Point B.A</name> 
    27                                 <Point> 
    28                                         <coordinates>52.28729651710943,8.922092297639281,0.0 </coordinates> 
    29                                 </Point> 
    30                         </Placemark> 
    31                 </Folder> 
    32                 <Folder> 
    33                         <name>Folder A</name> 
    34                         <Placemark> 
    35                                 <name>Point A.B</name> 
    36                                 <Point> 
    37                                         <coordinates>52.28729651710943,9.922092297639281,0.0 </coordinates> 
    38                                 </Point> 
    39                         </Placemark> 
    40                         <Placemark> 
    41                                 <name>Point A.A</name> 
    42                                 <Point> 
    43                                         <coordinates>52.28729651710943,8.922092297639281,0.0 </coordinates> 
    44                                 </Point> 
    45                         </Placemark> 
    46                 </Folder> 
    47         </Document> 
    48 </kml> 
     1<?xml version="1.0" ?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><name>Easy Testing of Recursive Containers</name><Folder><name>Folder A</name><Placemark><name>Point A.B</name><Point><coordinates>9.922092297639281,52.28729651710943,0.0 </coordinates></Point></Placemark><Placemark><name>Point A.A</name><Point><coordinates>8.922092297639281,52.28729651710943,0.0 </coordinates></Point></Placemark></Folder><Folder><name>Folder B</name><Placemark><name>Point B.B</name><Point><coordinates>8.922092297639281,52.28729651710943,0.0 </coordinates></Point></Placemark><Placemark><name>Point A.D</name><Point><coordinates>11.922092297639281,52.28729651710943,0.0 </coordinates></Point></Placemark><Placemark><name>Point B.A</name><Point><coordinates>8.922092297639281,52.28729651710943,0.0 </coordinates></Point></Placemark><Placemark><name>Point A.C</name><Point><coordinates>10.922092297639281,52.28729651710943,0.0 </coordinates></Point></Placemark></Folder></Document></kml> 
Note: See TracChangeset for help on using the changeset viewer.