/** * Creates a predicate that returns true if any of the given paths match exactly. */ public static Predicate paths(final String... paths) { final PathMatchPredicate[] predicates = new PathMatchPredicate[paths.length]; for (int i = 0; i < paths.length; ++i) { predicates[i] = new PathMatchPredicate(paths[i]); } return or(predicates); }
/** * Creates a predicate that returns true if the request path ends with any of the provided suffixes. */ public static Predicate suffixes(final String... paths) { if(paths.length == 1) { return suffix(paths[0]); } final PathSuffixPredicate[] predicates = new PathSuffixPredicate[paths.length]; for (int i = 0; i < paths.length; ++i) { predicates[i] = new PathSuffixPredicate(paths[i]); } return or(predicates); }
/** * Adds a new predicated handler. * <p> * * @param predicate * @param handlerWrapper */ public PredicatesHandler addPredicatedHandler(final Predicate predicate, final HandlerWrapper handlerWrapper) { this.addPredicatedHandler(predicate, handlerWrapper, null); return this; }
@Override public boolean resolve(final HttpServerExchange value) { for(final Predicate predicate : predicates) { if(!predicate.resolve(value)) { return false; } } return true; } }
public static PredicatesHandler predicates(final List<PredicatedHandler> handlers, HttpHandler next) { final PredicatesHandler predicatesHandler = new PredicatesHandler(next); for(PredicatedHandler handler : handlers) { predicatesHandler.addPredicatedHandler(handler); } return predicatesHandler; }
/** * parses the predicate string, and returns the result * @param predicate The prediate string * @param classLoader The class loader to load the predicates from * @return The predicate */ public static Predicate parse(final String predicate, ClassLoader classLoader) { return PredicateParser.parse(predicate, classLoader); }
AccessLogService(String pattern, String path, String pathRelativeTo, String filePrefix, String fileSuffix, boolean rotate, boolean extended, Predicate predicate) { this.pattern = pattern; this.path = path; this.pathRelativeTo = pathRelativeTo; this.filePrefix = filePrefix; this.fileSuffix = fileSuffix; this.rotate = rotate; this.extended = extended; this.useServerLog = false; this.predicate = predicate == null ? Predicates.truePredicate() : predicate; }
/** * Prediction which always returns true */ public static Predicate truePredicate() { return TruePredicate.instance(); }
/** * Creates a predicate that returns true if the relative request path matches any of the provided prefixes. */ public static Predicate prefixes(final String... paths) { return new PathPrefixPredicate(paths); }
/** * Predicate that returns true if the Content-Size of a request is below a * given value. */ public static Predicate minContentSize(final long size) { return new MinContentSizePredicate(size); }
/** * Returns true if the given attribute is present and contains one of the provided value. * @param attribute The exchange attribute. * @param values The values to check for. */ public static Predicate contains(final ExchangeAttribute attribute, final String ... values) { return new ContainsPredicate(attribute, values); }
/** * Creates a predicate that returns true if the given path matches exactly. */ public static Predicate path(final String path) { return new PathMatchPredicate(path); }
/** * Predicate which always returns false. */ public static Predicate falsePredicate() { return FalsePredicate.instance(); }
/** * Creates a predicate that returns true if the given predicate returns * false. */ public static Predicate not(final Predicate predicate) { return new NotPredicate(predicate); }
/** * Predicate that returns true if the Content-Size of a request is above a * given value. * * @author Stuart Douglas */ public static Predicate maxContentSize(final long size) { return new MaxContentSizePredicate(size); }
/** * Creates a predicate that matches the given attribute against a regex. * @param requireFullMatch If a full match is required in order to return true. * @param attribute The attribute to check against. * @param pattern The pattern to look for. */ public static Predicate regex(final ExchangeAttribute attribute, final String pattern, boolean requireFullMatch) { return new RegularExpressionPredicate(pattern, attribute, requireFullMatch); }
/** * Return a predicate that will return true if the given attribute is not null and not empty. * * @param attribute The attribute to check whether it exists or not. */ public static Predicate exists(final ExchangeAttribute attribute) { return new ExistsPredicate(attribute); }
@Override public boolean resolve(final HttpServerExchange value) { for (final Predicate predicate : predicates) { if (predicate.resolve(value)) { return true; } } return false; } }
/** * Creates a predicate that returns true if the given relative path starts with the provided prefix. */ public static Predicate prefix(final String path) { return new PathPrefixPredicate(path); }
@Override public boolean resolve(final HttpServerExchange value) { return !predicate.resolve(value); } }