public Filter(String pattern, boolean allow) { this.pattern = WildcardUtil.compileWildcardPattern(pattern); this.allow = allow; } }
/** * Convert wildcard pattern to Pattern * @param pattern String containing wildcard pattern * @return compiled regular expression as a Pattern */ public static Pattern compileWildcardPattern(String pattern) { StringBuilder buf = new StringBuilder(pattern); for (int i=buf.length()-1; i>=0; i--) { char c = buf.charAt(i); if (c == '*' && (i == 0 || buf.charAt(i-1) != '\\')) { buf.insert(i+1, '?'); buf.insert(i, '.'); } else if (c == '*') { i--; // skip backslash, too } else if (needsBackslashToBeLiteralInRegex(c)) { buf.insert(i, '\\'); } } return Pattern.compile(buf.toString()); }
private static void addPattern(List<Pattern> results, String pattern, String type) { results.add(REGEXP_PATTERN.equals(type) ? Pattern.compile(pattern) : WildcardUtil.compileWildcardPattern(pattern)); if (LOG.isTraceEnabled()) { LOG.trace("Adding include {} expression: {}", (REGEXP_PATTERN.equals(type) ? "property" : "wildcard"), pattern); } }
/** * Sets a comma-delimited list of wildcard expressions to match properties * that should be excluded from the JSON output. * * @param commaDelim A comma-delimited list of wildcard patterns */ public void setExcludeWildcards(String commaDelim) { Set<String> excludePatterns = JSONUtil.asSet(commaDelim); if (excludePatterns != null) { this.excludeProperties = new ArrayList<>(excludePatterns.size()); for (String pattern : excludePatterns) { this.excludeProperties.add(WildcardUtil.compileWildcardPattern(pattern)); } } }
/** * @return the appropriate set of includes, based on debug setting. * Derived classes can override if there are additional, custom * debug-only parameters. */ protected List getIncludeProperties() { if (includeProperties != null && getDebug()) { List<Pattern> list = new ArrayList<>(includeProperties); list.add(Pattern.compile("debug")); list.add(WildcardUtil.compileWildcardPattern("error.*")); return list; } else { return includeProperties; } }
/** * Sets a comma-delimited list of wildcard expressions to match * properties that should be excluded from the JSON output. * * @param commaDelim * A comma-delimited list of wildcard expressions */ public void setExcludeWildcards(String commaDelim) { Set<String> excludePatterns = JSONUtil.asSet(commaDelim); if (excludePatterns != null) { this.excludeProperties = new ArrayList<>(excludePatterns.size()); for (String pattern : excludePatterns) { this.excludeProperties.add(WildcardUtil.compileWildcardPattern(pattern)); } } }
protected Set<ApplicationResource> findResources(String path) throws IOException { Set<ApplicationResource> resources = new HashSet<>(); LOG.trace("Using ResourceFinder to find matches for {}", path); Pattern pattern = WildcardUtil.compileWildcardPattern(path); Map<String, URL> matches = finder.getResourcesMap(""); for (Map.Entry<String, URL> entry : matches.entrySet()) { if (pattern.matcher(entry.getKey()).matches()) { resources.add(new StrutsApplicationResource(entry.getValue())); } } LOG.trace("Found resources {} for path {}", resources, path); return resources; }
/** * Sets a comma-delimited list of wildcard expressions to match * properties that should be included from the JSON output. The * standard boilerplate (id, error, debug) are automatically included, * as appropriate, so you only need to provide patterns for the * contents of "result". * * @param commaDelim * A comma-delimited list of wildcard expressions */ public void setIncludeWildcards(String commaDelim) { includeProperties = JSONUtil.processIncludePatterns(JSONUtil.asSet(commaDelim), JSONUtil.WILDCARD_PATTERN); if (includeProperties != null) { includeProperties.add(Pattern.compile("id")); includeProperties.add(Pattern.compile("result")); includeProperties.add(Pattern.compile("error")); includeProperties.add(WildcardUtil.compileWildcardPattern("error.code")); } }