if (namespace == null) {
namespace = catalog.getDefaultNamespace();
}
wli.setNamespace(namespace);
Layer layer = wli.getWMSLayer(null);
// try to get the native SRS -> we use the bounding boxes, GeoServer will publish all of the
// supported SRS in the root, if we use getSRS() we'll get them all
for (String srs : layer.getBoundingBoxes().keySet()) {
try {
CoordinateReferenceSystem crs = CRS.decode(srs);
wli.setSRS(srs);
wli.setNativeCRS(crs);
} catch (Exception e) {
LOGGER.log(Level.INFO, "Skipping " + srs
+ " definition, it was not recognized by the referencing subsystem");
}
}
// fall back on WGS84 if necessary
if (wli.getSRS() == null) {
wli.setSRS("EPSG:4326");
wli.setNativeCRS(DefaultGeographicCRS.WGS84);
}
wli.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
// try to grab the envelope
GeneralEnvelope envelope = layer.getEnvelope(wli.getNativeCRS());
if (envelope != null) {
ReferencedEnvelope re = new ReferencedEnvelope(envelope.getMinimum(0), envelope
.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1), wli
.getNativeCRS());
// are we in crazy wms 1.3 land?
if(wli.getNativeCRS() instanceof GeographicCRS) {
WebMapServer mapServer = wms.getWebMapServer(null);
Version version = new Version(mapServer.getCapabilities().getVersion());
if(version.compareTo(new Version("1.3.0")) >= 0) {
// flip axis, the wms code won't actually use the crs
double minx = re.getMinX();
double miny = re.getMinY();
double maxx = re.getMaxX();
double maxy = re.getMaxY();
re = new ReferencedEnvelope(miny, maxy, minx, maxx, wli.getNativeCRS());
}
}
wli.setNativeBoundingBox(re);
}
CRSEnvelope llbbox = layer.getLatLonBoundingBox();
if (llbbox != null) {
ReferencedEnvelope re = new ReferencedEnvelope(llbbox.getMinX(), llbbox.getMaxX(),
llbbox.getMinY(), llbbox.getMaxY(), DefaultGeographicCRS.WGS84);
wli.setLatLonBoundingBox(re);
} else if (wli.getNativeBoundingBox() != null) {
try {
wli.setLatLonBoundingBox(wli.getNativeBoundingBox().transform(
DefaultGeographicCRS.WGS84, true));
} catch (Exception e) {
LOGGER.log(Level.INFO, "Could not transform native bbox into a lat/lon one", e);
}
}
// reflect all the metadata that we can grab
wli.setAbstract(layer.get_abstract());
wli.setDescription(layer.get_abstract());
wli.setTitle(layer.getTitle());
if (layer.getKeywords() != null) {
wli.getKeywords().addAll(Arrays.asList(layer.getKeywords()));
}
// strip off the prefix if we're cascading from a server that does add them
String published = wli.getName();
if (published.contains(":")) {