package io.undertow.predicate;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import io.undertow.server.HttpServerExchange;
import io.undertow.UndertowLogger;
public class PathSuffixPredicate implements Predicate {
private final String suffix;
private static final boolean traceEnabled;
static {
traceEnabled = UndertowLogger.PREDICATE_LOGGER.isTraceEnabled();
}
PathSuffixPredicate(final String suffix) {
this.suffix = suffix;
}
@Override
public boolean resolve(final HttpServerExchange value) {
boolean matches = value.getRelativePath().endsWith(suffix);
if (traceEnabled) {
UndertowLogger.PREDICATE_LOGGER.tracef("Path suffix [%s] %s input [%s] for %s.", suffix, (matches ? "MATCHES" : "DOES NOT MATCH" ), value.getRelativePath(), value);
}
return matches;
}
public String toString() {
return "path-suffix( '" + suffix + "' )";
}
public static class Builder implements PredicateBuilder {
@Override
public String name() {
return "path-suffix";
}
@Override
public Map<String, Class<?>> parameters() {
return Collections.<String, Class<?>>singletonMap("path", String[].class);
}
@Override
public Set<String> requiredParameters() {
return Collections.singleton("path");
}
@Override
public String defaultParameter() {
return "path";
}
@Override
public Predicate build(final Map<String, Object> config) {
String[] path = (String[]) config.get("path");
return Predicates.suffixes(path);
}
}
}