private List<TileLayer> getLayers(WebMapServer wms, String wmsUrl, String urlVersion)
throws GeoWebCacheException {
List<TileLayer> layers = new LinkedList<TileLayer>();
WMSCapabilities capabilities = wms.getCapabilities();
if (capabilities == null) {
throw new ConfigurationException("Unable to get capabitilies from " + wmsUrl);
}
WMSHttpHelper sourceHelper = new WMSHttpHelper();
List<Layer> layerList = capabilities.getLayerList();
Iterator<Layer> layerIter = layerList.iterator();
while (layerIter.hasNext()) {
Layer layer = layerIter.next();
String name = layer.getName();
String stylesStr = "";
String title = layer.getTitle();
String description = layer.get_abstract();
LayerMetaInformation layerMetaInfo = null;
if (title != null || description != null) {
layerMetaInfo = new LayerMetaInformation(title, description, null, null);
}
boolean queryable = layer.isQueryable();
if (name != null) {
List<StyleImpl> styles = layer.getStyles();
StringBuffer buf = new StringBuffer();
if (styles != null) {
Iterator<StyleImpl> iter = styles.iterator();
boolean hasOne = false;
while (iter.hasNext()) {
if (hasOne) {
buf.append(",");
}
buf.append(iter.next().getName());
hasOne = true;
}
stylesStr = buf.toString();
}
double minX = layer.getLatLonBoundingBox().getMinX();
double minY = layer.getLatLonBoundingBox().getMinY();
double maxX = layer.getLatLonBoundingBox().getMaxX();
double maxY = layer.getLatLonBoundingBox().getMaxY();
BoundingBox bounds4326 = new BoundingBox(minX, minY, maxX, maxY);
log.info("Found layer: " + layer.getName() + " with LatLon bbox "
+ bounds4326.toString());
BoundingBox bounds3785 = new BoundingBox(longToSphericalMercatorX(minX),
latToSphericalMercatorY(minY), longToSphericalMercatorX(maxX),
latToSphericalMercatorY(maxY));
String[] wmsUrls = { wmsUrl };
LinkedList<ParameterFilter> paramFilters = new LinkedList<ParameterFilter>();
for (Dimension dimension : layer.getDimensions().values()) {
Extent dimExtent = layer.getExtent(dimension.getName());
paramFilters.add(new NaiveWMSDimensionFilter(dimension, dimExtent));
}
WMSLayer wmsLayer = null;
try {
wmsLayer = getLayer(name, wmsUrls, bounds4326, bounds3785, stylesStr,
queryable, layer.getBoundingBoxes(), paramFilters);
} catch (GeoWebCacheException gwc) {
log.error("Error creating " + layer.getName() + ": " + gwc.getMessage());
}
if (wmsLayer != null) {
// Finalize with some defaults
wmsLayer.setCacheBypassAllowed(allowCacheBypass);
wmsLayer.setBackendTimeout(backendTimeout);
wmsLayer.setMetaInformation(layerMetaInfo);
if (urlVersion != null) {
wmsLayer.setVersion(urlVersion);
} else {
String wmsVersion = capabilities.getVersion();
if (wmsVersion != null && wmsVersion.length() > 0) {
wmsLayer.setVersion(wmsVersion);
}
}
wmsLayer.setSourceHelper(sourceHelper);