fcObj = new ReprojectingFeatureCollection(fcObj, DefaultGeographicCRS.WGS84);
}
List<SimpleFeatureCollection> collections = new ArrayList<SimpleFeatureCollection>();
collections.add(fcObj);
KmlEncodingContext context = new WFSKmlEncodingContext(gs.getService(WFSInfo.class),
collections);
// create the document
Kml kml = new Kml();
Document document = kml.createAndSetDocument();
// get the callbacks for the document and let them loose
List<KmlDecorator> docDecorators = context.getDecoratorsForClass(Document.class);
for (KmlDecorator decorator : docDecorators) {
document = (Document) decorator.decorate(document, context);
if (document == null) {
throw new ServiceException("Coding error in decorator " + decorator
+ ", document objects cannot be set to null");
}
}
// build the contents
for (SimpleFeatureCollection collection : collections) {
// create the folder
SimpleFeatureCollection fc = (SimpleFeatureCollection) collection;
Folder folder = document.createAndAddFolder();
folder.setName(fc.getSchema().getTypeName());
// have it be decorated
List<KmlDecorator> folderDecorators = context.getDecoratorsForClass(Folder.class);
for (KmlDecorator decorator : folderDecorators) {
folder = (Folder) decorator.decorate(folder, context);
if (folder == null) {
break;
}
}
if (folder == null) {
continue;
}
// create the streaming features
context.setCurrentFeatureCollection(fc);
List<Feature> features = new SequenceList<Feature>(new WFSFeatureSequenceFactory(
context));
context.addFeatures(folder, features);
}
// write out the output
encoder.encode(kml, os, context);
os.flush();