List of usage examples for java.util.regex Matcher lookingAt
public boolean lookingAt()
From source file:com.meltmedia.cadmium.servlets.BasicFileServlet.java
public static List<String> parseETagList(String value) { List<String> etags = new ArrayList<String>(); value = value.trim();/*from w ww .j av a2s .c o m*/ if ("*".equals(value)) { etags.add(value); } else { Matcher etagMatcher = etagPattern.matcher(value); while (etagMatcher.lookingAt()) { etags.add(unescapePattern.matcher(etagMatcher.group(2)).replaceAll("$1")); etagMatcher.region(etagMatcher.start() + etagMatcher.group().length(), value.length()); } if (!etagMatcher.hitEnd()) { etags.clear(); } } return etags; }
From source file:jp.co.ctc_g.jfw.core.util.Beans.java
/** * ?????????????/*w w w . j av a2 s. c o m*/ * ???<code>getFoo</code><code>foo</code>? * <code>isBar</code><code>bar</code>?<code>setFoo</code><code>foo</code>??????? * @param accessorName ??????? * @return ?? */ public static String generatePropertyNameFor(String accessorName) { if (Strings.isEmpty(accessorName)) return accessorName; if (Beans.isPropertyAccessor(accessorName)) { Matcher matcher = FIRST_UPPERCASE_PATTERN.matcher(accessorName); return matcher.lookingAt() ? Beans.decapitalize(accessorName.substring(matcher.end() - 1)) : accessorName; } else { return accessorName; } }
From source file:com.edgenius.wiki.render.filter.UrlFilter.java
@Override public void replace(StringBuffer buffer, MatchResult matchResult, RenderContext context) { int count = matchResult.groupCount(); if (count != 2) { buffer.append(matchResult.group(0)); return;/*from ww w. jav a 2s .c o m*/ } String front = matchResult.group(1); String link = matchResult.group(2); String end = ""; Matcher m = END_PATTERN.matcher(StringUtils.reverse(link)); if (m.lookingAt()) { end = StringUtils.reverse(m.group(1)); link = link.substring(0, link.length() - end.length()); } buffer.append(formatter.format(new Object[] { front, link, end, RenderUtil.getExternalImage(context) })); }
From source file:com.predic8.membrane.core.interceptor.balancer.JSESSIONIDExtractor.java
@Override public String getSessionId(Message msg) throws Exception { String cookie = msg.getHeader().getFirstValue("Cookie"); if (cookie == null) { log.debug("no cookie set"); return null; }/*www . j a v a 2s . c o m*/ Matcher m = pattern.matcher(cookie); log.debug("cookie: " + msg.getHeader().getFirstValue("Cookie")); if (!m.lookingAt()) return null; log.debug("JSESSION cookie found: " + m.group(1).trim()); return m.group(1).trim(); }
From source file:gate.bulstem.BulStemPR.java
private String stem(String word) { Matcher m = vocals.matcher(word); if (!m.lookingAt()) { return word; }//from ww w . ja va 2 s . c o m for (int i = m.end() + 1; i < word.length(); i++) { String suffix = word.substring(i); if ((suffix = stemmingRules.get(suffix)) != null) { // get the new stem by cutting up the word and adding the right suffix // from the rules return word.substring(0, i) + suffix; } } return word; }
From source file:org.cleverbus.admin.services.log.LogParser.java
/** * Processes the next log line by either appending it to the last log event, * if it's not a valid log line and last log event wasn't ignored (appendTo != null); * or by parsing it into a new event (parseTo). * * @param line the log line to process * @param parseTo the next log event to parse line into * @param appendTo the log event to append non-event lines to * @param config log parser config//w w w. ja v a 2 s . c o m * @return appendTo event, if the line was appended to it; parseTo event if the line was fully parsed into this event; * or null if the line was ignored */ LogEvent parseLine(String line, LogEvent parseTo, LogEvent appendTo, LogParserConfig config) { Matcher dateMatcher = config.getDatePattern().matcher(line); if (!dateMatcher.lookingAt()) { return parseFailed(line, appendTo); } DateTime eventDate = getDate(dateMatcher.group(1), config); if (eventDate == null) { return parseFailed(line, appendTo); } // line might still not match properties and therefore not be a new log event, // so don't stop just yet, even if the date is wrong boolean skipLogLine = eventDate.isBefore(config.getFromDate()); if (skipLogLine && appendTo == null) { return null; // no point continuing, since this line wouldn't be appended anyway } parseTo.setDate(eventDate); String unmatched = line.substring(0, dateMatcher.start()) + line.substring(dateMatcher.end(), line.length()); // date matches, but is the line a new log event line? Matcher propertiesMatcher = config.getPropertiesPattern().matcher(unmatched); if (!propertiesMatcher.lookingAt()) { return parseFailed(line, appendTo); } if (skipLogLine || !parseEventProperties(propertiesMatcher, parseTo, config)) { return null; } if (unmatched != null && config.getMsg() != null && !unmatched.contains(config.getMsg())) { return null; } unmatched = unmatched.substring(0, propertiesMatcher.start()) + unmatched.substring(propertiesMatcher.end(), unmatched.length()); parseTo.setMessage(unmatched); return parseTo; }
From source file:$.LogParser.java
/** * Processes the next log line by either appending it to the last log event, * if it's not a valid log line and last log event wasn't ignored (appendTo != null); * or by parsing it into a new event (parseTo). *//from w ww . j ava 2 s.com * @param line the log line to process * @param parseTo the next log event to parse line into * @param appendTo the log event to append non-event lines to * @param config log parser config * @return appendTo event, if the line was appended to it; parseTo event if the line was fully parsed into this event; * or null if the line was ignored */ LogEvent parseLine(String line, LogEvent parseTo, LogEvent appendTo, LogParserConfig config) { Matcher dateMatcher = config.getDatePattern().matcher(line); if (!dateMatcher.lookingAt()) { return parseFailed(line, appendTo); } DateTime eventDate = getDate(dateMatcher.group(1), config); if (eventDate == null) { return parseFailed(line, appendTo); } // line might still not match properties and therefore not be a new log event, // so don't stop just yet, even if the date is wrong boolean skipLogLine = eventDate.isBefore(config.getFromDate()); if (skipLogLine && appendTo == null) { return null; // no point continuing, since this line wouldn't be appended anyway } parseTo.setDate(eventDate); String unmatched = line.substring(0, dateMatcher.start()) + line.substring(dateMatcher.end(), line.length()); // date matches, but is the line a new log event line? Matcher propertiesMatcher = config.getPropertiesPattern().matcher(unmatched); if (!propertiesMatcher.lookingAt()) { return parseFailed(line, appendTo); } if (skipLogLine || !parseEventProperties(propertiesMatcher, parseTo, config)) { return null; } if (unmatched != null && config.getMsg() != null && !unmatched.contains(config.getMsg())) { return null; } unmatched = unmatched.substring(0, propertiesMatcher.start()) + unmatched.substring(propertiesMatcher.end(), unmatched.length()); parseTo.setMessage(unmatched); return parseTo; }
From source file:com.hurence.logisland.processor.MatchIP.java
@Override protected Collection<Record> internalProcess(ProcessContext context, Collection<Record> records) { // convert all numeric fields to double to get numeric range working ... final List<Record> outRecords = new ArrayList<>(); final List<InputDocument> inputDocs = new ArrayList<>(); final Map<String, Record> inputRecords = new HashMap<>(); for (final Record record : records) { final InputDocument.Builder docbuilder = InputDocument.builder(record.getId()); for (final String fieldName : record.getAllFieldNames()) { if (luceneAttrsToQuery.contains(fieldName) && record.getField(fieldName).getRawValue() != null) { String ip = record.getField(fieldName).asString(); // Check the value is an IPv4 address or ignore Matcher checkIp = ipPattern.matcher(ip); if (checkIp.lookingAt()) { long ipLong = ipToLong(ip); docbuilder.addField(fieldName, String.valueOf(ipLong), keywordAnalyzer); }/*from w w w .j a v a 2s . c o m*/ } } inputDocs.add(docbuilder.build()); inputRecords.put(record.getId(), record); } // match a batch of documents Matches<QueryMatch> matches; try { matches = monitor.match(DocumentBatch.of(inputDocs), SimpleMatcher.FACTORY); } catch (IOException e) { getLogger().error("Could not match documents", e); return outRecords; } MatchHandlers.MatchHandler _matchHandler = null; if (onMatchPolicy == OnMatchPolicy.first && onMissPolicy == OnMissPolicy.discard) { // Legacy behaviour _matchHandler = new MatchHandlers.LegacyMatchHandler(); } else if (onMissPolicy == OnMissPolicy.discard) { // Ignore non matching records. Concat all query information (name, value) instead of first one only. _matchHandler = new MatchHandlers.ConcatMatchHandler(); } else { // All records in, all records out. Concat all query information (name, value) instead of first one only. _matchHandler = new MatchHandlers.AllInAllOutMatchHandler(records, this.onMatchPolicy); } final MatchHandlers.MatchHandler matchHandler = _matchHandler; for (DocumentMatches<QueryMatch> docMatch : matches) { docMatch.getMatches() .forEach(queryMatch -> matchHandler.handleMatch(inputRecords.get(docMatch.getDocId()), context, matchingRules.get(queryMatch.getQueryId()), recordTypeUpdatePolicy)); } if (ipRegexps != null && ipRegexps.size() > 0) { inputRecords.keySet().forEach((k) -> { // Only consider records that have not matched any IP rules yet int count = matches.getMatchCount(k); if (count == 0) { // Apply regexp rules if any available for (String ipAttrName : ipRegexps.keySet()) { if (inputRecords.get(k).hasField(ipAttrName) && (inputRecords.get(k).getField(ipAttrName).getRawValue() != null)) { HashSet<Pair<String, Pattern>> ipRegexHashset = ipRegexps.get(ipAttrName); ipRegexHashset.forEach(p -> { String ruleName = p.getLeft(); Pattern ipRegexPattern = p.getRight(); String attrValueToMatch = inputRecords.get(k).getField(ipAttrName).asString(); Matcher ipMatcher = ipRegexPattern.matcher(attrValueToMatch); if (ipMatcher.lookingAt()) { // This is a match ! matchHandler.handleMatch(inputRecords.get(k), context, regexpMatchingRules.get(ruleName), recordTypeUpdatePolicy); } }); } } } }); } return matchHandler.outputRecords(); }
From source file:com.hurence.logisland.processor.MatchIP.java
@Override protected void updateMatchingRules(ProcessContext context) { // loop over dynamic properties to add rules for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) { if (!entry.getKey().isDynamic()) { continue; }/*w w w. ja v a 2s . c o m*/ final String name = entry.getKey().getName(); final String query = entry.getValue(); String[] params = query.split(":", 2); if (params.length == 2) { String queryField = params[0]; String luceneQuery; String luceneValue; String ipValue = params[1]; Matcher ipMatcher = ipPattern.matcher(ipValue); Matcher cidrMatcher = cidrPattern.matcher(ipValue); if (ipMatcher.lookingAt()) { // This is a static ip address // convert it to a long long addr = ipToLong(ipValue); luceneValue = String.valueOf(addr); luceneQuery = queryField + ":" + luceneValue; matchingRules.put(name, new MatchingRule(name, luceneQuery, query)); luceneAttrsToQuery.add(queryField); } else if (cidrMatcher.lookingAt()) { // This is a cidr // Convert it to a range SubnetUtils su = new SubnetUtils(ipValue); String lowIp = su.getInfo().getLowAddress(); String highIp = su.getInfo().getHighAddress(); long lowIpLong = ipToLong(lowIp); long highIpLong = ipToLong(highIp); luceneValue = "[ " + String.valueOf(lowIpLong) + " TO " + String.valueOf(highIpLong) + " ]"; luceneQuery = queryField + ":" + luceneValue; matchingRules.put(name, new MatchingRule(name, luceneQuery, query)); luceneAttrsToQuery.add(queryField); } else { regexpMatchingRules.put(name, new MatchingRule(name, query)); // Consider the value to be a regexp // To Be Done Pattern ipRegexp = Pattern.compile(ipValue); if (ipRegexps == null) { ipRegexps = new HashMap<>(); } if (ipRegexps.containsKey(queryField)) { HashSet<Pair<String, Pattern>> regexpVals = ipRegexps.get(queryField); regexpVals.add(new ImmutablePair<>(name, ipRegexp)); ipRegexps.put(queryField, regexpVals); } else { HashSet<Pair<String, Pattern>> regexpVals = new HashSet<>(); regexpVals.add(new org.apache.commons.lang3.tuple.ImmutablePair<>(name, ipRegexp)); ipRegexps.put(queryField, regexpVals); } } } } }