@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public GetLegendGraphicRequest read(Object req, Map kvp, Map rawKvp) throws Exception {
GetLegendGraphicRequest request = (GetLegendGraphicRequest) super.read(req, kvp, rawKvp);
request.setRawKvp(rawKvp);
if (request.getVersion() == null || request.getVersion().length() == 0) {
String version = (String) rawKvp.get("WMTVER");
if (version == null) {
version = wms.getVersion();
}
request.setVersion(version);
}
final String language = (String) rawKvp.get("LANGUAGE");
if(language != null) {
request.setLocale(new Locale(language));
}
// Fix for http://jira.codehaus.org/browse/GEOS-710
// Since at the moment none of the other request do check the version
// numbers, we
// disable this check for the moment, and wait for a proper fix once the
// we support more than one version of WMS/WFS specs
// if (!GetLegendGraphicRequest.SLD_VERSION.equals(version)) {
// throw new WmsException("Invalid SLD version number \"" + version
// + "\"");
// }
final String layer = (String) rawKvp.get("LAYER");
final boolean strict = rawKvp.containsKey("STRICT") ? Boolean.valueOf((String) rawKvp
.get("STRICT")) : request.isStrict();
request.setStrict(strict);
if (strict && layer == null) {
throw new ServiceException("LAYER parameter not present for GetLegendGraphic",
"LayerNotDefined");
}
if (strict && request.getFormat() == null) {
throw new ServiceException("Missing FORMAT parameter for GetLegendGraphic",
"MissingFormat");
}
// object representing the layer or layer group requested
Object infoObject=null;
// list of layers to render in the legend (we can have more
// than one if a layergroup is requested)
List<FeatureType> layers = new ArrayList<FeatureType>();
if (layer != null) {
try {
LayerInfo layerInfo = wms.getLayerByName(layer);
if (layerInfo != null) {
addLayer(layers,layerInfo,request);
infoObject=layerInfo;
} else {
LayerGroupInfo layerGroupInfo = wms.getLayerGroupByName(layer);
if(layerGroupInfo != null) {
// add all single layers of the group
for(LayerInfo singleLayer : layerGroupInfo.layers()) {
addLayer(layers,singleLayer,request);
}
infoObject=layerGroupInfo;
} else {
throw new ServiceException(layer + " layer does not exist.");
}
}
request.setLayers(layers);
} catch (IOException e) {
throw new ServiceException(e);
} catch (NoSuchElementException ne) {
throw new ServiceException(new StringBuffer(layer)
.append(" layer does not exists.").toString(), ne);
} catch (Exception te) {
throw new ServiceException("Can't obtain the schema for the required layer.", te);
}
} else {
layers.add(null);
request.setLayers(layers);
}
if (request.getFormat() == null) {
request.setFormat(GetLegendGraphicRequest.DEFAULT_FORMAT);
}
if (null == wms.getLegendGraphicOutputFormat(request.getFormat())) {
throw new ServiceException(new StringBuffer("Invalid graphic format: ").append(
request.getFormat()).toString(), "InvalidFormat");
}
try {
parseOptionalParameters(request, infoObject, rawKvp);
if (layers.size() != request.getStyles().size()) {
String msg = layers.size() + " layers requested, but found " + request.getStyles().size()
+ " styles specified. ";
throw new ServiceException(msg, getClass().getName());
}
if (request.getRules().size()>0 && layers.size() != request.getRules().size()) {
String msg = layers.size() + " layers requested, but found " + request.getRules().size()
+ " rules specified. ";
throw new ServiceException(msg, getClass().getName());
}
} catch (IOException e) {
throw new ServiceException(e);