}
if (name != null && name.length() == 0) {
name = null;
}
if (name == null) {// name is mandatory
throw new HttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST,
"Layer name not provided");
}
LayerInfo layer = null;
LayerGroupInfo layerGroup = null;
if (id != null) {
layer = catalog.getLayer(id);
if (layer == null) {
layerGroup = catalog.getLayerGroup(id);
if (layerGroup == null) {
throw new HttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST,
"No GeoServer Layer or LayerGroup exists with id '" + id + "'");
}
}
} else {
layer = catalog.getLayerByName(name);
if (layer == null) {
layerGroup = catalog.getLayerGroupByName(name);
if (layerGroup == null) {
throw new HttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND,
"GeoServer Layer or LayerGroup '" + name + "' not found");
}
}
}
final String actualId = layer != null ? layer.getId() : layerGroup.getId();
final String actualName = layer != null ? GWC.tileLayerName(layer) : GWC
.tileLayerName(layerGroup);
if (id != null && !name.equals(actualName)) {
throw new HttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST,
"Layer with id '" + id + "' found but name does not match: '" + name
+ "'/'" + actualName + "'");
}
info.setId(actualId);