info.getResolutions().add(1. / scale.getPixelPerUnit());
}
}
private void postProcess(VectorLayer layer) throws LayerException {
VectorLayerInfo info = layer.getLayerInfo();
if (info != null) {
// check for invalid attribute names
for (AttributeInfo attributeInfo : info.getFeatureInfo().getAttributes()) {
if (attributeInfo.getName().contains(".") || attributeInfo.getName().contains("/")) {
throw new LayerException(ExceptionCode.INVALID_ATTRIBUTE_NAME, attributeInfo.getName(),
layer.getId());
}
}
// apply defaults to all styles
for (NamedStyleInfo namedStyle : info.getNamedStyleInfos()) {
// check sld location
if (namedStyle.getSldLocation() != null) {
Resource resource = applicationContext.getResource(namedStyle.getSldLocation());
IBindingFactory bindingFactory;
try {
bindingFactory = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
IUnmarshallingContext unmarshallingContext = bindingFactory.createUnmarshallingContext();
StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) unmarshallingContext
.unmarshalDocument(new InputStreamReader(resource.getInputStream()));
namedStyle.setStyledLayerInfo(sld);
} catch (JiBXException e) {
throw new LayerException(e, ExceptionCode.INVALID_SLD, namedStyle.getSldLocation(),
layer.getId());
} catch (IOException e) {
throw new LayerException(e, ExceptionCode.INVALID_SLD, namedStyle.getSldLocation(),
layer.getId());
}
String layerName = (namedStyle.getSldLayerName() != null ? namedStyle.getSldLayerName() : layer
.getId());
String styleName = (namedStyle.getSldStyleName() != null ? namedStyle.getSldStyleName() : layer
.getId());
NamedStyleInfo sldStyle = styleConverterService.convert(namedStyle.getStyledLayerInfo(),
info.getFeatureInfo(), layerName, styleName);
namedStyle.setFeatureStyles(sldStyle.getFeatureStyles());
namedStyle.setLabelStyle(sldStyle.getLabelStyle());
}
}
// apply defaults to all styles
for (NamedStyleInfo namedStyle : info.getNamedStyleInfos()) {
for (FeatureStyleInfo featureStyle : namedStyle.getFeatureStyles()) {
featureStyle.applyDefaults();
}
if (namedStyle.getLabelStyle().getLabelAttributeName() == null) {
AttributeInfo attributeInfo = info.getFeatureInfo().getAttributes().get(0);
namedStyle.getLabelStyle().setLabelAttributeName(attributeInfo.getName());
}
namedStyle.getLabelStyle().getBackgroundStyle().applyDefaults();
namedStyle.getLabelStyle().getFontStyle().applyDefaults();
}