List of usage examples for java.util.regex Pattern pattern
pattern
From source file:com.edgenius.core.util.WebUtil.java
/** * @param agent //from w ww . ja v a 2 s . com * @return */ public static boolean isPublicSearchEngineRobot(String agent) { if (!agentListInit) { agentListInit = true; try { ResourceBundle ua = ResourceBundle.getBundle(USER_AGENET_BROWSER); Enumeration<String> em = ua.getKeys(); while (em.hasMoreElements()) { String regex = ua.getString(em.nextElement()); try { userAgentPatternList.add(Pattern.compile(regex)); } catch (Exception e) { log.error("Unable compile user agent pattern: " + regex); } } } catch (Throwable e) { log.error("Unable load user agent properties, use default instead"); } } if (userAgentPatternList.size() > 0) { // use User-Agent to detect if current request is from browser, search engine robot, web crawler etc. for (Pattern pattern : userAgentPatternList) { //so far, browser is small amount than robot, so for performance reason, use browser agent list //See our issue http://bug.edgenius.com/issues/34 //and SUN Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993 try { if (pattern.matcher(agent).matches()) return false; } catch (StackOverflowError e) { AuditLogger.error("StackOverflow Error in WebUtil.isPublicSearchEngineRobot. Input[" + agent + "] Pattern [" + pattern.pattern() + "]"); } catch (Throwable e) { AuditLogger.error("Unexpected error in WebUtil.isPublicSearchEngineRobot. Input[" + agent + "] Pattern [" + pattern.pattern() + "]", e); } } } else { //default very rough check String user = agent.toLowerCase(); if (user.indexOf("crawl") != -1 || user.indexOf("spider") != -1 || user.indexOf("check") != -1 || user.indexOf("bot") != -1) { return true; } else if (user.indexOf("mozilla") != -1 // ||user.indexOf("") != -1 || user.indexOf("opera") != -1) { return false; } } return true; }
From source file:org.codehaus.mojo.license.ArtifactHelper.java
protected static boolean isIncludable(Log log, Artifact project, Pattern includedGroupPattern, Pattern includedArtifactPattern) { // check if the groupId of the project should be included if (includedGroupPattern != null) { // we have some defined license filters try {/* w ww .j a v a 2 s.c o m*/ Matcher matchGroupId = includedGroupPattern.matcher(project.getGroupId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Include " + project.getGroupId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, includedGroupPattern.pattern())); } } // check if the artifactId of the project should be included if (includedArtifactPattern != null) { // we have some defined license filters try { Matcher matchGroupId = includedArtifactPattern.matcher(project.getArtifactId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Include " + project.getArtifactId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, includedArtifactPattern.pattern())); } } return false; }
From source file:org.codehaus.mojo.license.ArtifactHelper.java
protected static boolean isExcludable(Log log, Artifact project, Pattern excludedGroupPattern, Pattern excludedArtifactPattern) { // check if the groupId of the project should be included if (excludedGroupPattern != null) { // we have some defined license filters try {/*from w ww . j a va 2 s . co m*/ Matcher matchGroupId = excludedGroupPattern.matcher(project.getGroupId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Exclude " + project.getGroupId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, excludedGroupPattern.pattern())); } } // check if the artifactId of the project should be included if (excludedArtifactPattern != null) { // we have some defined license filters try { Matcher matchGroupId = excludedArtifactPattern.matcher(project.getArtifactId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Exclude " + project.getArtifactId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALIDE_PATTERN_MESSAGE, excludedArtifactPattern.pattern())); } } return false; }
From source file:pl.otros.logview.gui.message.pattern.PropertyPatternMessageColorizer.java
protected int countGroups(Pattern pattern) { int count = StringUtils.countMatches(pattern.pattern().replace("\\(", ""), "("); return count; }
From source file:edu.amc.sakai.user.RegexpBlacklistEidValidator.java
private Collection<String> eidBlacklistAsStrings() { if (eidBlacklist == null || eidBlacklist.isEmpty()) { return new HashSet<String>(0); }//from www. ja v a 2 s . co m HashSet<String> patternStrings = new HashSet<String>(eidBlacklist.size()); for (Pattern pattern : eidBlacklist) { patternStrings.add(pattern.pattern()); } return patternStrings; }
From source file:org.echocat.jomon.runtime.jaxb.PatternAdapter.java
@Override public String marshal(Pattern v) throws Exception { final String patternAsString; if (v != null) { patternAsString = "/" + v.pattern() + "/" + toFlagsAsString(v.flags()); } else {/* w w w .j a v a2s. c om*/ patternAsString = null; } return patternAsString; }
From source file:guru.qas.martini.annotation.StepsAnnotationProcessorTest.java
@Test public void testMultipleGivenRegex() throws NoSuchMethodException { MultipleGivenBean source = new MultipleGivenBean(); ClassPathXmlApplicationContext context = getContext(source); process(context, source);/*w w w . j ava 2s. c o m*/ MultipleGivenBean steps = context.getBean(MultipleGivenBean.class); Class<?> wrapped = AopUtils.getTargetClass(steps); Method method = wrapped.getMethod("doSomething"); Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class); Collection<StepImplementation> givens = givenBeanIndex.values(); Set<String> matches = Sets.newHashSetWithExpectedSize(2); for (StepImplementation given : givens) { Method givenMethod = given.getMethod(); if (givenMethod.equals(method)) { Pattern pattern = given.getPattern(); String regex = pattern.pattern(); matches.add(regex); } } int count = matches.size(); assertEquals(count, 2, "wrong number of GivenStep objects registered for MultipleGivenBean.getMartinis()"); Set<String> expected = Sets.newHashSet("this is regular expression one", "this is regular expression two"); assertEquals(matches, expected, "Steps contain wrong regex Pattern objects"); }
From source file:org.diorite.impl.command.PluginCommandBuilderImpl.java
@Override public PluginCommandBuilderImpl pattern(final Pattern pattern) { this.checkPattern(); this.pattern = Pattern.compile(pattern.pattern(), pattern.flags()); return this; }
From source file:org.jboss.windup.interrogator.impl.ExtensionInterrogator.java
protected boolean matchesExtension(String path) { for (Pattern extensionPattern : extensions) { if (extensionPattern.matcher(path).find()) { LOG.debug("Matched on extension: " + extensionPattern.pattern()); return true; }/* w w w . j a va2 s. com*/ } return false; }
From source file:com.ibm.watson.catalyst.jumpqa.matcher.EntryPatterns.java
@Override public int hashCode() { HashCodeBuilder result = new HashCodeBuilder(SEED, MULTIPLY); if (_titlePattern.isPresent()) { Pattern p1 = _titlePattern.get(); result.append(p1.pattern()); result.append(p1.flags());/*from w ww . j a va2 s . c om*/ } if (_answerPattern.isPresent()) { Pattern p2 = _answerPattern.get(); result.append(p2.pattern()); result.append(p2.flags()); } if (_textPattern.isPresent()) { Pattern p3 = _textPattern.get(); result.append(p3.pattern()); result.append(p3.flags()); } return result.hashCode(); }