/** Get the names of all the styles supported by the layer */ public Set<String> getLayerStyles() { checkInitialized(); return availableStyles; }
@Override public boolean applies(String parameterValue) { checkInitialized(); return parameterValue == null || getLegalValues().contains(parameterValue); }
@Override public String getDefaultValue() { checkInitialized(); String name = super.getDefaultValue(); if (name.isEmpty()) { // Default is not set so use the default from the layer if (defaultStyle == null) return ""; return defaultStyle; } else { // Default is set so use it return name; } }
@Override public List<String> getLegalValues() { checkInitialized(); Set<String> layerStyles = getLayerStyles(); // will contain the layer legal \ allowed styles List<String> finalStyles = new ArrayList<>(); if (allowedStyles == null) { // Values is null so allow any of the backing layer's styles finalStyles.addAll(layerStyles); } else { // Values is set so only allow the intersection of the specified styles and those of the // backing layer. finalStyles.addAll(Sets.intersection(layerStyles, allowedStyles)); } // make sure layer default style is considered a legal style if (defaultStyle != null && !finalStyles.contains(defaultStyle)) { finalStyles.add(defaultStyle); } return finalStyles; }
@Override public String apply(String str) throws ParameterException { checkInitialized(); if (str == null || str.isEmpty()) { // Use the default return getDefaultValue(); } else { for (String value : getLegalValues()) { // Find a matching style if (value.equalsIgnoreCase(str)) { return value; } } // no match so fail throw new ParameterException( 400, "InvalidParameterValue", "Style", String.format("Style '%s' is invalid.", str)); } }