throw new WmsException("SLD document contains no layers");
}
final List<MapLayerInfo> layers = new ArrayList<MapLayerInfo>();
final List<Style> styles = new ArrayList<Style>();
MapLayerInfo currLayer = null;
Style currStyle = null;
String layerName;
UserLayer ul;
for(StyledLayer sl: styledLayers) {
layerName = sl.getName();
if (null == layerName) {
throw new WmsException("A UserLayer without layer name was passed");
}
final WMS wms = request.getWMS();
if (sl instanceof UserLayer && ((((UserLayer) sl)).getRemoteOWS() != null)) {
// this beast can define multiple feature sources and multiple styles, we'll
// have to mix and match them (ugh)
ul = ((UserLayer) sl);
try {
addRemoteLayersFromUserLayer(request, ul, layers, styles);
} catch (IOException e) {
throw new WmsException("Error accessing remote layers", "RemoteAccessFailed", e);
}
} else {
// simpler case, one layer, eventually multiple styles
currLayer = null;
// handle the InLineFeature stuff
if ((sl instanceof UserLayer)
&& ((((UserLayer) sl)).getInlineFeatureDatastore() != null)) {
// SPECIAL CASE - we make the temporary version
ul = ((UserLayer) sl);
try {
currLayer = initializeInlineFeatureLayer(request, ul);
} catch (Exception e) {
throw new WmsException(e);
}
} else {
if(wms.getLayerGroupByName(layerName) != null) {
LayerGroupInfo group = wms.getLayerGroupByName(layerName);
for(int i = 0; i < group.getLayers().size(); i++) {
LayerInfo layer = group.getLayers().get(i);
layers.add(new MapLayerInfo(layer));
StyleInfo style = group.getStyles().get(i);
if(style != null) {
styles.add(style.getStyle());
} else {
styles.add(layer.getDefaultStyle().getStyle());
}
}
// move to the next named layer
continue;
} else {
LayerInfo layerInfo = wms.getLayerByName(layerName);
if(layerInfo == null)
throw new WmsException("Unknown layer: " + layerName);
currLayer = new MapLayerInfo(layerInfo);
if (sl instanceof NamedLayer) {
NamedLayer namedLayer = ((NamedLayer) sl);
currLayer.setLayerFeatureConstraints(namedLayer.getLayerFeatureConstraints());
}
}
}
if (currLayer.getType() == MapLayerInfo.TYPE_RASTER) {
try {
addStyles(request, currLayer, sl, layers, styles);
} catch (WmsException wm) {
// hmm, well, the style they specified in the wms
// request