use of org.apache.oro.text.regex.Pattern in project xwiki-platform by xwiki.
the class Util method getAllMatches.
public List<String> getAllMatches(String content, String spattern, int group) throws MalformedPatternException {
List<String> list = new ArrayList<String>();
PatternMatcherInput input = new PatternMatcherInput(content);
Pattern pattern = patterns.addPattern(spattern);
while (this.matcher.contains(input, pattern)) {
MatchResult result = this.matcher.getMatch();
String smatch = result.group(group);
list.add(smatch);
}
return list;
}
use of org.apache.oro.text.regex.Pattern in project photon-model by vmware.
the class Recurser method matches.
private boolean matches(String pattern, String path) throws FinderException {
Pattern compiled;
try {
compiled = this.globCompiler.compile(pattern);
} catch (MalformedPatternException e) {
throw new FinderException("Bad glob pattern: " + pattern, e);
}
path = basename(path);
return this.matcher.matches(path, compiled);
}
use of org.apache.oro.text.regex.Pattern in project ofbiz-framework by apache.
the class UtilHttp method checkURLforSpiders.
/**
* checks, if the current request comes from a searchbot
*
* @param request
* @return whether the request is from a web searchbot
*/
public static boolean checkURLforSpiders(HttpServletRequest request) {
boolean result = false;
String spiderRequest = (String) request.getAttribute("_REQUEST_FROM_SPIDER_");
if (UtilValidate.isNotEmpty(spiderRequest)) {
if ("Y".equals(spiderRequest)) {
return true;
}
return false;
}
String initialUserAgent = request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "";
List<String> spiderList = StringUtil.split(UtilProperties.getPropertyValue("url", "link.remove_lsessionid.user_agent_list"), ",");
if (UtilValidate.isNotEmpty(spiderList)) {
for (String spiderNameElement : spiderList) {
Pattern pattern = null;
try {
pattern = PatternFactory.createOrGetPerl5CompiledPattern(spiderNameElement, false);
} catch (MalformedPatternException e) {
Debug.logError(e, module);
}
PatternMatcher matcher = new Perl5Matcher();
if (matcher.contains(initialUserAgent, pattern)) {
request.setAttribute("_REQUEST_FROM_SPIDER_", "Y");
result = true;
break;
}
}
}
if (!result) {
request.setAttribute("_REQUEST_FROM_SPIDER_", "N");
}
return result;
}
use of org.apache.oro.text.regex.Pattern in project ofbiz-framework by apache.
the class PatternFactory method createOrGetPerl5CompiledPattern.
/**
* Compiles and caches a Perl5 regexp pattern for the given string pattern.
* This would be of no benefits (and may bloat memory usage) if stringPattern is never the same.
* @param stringPattern a Perl5 pattern string
* @param caseSensitive case sensitive true/false
* @return a <code>Pattern</code> instance for the given string pattern
* @throws MalformedPatternException
*/
public static Pattern createOrGetPerl5CompiledPattern(String stringPattern, boolean caseSensitive) throws MalformedPatternException {
Pattern pattern = compiledPerl5Patterns.get(stringPattern);
if (pattern == null) {
Perl5Compiler compiler = new Perl5Compiler();
if (caseSensitive) {
// READ_ONLY_MASK guarantees immutability
pattern = compiler.compile(stringPattern, Perl5Compiler.READ_ONLY_MASK);
} else {
pattern = compiler.compile(stringPattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
}
pattern = compiledPerl5Patterns.putIfAbsentAndGet(stringPattern, pattern);
if (Debug.verboseOn()) {
Debug.logVerbose("Compiled and cached the pattern: '" + stringPattern, module);
}
}
return pattern;
}
use of org.apache.oro.text.regex.Pattern in project ofbiz-framework by apache.
the class SeoTransform method seoUrl.
/**
* Transform a url according to seo pattern regular expressions.
*
* @param url , String to do the seo transform
* @param isAnon , boolean to indicate whether it's an anonymous visit.
*
* @return String, the transformed url.
*/
public static String seoUrl(String url, boolean isAnon) {
Perl5Matcher matcher = new Perl5Matcher();
if (SeoConfigUtil.checkUseUrlRegexp() && matcher.matches(url, SeoConfigUtil.getGeneralRegexpPattern())) {
Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
boolean foundMatch = false;
while (keys.hasNext()) {
String key = keys.next();
Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
if (pattern.getPattern().contains(";jsessionid=")) {
if (isAnon) {
if (SeoConfigUtil.isJSessionIdAnonEnabled()) {
continue;
}
} else {
if (SeoConfigUtil.isJSessionIdUserEnabled()) {
continue;
}
boolean foundException = false;
for (int i = 0; i < SeoConfigUtil.getUserExceptionPatterns().size(); i++) {
if (matcher.matches(url, SeoConfigUtil.getUserExceptionPatterns().get(i))) {
foundException = true;
break;
}
}
if (foundException) {
continue;
}
}
}
String replacement = SeoConfigUtil.getSeoReplacements().get(key);
if (matcher.matches(url, pattern)) {
for (int i = 1; i < matcher.getMatch().groups(); i++) {
replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
}
// break if found any matcher
url = replacement;
foundMatch = true;
break;
}
}
if (!foundMatch) {
if (Debug.verboseOn()) {
Debug.logVerbose("Can NOT find a seo transform pattern for this url: " + url, module);
}
}
}
return url;
}
Aggregations