Changeset 97
- Timestamp:
- 07/20/2009 03:31:03 PM (4 years ago)
- Location:
- spatial.streams.kml/src
- Files:
-
- 3 edited
-
main/java/org/geospatial/kml/Document.java (modified) (1 diff)
-
main/java/org/geospatial/kml/KML.java (modified) (2 diffs)
-
test/resources/sapience/features/streams/kml/samples/easy.out.kml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
spatial.streams.kml/src/main/java/org/geospatial/kml/Document.java
r95 r97 22 22 @XStreamAlias("Document") 23 23 public class Document extends KMLContainer { 24 25 24 26 27 28 25 @XStreamImplicit 29 26 private List<StyleSelector> styles = null; 30 27 31 32 28 33 34 35 29 /** 36 30 * Shared Styles for this document. -
spatial.streams.kml/src/main/java/org/geospatial/kml/KML.java
r93 r97 9 9 10 10 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 */ 11 19 @XStreamAlias("kml") 12 20 public class KML { 13 21 14 @XStreamAlias("Document") 22 /* A basic <kml> element contains 0 or 1 Feature 23 * and 0 or 1 NetworkLinkControl: 24 */ 25 15 26 @XStreamImplicit 16 private List< Document> documents;27 private List<KMLFeature> documents; 17 28 18 29 /** 19 * Returns the first document30 * Returns the first feature 20 31 * @return 21 32 */ 22 public List< Document> getDocuments() {33 public List<KMLFeature> listFeatures() { 23 34 if (documents == null) { 24 documents = new ArrayList< Document>();35 documents = new ArrayList<KMLFeature>(); 25 36 } 26 37 return documents; … … 28 39 29 40 /** 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 * 32 45 * @return 33 46 * @throws MultipleFeaturesException 34 47 */ 35 48 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 } 37 57 else throw new IOException("Multiple Documents in this KML"); 38 58 } 39 59 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); 42 84 } 43 85 -
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.