checkNotNull(legendInfo.getFormat(), "Legend format is mandatory in WMTS."); checkNotNull(legendInfo.getLegendUrl(), "Legend URL is mandatory in WMTS."); xml.attribute("format", legendInfo.getFormat()); xml.attribute("xlink:href", legendInfo.getLegendUrl()); if (legendInfo.getWidth() != null) { xml.attribute("width", String.valueOf(legendInfo.getWidth())); if (legendInfo.getHeight() != null) { xml.attribute("height", String.valueOf(legendInfo.getHeight())); if (legendInfo.getMinScale() != null) { xml.attribute("minScaleDenominator", String.valueOf(legendInfo.getMinScale())); if (legendInfo.getMaxScale() != null) { xml.attribute("maxScaleDenominator", String.valueOf(legendInfo.getMaxScale()));
public LegendInfo build() { // let's see if we need to really on the default values for width, height and format Integer finalWidth = width == null ? defaultWidth : width; Integer finalHeight = height == null ? defaultHeight : height; String finalFormat = format == null ? defaultFormat : format; // checking mandatory format value checkNotNull(finalFormat, "A legend image format is mandatory."); // default styles can have a NULL name String finalStyleName = styleName == null ? "" : styleName; // building the legend url String finalUrl = buildFinalUrl(finalStyleName, finalWidth, finalHeight, finalFormat); return new LegendInfo( finalStyleName, finalWidth, finalHeight, finalFormat, finalUrl, minScale, maxScale); }
legendInfo.getWidth(), "Legend with is mandatory in WMS (1.1.0, 1.1.1 and 1.3.0)."); checkNotNull( legendInfo.getHeight(), "Legend height is mandatory in WMS (1.1.0, 1.1.1 and 1.3.0)."); checkNotNull( legendInfo.getFormat(), "Legend format is mandatory in WMS (1.1.0, 1.1.1 and 1.3.0)."); checkNotNull( legendInfo.getLegendUrl(), "Legend URL is mandatory in WMS (1.1.0, 1.1.1 and 1.3.0)."); xml.indentElement("LegendURL"); xml.attribute("width", String.valueOf(legendInfo.getWidth())); xml.attribute("height", String.valueOf(legendInfo.getHeight())); xml.simpleElement("Format", legendInfo.getFormat(), true); xml.attribute("xlink:href", legendInfo.getLegendUrl()); xml.endElement("OnlineResource");
@Test public void testWithCompleteUrl() { LegendInfo legendInfo = new LegendInfoBuilder() .withLayerName("layer1") .withLayerUrl("http://localhost:8080/geoserver") .withDefaultWidth(50) .withDefaultHeight(100) .withDefaultFormat("image/png") .withStyleName("style1") .withWidth(150) .withHeight(200) .withFormat("image/gif") .withCompleteUrl("http://my.server.com/image.gif") .build(); assertThat(legendInfo.getWidth(), is(150)); assertThat(legendInfo.getHeight(), is(200)); assertThat(legendInfo.getFormat(), is("image/gif")); assertThat(legendInfo.getStyleName(), is("style1")); assertThat(legendInfo.getLegendUrl(), is("http://my.server.com/image.gif")); }
@Test public void testWithOnlyDefaults() { LegendInfo legendInfo = new LegendInfoBuilder() .withLayerName("layer1") .withLayerUrl("http://localhost:8080/geoserver") .withDefaultWidth(50) .withDefaultHeight(100) .withDefaultFormat("image/png") .build(); assertThat(legendInfo.getWidth(), is(50)); assertThat(legendInfo.getHeight(), is(100)); assertThat(legendInfo.getFormat(), is("image/png")); assertThat(legendInfo.getStyleName(), is("")); assertThat(legendInfo.getMinScale(), is(nullValue())); assertThat(legendInfo.getMaxScale(), is(nullValue())); assertThat( legendInfo.getLegendUrl(), is( "http://localhost:8080/geoserver?" + "service=WMS&request=GetLegendGraphic&format=image/png&width=50&height=100&layer=layer1&style=")); }
@Test public void testWithUrl() { LegendInfo legendInfo = new LegendInfoBuilder() .withLayerName("layer1") .withLayerUrl("http://localhost:8080/geoserver") .withDefaultWidth(50) .withDefaultHeight(100) .withDefaultFormat("image/png") .withStyleName("style1") .withWidth(150) .withHeight(200) .withFormat("image/gif") .withUrl("http://localhost:9090/image.gif?") .build(); assertThat(legendInfo.getWidth(), is(150)); assertThat(legendInfo.getHeight(), is(200)); assertThat(legendInfo.getFormat(), is("image/gif")); assertThat(legendInfo.getStyleName(), is("style1")); assertThat( legendInfo.getLegendUrl(), is( "http://localhost:9090/image.gif?" + "service=WMS&request=GetLegendGraphic&format=image/gif&width=150&height=200&layer=layer1&style=style1")); }
@Test public void testWithValuesNoDefaults() { LegendInfo legendInfo = new LegendInfoBuilder() .withLayerName("layer1") .withLayerUrl("http://localhost:8080/geoserver") .withStyleName("style1") .withWidth(150) .withHeight(200) .withFormat("image/gif") .withMinScale(50.5) .withMaxScale(80.5) .build(); assertThat(legendInfo.getWidth(), is(150)); assertThat(legendInfo.getHeight(), is(200)); assertThat(legendInfo.getFormat(), is("image/gif")); assertThat(legendInfo.getStyleName(), is("style1")); assertThat(legendInfo.getMinScale(), is(50.5)); assertThat(legendInfo.getMaxScale(), is(80.5)); assertThat( legendInfo.getLegendUrl(), is( "http://localhost:8080/geoserver?" + "service=WMS&request=GetLegendGraphic&format=image/gif&width=150&height=200&layer=layer1&style=style1")); } }
@Test public void testWithValues() { LegendInfo legendInfo = new LegendInfoBuilder() .withLayerName("layer1") .withLayerUrl("http://localhost:8080/geoserver") .withDefaultWidth(50) .withDefaultHeight(100) .withDefaultFormat("image/png") .withStyleName("style1") .withWidth(150) .withHeight(200) .withFormat("image/gif") .withMinScale(1000.55) .withMaxScale(2000.655) .build(); assertThat(legendInfo.getWidth(), is(150)); assertThat(legendInfo.getHeight(), is(200)); assertThat(legendInfo.getFormat(), is("image/gif")); assertThat(legendInfo.getStyleName(), is("style1")); assertThat(legendInfo.getMinScale(), is(1000.55)); assertThat(legendInfo.getMaxScale(), is(2000.655)); assertThat( legendInfo.getLegendUrl(), is( "http://localhost:8080/geoserver?" + "service=WMS&request=GetLegendGraphic&format=image/gif&width=150&height=200&layer=layer1&style=style1")); }