/** * Appends to current pattern new part which is could be a thread coupling pattern or just a * different thing to look up in the data. * * @param val pattern to be added * @param qualifier identifies how to conjunct it with previous patterns */ protected void addExtendedFilterPattern(String val, String qualifier) { if (LOGGER.isTraceEnabled()) LOGGER.trace("adding complex pattern: val={} qual={}", val, qualifier); if (qualifier != null) patternBuilder = patternBuilder.append(Qualifier.valueOf(qualifier).getPattern()); patternBuilder = patternBuilder.append("(?:").append(val).append(")"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Built so far: {}", patternBuilder.toString()); } }
public void setFilterPattern(String filterPattern, boolean noRegex) { this.noRegex = noRegex; this.givenFilterPattern = filterPattern; patternBuilder = new StringBuilder("(?ms)"); extractPatternParts(noRegex ? Pattern.quote(filterPattern) : filterPattern); this.filterPattern = Pattern.compile(patternBuilder.toString()); }
/** * Parses supplied filterPattern. If it contains any qualifiers like %and&|%or% parses them into * valid regex representation. * * @param val pattern String */ protected void extractPatternParts(String val) { String qRegex = ""; for (Qualifier it : Qualifier.values()) { qRegex += qRegex.length() > 0 ? "|%" + it + "%" : "%" + it + "%"; } if (LOGGER.isTraceEnabled()) LOGGER.trace("Trying to match supplied pattern /{}/ if it contains /{}/", val, qRegex); Matcher qualifierMatcher = Pattern.compile(qRegex).matcher(val); // matching any qualifiers with % signs if (qualifierMatcher.find()) { if (LOGGER.isTraceEnabled()) LOGGER.trace("Processing extended pattern"); String[] tokens = val.split("%"); String nextQualifier = null; if (tokens != null) { qRegex = qRegex.replaceAll("%", ""); // matching only qualifier names for (String grp : tokens) { if (LOGGER.isTraceEnabled()) LOGGER.trace("Next group in match: {}", grp); qualifierMatcher = Pattern.compile(qRegex).matcher(grp); if (qualifierMatcher.matches()) { nextQualifier = qualifierMatcher.group(); continue; } addExtendedFilterPattern(grp, nextQualifier); nextQualifier = null; } } else throw new IllegalArgumentException("Check your extended pattern:/" + val + "/"); } else { if (LOGGER.isTraceEnabled()) LOGGER.trace("No extended pattern supplied; keeping things simple"); patternBuilder.append(val); } }