/** * Checks whether a given parameter value applies to this filter. * * @param parameterValue the value to check if applies to this parameter filter * @return {@code true} if {@code parameterValue} is valid according to this filter, {@code * false} otherwise */ @Override public boolean applies(@Nullable String parameterValue) { return getLegalValues().contains(getNormalize().apply(parameterValue)); }
/** * @see org.geoserver.gwc.layer.GeoServerTileLayerInfo#cachedStyles() */ @Override public ImmutableSet<String> cachedStyles() { ParameterFilter styleQualifier = TileLayerInfoUtil.findParameterFilter("STYLES", getParameterFilters()); if (styleQualifier != null) { if (styleQualifier instanceof StringParameterFilter) { StringParameterFilter sp = (StringParameterFilter) styleQualifier; return ImmutableSet.copyOf(sp.getLegalValues()); } } return ImmutableSet.of(); }
@Override public String apply(@Nullable String str) throws ParameterException { if (str == null || str.length() == 0) { return getDefaultValue(); } str = getNormalize().apply(str); if (getLegalValues().contains(str)) { return str; } throw new ParameterException(str + " violates filter for parameter " + getKey()); }
public void testGetParameterFilters() { layerInfoTileLayer = new GeoServerTileLayer(layerInfo, defaults, gridSetBroker); List<ParameterFilter> parameterFilters = layerInfoTileLayer.getParameterFilters(); assertNotNull(parameterFilters); assertEquals(1, parameterFilters.size()); assertTrue(parameterFilters.get(0) instanceof StringParameterFilter); StringParameterFilter styleFilter = (StringParameterFilter) parameterFilters.get(0); assertEquals("STYLES", styleFilter.getKey()); assertEquals("default_style", styleFilter.getDefaultValue()); assertEquals(new HashSet<String>(Arrays.asList("alternateStyle-1", "alternateStyle-2")), new HashSet<String>(styleFilter.getLegalValues())); // layerInfoTileLayer.getInfo().getCachedStyles().add("alternateStyle-2"); }
@Test public void testNormalizeLocale() throws Exception { filter.setValues(Arrays.asList("f\u0131o", "B\u0131r", "BIZ")); filter.setNormalize(new CaseNormalizer(Case.LOWER, Locale.forLanguageTag("tr"))); assertThat(filter.getLegalValues(), containsInAnyOrder("f\u0131o", "b\u0131r", "b\u0131z")); for (String test : Arrays.asList("f\u0131o", "B\u0131r", "BIZ")) { assertThat(filter.applies(test), is(true)); assertThat(filter.apply(test), equalTo(test.toLowerCase(Locale.forLanguageTag("tr")))); } for (String test : Arrays.asList( "F\u0131o", "FIO", "B\u0131R", "b\u0131r", "BIR", "BIz", "b\u0131z")) { assertThat(filter.applies(test), is(true)); assertThat(filter.apply(test), equalTo(test.toLowerCase(Locale.forLanguageTag("tr")))); } for (String test : Arrays.asList("f\u0131oo", "f\u0131", "B\u0131", "BB\u0131rr", "BI", "BBIZ")) { assertThat(filter.applies(test), is(false)); try { filter.apply(test); fail(); } catch (Exception ex) { assertThat(ex, instanceOf(ParameterException.class)); } } assertThat(filter.apply(null), equalTo("Default")); assertThat(filter.apply(""), equalTo("Default")); }
@Test public void testNormalizeLower() throws Exception { filter.setNormalize(new CaseNormalizer(Case.LOWER, Locale.ENGLISH)); assertThat(filter.getLegalValues(), containsInAnyOrder("foo", "bar", "baz")); for (String test : Arrays.asList("foo", "Bar", "BAZ")) { assertThat(filter.applies(test), is(true)); assertThat(filter.apply(test), equalTo(test.toLowerCase(Locale.ENGLISH))); } for (String test : Arrays.asList("Foo", "FOO", "BaR", "bar", "BAR", "BAz", "baz")) { assertThat(filter.applies(test), is(true)); assertThat(filter.apply(test), equalTo(test.toLowerCase(Locale.ENGLISH))); } for (String test : Arrays.asList("fooo", "fo", "Ba", "BBarr", "BA", "BBAZ")) { assertThat(filter.applies(test), is(false)); try { filter.apply(test); fail(); } catch (Exception ex) { assertThat(ex, instanceOf(ParameterException.class)); } } assertThat(filter.apply(null), equalTo("Default")); assertThat(filter.apply(""), equalTo("Default")); }
@Test public void testNormalizeUpper() throws Exception { filter.setNormalize(new CaseNormalizer(Case.UPPER, Locale.ENGLISH)); assertThat(filter.getLegalValues(), containsInAnyOrder("FOO", "BAR", "BAZ")); for (String test : Arrays.asList("foo", "Bar", "BAZ")) { assertThat(filter.applies(test), is(true)); assertThat(filter.apply(test), equalTo(test.toUpperCase(Locale.ENGLISH))); } for (String test : Arrays.asList("Foo", "FOO", "BaR", "bar", "BAR", "BAz", "baz")) { assertThat(filter.applies(test), is(true)); assertThat(filter.apply(test), equalTo(test.toUpperCase(Locale.ENGLISH))); } for (String test : Arrays.asList("fooo", "fo", "Ba", "BBarr", "BA", "BBAZ")) { assertThat(filter.applies(test), is(false)); try { filter.apply(test); fail(); } catch (Exception ex) { assertThat(ex, instanceOf(ParameterException.class)); } } assertThat(filter.apply(null), equalTo("Default")); assertThat(filter.apply(""), equalTo("Default")); }
hasProperty("locale", equalTo(Locale.getDefault())))); assertThat(filter.getLegalValues(), containsInAnyOrder("foo", "Bar", "BAZ"));
assertEquals(ImmutableList.of("burg", "point"), stringFilter.getLegalValues());
assertEquals(ImmutableList.of("burg", "point"), stringFilter.getLegalValues());