Hi,
the KML2 module is almost ready as a KML module replacement, so I wanted to give people an introduction to its features and design, given that the next steps are going to be mostly bug fixes (unless I receive negative feedback on some design elements of course).
As already reported in a previous thread (March 1st) the module builds KML documents as object model trees based on the JAK library (https://code.google.com/p/javaapiforkml/) and uses the JDK own JAXB library to then serialize the resulting tree. Tests have been made to make sure JAXB is not affecting WFS CITE tests.
There are three KML object model builders in the codebase, two of them building a small KML made mostly of links, and one that is streaming, based on lists that are evaluated as they are traversed:
https://github.com/geoserver/geoserver/tree/master/src/community/kml2/src/main/java/org/geoserver/kml/builder
For example, the simple network link builder just builds a kml with a networklink for each layer:
https://github.com/geoserver/geoserver/blob/master/src/community/kml2/src/main/java/org/geoserver/kml/builder/SimpleNetworkLinkBuilder.java
The StreamingKMLBuilder instead builds a KML document containing a list of folders (one per layer) that is generated as the list itself is traversed, which in turn contains placemarks that are also generated as the list of placemarks is traversed:
https://github.com/geoserver/geoserver/blob/master/src/community/kml2/src/main/java/org/geoserver/kml/builder/StreamingKMLBuilder.java
The streaming behavior is based on the Sequence construct, a simplified iterator, and classes that wrap it to build enough List behavior to allow JAXB to encode the output:
https://github.com/geoserver/geoserver/tree/master/src/community/kml2/src/main/java/org/geoserver/kml/sequence
If you look at the feature sequence factory and its sequence, you’ll see how the streaming encoding works:
https://github.com/geoserver/geoserver/blob/master/src/community/kml2/src/main/java/org/geoserver/kml/sequence/FeatureSequenceFactory.java
The interesting bit here is that a basic Placemark is built, and then its contents are actually filled by pluggable decorators that do add the geometry, title, description, style and so on:
https://github.com/geoserver/geoserver/tree/master/src/community/kml2/src/main/java/org/geoserver/kml/decorator
This makes it easy to add new content in placemarks, but will also allow to completely separate GeoSearch as a clear cut plugin (still have to do this, it’s my next step after I’ve finished testing the KML generation and compare all the outputs to the old KML generator).
The regionation code is still there, and has been isolated in its own little package:
https://github.com/geoserver/geoserver/tree/master/src/community/kml2/src/main/java/org/geoserver/kml/regionate
All the crufty code to load the data and parse the styles have been factored out in a bunch of small Visitor classes, plus a KMLFeatureAccessor that binds them all togheter:
https://github.com/geoserver/geoserver/tree/master/src/community/kml2/src/main/java/org/geoserver/kml/utils
As you can see, generally speaking, each bit of the KML generation has been split into smaller self contained classes having just one purpose. The old KMLUtils is still there, but have a look and you’ll see it really just has a handful of utility methods left.
The code coverage is, at the moment, at 77%, but I plan to increase if further as I progress with the interactive tests and find areas that are not well covered.
Given that in 30 days we’re going to have the feature freeze, I’m also going to ask how we are playing with the upgrade.
I’m of course biased, but I feel this code is much more solid and more understandable than the old code base, besides being easier to extend, so if it was just for me I’d do a simple swap, kml2 in, old kml out.
My next step is to go through each page of the documentation about KML and manually try each request and parameter described there, comparing it with the outputs of the old module, to make sure there are no regressions (and then create a geosearch2 that leverages the kml2 module).
Soo… what do you think?
Ah, if you want to build it as a replacement of the kml module, you can by doing so:
mvn eclipse:eclipse -P!kml,kml2
The \ is there to escape the ! which is otherwise interpreted as a signal by the linux shell, if you are on another operating system you might not need it (and oh, the ! is there to exclude the kml profile).
Well, let me know
Cheers
Andrea
–
==
Our support, Your Success! Visit http://opensdi.geo-solutions.it for more information.
Ing. Andrea Aime
@geowolf
Technical Lead
GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549
http://www.geo-solutions.it
http://twitter.com/geosolutions_it