WmsTileFactory implements TileFactory { public String urlForTile(Sector sector, int width, int height) { if (sector == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "WmsTileFactory", "urlForTile", "missingSector")); } if (width < 1 || height < 1) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "WmsTileFactory", "urlForTile", "invalidWidthOrHeight")); } StringBuilder url = new StringBuilder(this.serviceAddress); int index = url.indexOf("?"); if (index < 0) { url.append("?"); } else if (index != url.length() - 1) { index = url.lastIndexOf("&"); if (index != url.length() - 1) { url.append("&"); } } index = this.serviceAddress.toUpperCase(Locale.US).indexOf("SERVICE=WMS"); if (index < 0) { url.append("SERVICE=WMS"); } url.append("&VERSION=").append(this.wmsVersion); url.append("&REQUEST=GetMap"); url.append("&LAYERS=").append(this.layerNames); url.append("&STYLES=").append(this.styleNames != null ? this.styleNames : ""); if (this.wmsVersion.equals("1.3.0")) { url.append("&CRS=").append(this.coordinateSystem); url.append("&BBOX="); if (this.coordinateSystem.equals("CRS:84")) { url.append(sector.minLongitude()).append(",").append(sector.minLatitude()).append(","); url.append(sector.maxLongitude()).append(",").append(sector.maxLatitude()); } else { url.append(sector.minLatitude()).append(",").append(sector.minLongitude()).append(","); url.append(sector.maxLatitude()).append(",").append(sector.maxLongitude()); } } else { url.append("&SRS=").append(this.coordinateSystem); url.append("&BBOX="); url.append(sector.minLongitude()).append(",").append(sector.minLatitude()).append(","); url.append(sector.maxLongitude()).append(",").append(sector.maxLatitude()); } url.append("&WIDTH=").append(width); url.append("&HEIGHT=").append(height); url.append("&FORMAT=").append(this.imageFormat != null ? this.imageFormat : "image/png"); url.append("&TRANSPARENT=").append(this.transparent ? "TRUE" : "FALSE"); if (this.timeString != null) { url.append("&TIME=").append(this.timeString); } return url.toString(); } WmsTileFactory(String serviceAddress, String wmsVersion, String layerNames, String styleNames);  WmsTileFactory(WmsLayerConfig config); String getServiceAddress(); void setServiceAddress(String serviceAddress); String getWmsVersion(); void setWmsVersion(String wmsVersion); String getLayerNames(); void setLayerNames(String layerNames); String getStyleNames(); void setStyleNames(String styleNames); String getCoordinateSystem(); void setCoordinateSystem(String coordinateSystem); String getImageFormat(); void setImageFormat(String imageFormat); boolean isTransparent(); void setTransparent(boolean transparent); String getTimeString(); void setTimeString(String timeString); @Override Tile createTile(Sector sector, Level level, int row, int column); String urlForTile(Sector sector, int width, int height);  }
@Test public void testUrlForTile_ParameterCheck() { WmsLayerConfig layerConfig = new WmsLayerConfig(COMMON_SERVICE_ADDRESS, COMMON_LAYER_NAMES); WmsTileFactory standardWmsMapFactory = new WmsTileFactory(layerConfig); try { standardWmsMapFactory.urlForTile(null, 0, 0); fail("null parameters provided to urlForTile"); } catch (IllegalArgumentException ex) { assertNotNull("null exception thrown", ex); } Sector sector = PowerMockito.mock(Sector.class); standardWmsMapFactory = new WmsTileFactory(layerConfig); try { standardWmsMapFactory.urlForTile(sector, 0, 0); fail("null Parameters Pushed to urlForTile"); } catch (IllegalArgumentException ex) { assertNotNull("null exception thrown", ex); } }
@Test public void testUrlForTile_QueryDelimiterPositioning_BaseUrl() { String serviceAddress = COMMON_SERVICE_ADDRESS; String wmsVersion = COMMON_WMS_VERSION; String layerNames = COMMON_LAYER_NAMES; int tileHeight = 5; int tileWidth = 4; Sector sector = PowerMockito.mock(Sector.class); PowerMockito.when(sector.minLatitude()).thenReturn(NOTIONAL_MIN_LAT); PowerMockito.when(sector.maxLatitude()).thenReturn(NOTIONAL_MAX_LAT); PowerMockito.when(sector.minLongitude()).thenReturn(NOTIONAL_MIN_LON); PowerMockito.when(sector.maxLongitude()).thenReturn(NOTIONAL_MAX_LON); WmsTileFactory wmsFactory = new WmsTileFactory(serviceAddress, wmsVersion, layerNames, null); String url = wmsFactory.urlForTile(sector, tileWidth, tileHeight); checkQueryDelimiter(url); }
@Test public void testUrlForTile_QueryDelimiterPositioning_DelimiterAppended() { String serviceAddress = COMMON_SERVICE_ADDRESS; String wmsVersion = COMMON_WMS_VERSION; String layerNames = COMMON_LAYER_NAMES; int tileHeight = 5; int tileWidth = 4; Sector sector = PowerMockito.mock(Sector.class); PowerMockito.when(sector.minLatitude()).thenReturn(NOTIONAL_MIN_LAT); PowerMockito.when(sector.maxLatitude()).thenReturn(NOTIONAL_MAX_LAT); PowerMockito.when(sector.minLongitude()).thenReturn(NOTIONAL_MIN_LON); PowerMockito.when(sector.maxLongitude()).thenReturn(NOTIONAL_MAX_LON); WmsTileFactory wmsFactory = new WmsTileFactory(serviceAddress + '?', wmsVersion, layerNames, null); String url = wmsFactory.urlForTile(sector, tileWidth, tileHeight); checkQueryDelimiter(url); }
@Test public void testUrlForTile_QueryDelimiterPositioning_BareUrl_AdditionalParameters() { String serviceAddress = COMMON_SERVICE_ADDRESS; String wmsVersion = COMMON_WMS_VERSION; String layerNames = COMMON_LAYER_NAMES; int tileHeight = 5; int tileWidth = 4; Sector sector = PowerMockito.mock(Sector.class); PowerMockito.when(sector.minLatitude()).thenReturn(NOTIONAL_MIN_LAT); PowerMockito.when(sector.maxLatitude()).thenReturn(NOTIONAL_MAX_LAT); PowerMockito.when(sector.minLongitude()).thenReturn(NOTIONAL_MIN_LON); PowerMockito.when(sector.maxLongitude()).thenReturn(NOTIONAL_MAX_LON); WmsTileFactory wmsFactory = new WmsTileFactory(serviceAddress + "?NOTIONAL=YES", wmsVersion, layerNames, null); String url = wmsFactory.urlForTile(sector, tileWidth, tileHeight); checkQueryDelimiter(url); }
@Test public void testUrlForTile_QueryDelimiterPositioning_BareUrl_AdditionalParametersWithAmpersand() { String serviceAddress = COMMON_SERVICE_ADDRESS; String wmsVersion = COMMON_WMS_VERSION; String layerNames = COMMON_LAYER_NAMES; int tileHeight = 5; int tileWidth = 4; Sector sector = PowerMockito.mock(Sector.class); PowerMockito.when(sector.minLatitude()).thenReturn(NOTIONAL_MIN_LAT); PowerMockito.when(sector.maxLatitude()).thenReturn(NOTIONAL_MAX_LAT); PowerMockito.when(sector.minLongitude()).thenReturn(NOTIONAL_MIN_LON); PowerMockito.when(sector.maxLongitude()).thenReturn(NOTIONAL_MAX_LON); WmsTileFactory wmsFactory = new WmsTileFactory(serviceAddress + "?NOTIONAL=YES&", wmsVersion, layerNames, null); String url = wmsFactory.urlForTile(sector, tileWidth, tileHeight); checkQueryDelimiter(url); }