SimpleFeature sf = context.getCurrentFeature();
Placemark pm = (Placemark) feature;
// create the extended data, and encode any non null, non geometric attribute
ExtendedData exd = pm.createAndSetExtendedData();
SchemaData schemaData = exd.createAndAddSchemaData();
schemaData.setSchemaUrl("#" + context.getCurrentFeatureType().getTypeName() + "_" + context.getCurrentLayerIndex());
for (AttributeDescriptor ad : sf.getFeatureType().getAttributeDescriptors()) {
// skip geometry attributes
if (ad instanceof GeometryDescriptor) {
continue;
}
Object value = sf.getAttribute(ad.getLocalName());
if (value == null) {
continue;
}
// make an exception for dates
String kmlValue;
if (value instanceof Date) {
try {
kmlValue = DATE_CONVERTER.convert(value, String.class);
} catch (Exception e) {
throw new ServiceException("Failed to convert date into string while "
+ "generating extended data section", e);
}
} else {
kmlValue = Converters.convert(value, String.class);
}
SimpleData sd = schemaData.createAndAddSimpleData(ad.getLocalName());
sd.setValue(kmlValue);
}
return pm;
}