static class PlacemarkNameDecorator implements KmlDecorator {
static final Logger LOGGER = Logging.getLogger(PlacemarkNameDecorator.class);
@Override
public Feature decorate(Feature feature, KmlEncodingContext context) {
Placemark pm = (Placemark) feature;
// try with the template
SimpleFeature sf = context.getCurrentFeature();
String title = null;
try {
title = context.getTemplate().title(sf);
} catch(IOException e) {
String msg = "Error occured processing 'title' template.";
LOGGER.log(Level.WARNING, msg, e);
}
// if we got nothing, set the title to the ID, but also try the text symbolizers
String featureId = sf.getID();
if (title == null || "".equals(title) || featureId.equals(title)) {
title = featureId;
// see if we can do better with a text symbolizer
// symbolizers are available only in wms mode
if(context.getCurrentSymbolizers() != null) {
StringBuffer label = new StringBuffer();
for (Symbolizer sym : context.getCurrentSymbolizers()) {
if (sym instanceof TextSymbolizer) {
Expression e = SLD.textLabel((TextSymbolizer) sym);
String value = e.evaluate(sf, String.class);
if ((value != null) && !"".equals(value.trim())) {
label.append(value);
}
}
}
if (label.length() > 0) {
title = label.toString();
}
}
}
pm.setName(title);
return pm;
}