use of org.apache.oro.text.regex.Perl5Matcher in project jspwiki by apache.
the class PluginContent method parsePluginLine.
/**
* Parses a plugin invocation and returns a DOM element.
*
* @param context The WikiContext
* @param commandline The line to parse
* @param pos The position in the stream parsing.
* @return A DOM element
* @throws PluginException If plugin invocation is faulty
* @since 2.10.0
*/
public static PluginContent parsePluginLine(final Context context, final String commandline, final int pos) throws PluginException {
final PatternMatcher matcher = new Perl5Matcher();
try {
final PluginManager pm = context.getEngine().getManager(PluginManager.class);
if (matcher.contains(commandline, pm.getPluginPattern())) {
final MatchResult res = matcher.getMatch();
final String plugin = res.group(2);
final String args = commandline.substring(res.endOffset(0), commandline.length() - (commandline.charAt(commandline.length() - 1) == '}' ? 1 : 0));
final Map<String, String> arglist = pm.parseArgs(args);
// set wikitext bounds of plugin as '_bounds' parameter, e.g., [345,396]
if (pos != -1) {
final int end = pos + commandline.length() + 2;
final String bounds = pos + "|" + end;
arglist.put(PluginManager.PARAM_BOUNDS, bounds);
}
return new PluginContent(plugin, arglist);
}
} catch (final ClassCastException e) {
log.error("Invalid type offered in parsing plugin arguments.", e);
throw new InternalWikiException("Oops, someone offered !String!", e);
} catch (final NoSuchElementException e) {
final String msg = "Missing parameter in plugin definition: " + commandline;
log.warn(msg, e);
throw new PluginException(msg);
} catch (final IOException e) {
final String msg = "Zyrf. Problems with parsing arguments: " + commandline;
log.warn(msg, e);
throw new PluginException(msg);
}
return null;
}
use of org.apache.oro.text.regex.Perl5Matcher in project jspwiki by apache.
the class AbstractReferralPlugin method filterCollection.
/**
* Filters a collection according to the include and exclude parameters.
*
* @param c The collection to filter.
* @return A filtered collection.
*/
protected List<String> filterCollection(final Collection<String> c) {
final ArrayList<String> result = new ArrayList<>();
final PatternMatcher pm = new Perl5Matcher();
for (final String pageName : c) {
//
// If include parameter exists, then by default we include only those
// pages in it (excluding the ones in the exclude pattern list).
//
// include='*' means the same as no include.
//
boolean includeThis = m_include == null;
if (m_include != null) {
for (final Pattern pattern : m_include) {
if (pm.matches(pageName, pattern)) {
includeThis = true;
break;
}
}
}
if (m_exclude != null) {
for (final Pattern pattern : m_exclude) {
if (pm.matches(pageName, pattern)) {
includeThis = false;
// The inner loop, continue on the next item
break;
}
}
}
if (includeThis) {
result.add(pageName);
// if we want to show the last modified date of the most recently change page, we keep a "high watermark" here:
final Page page;
if (m_lastModified) {
page = m_engine.getManager(PageManager.class).getPage(pageName);
if (page != null) {
final Date lastModPage = page.getLastModified();
log.debug("lastModified Date of page {} : {}", pageName, m_dateLastModified);
if (lastModPage.after(m_dateLastModified)) {
m_dateLastModified = lastModPage;
}
}
}
}
}
return result;
}
use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class RegexUtil method parser.
public static String[] parser(String src, String regex) {
String patternStr = regex;
/**
* 编译正则表达式patternStr,并用该表达式与传入的src字符串进行模式匹配,
* 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回
* 该数组
*/
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
pattern = compiler.compile(patternStr, default_mask);
} catch (MalformedPatternException e) {
e.printStackTrace();
return null;
}
PatternMatcher matcher = new Perl5Matcher();
MatchResult result = null;
String[] tokens = null;
boolean match = matcher.matches(src, pattern);
if (match) {
result = matcher.getMatch();
int size = result.groups() - 1;
tokens = new String[size];
for (int i = 0; i < size; i++) {
tokens[i] = result.group(i + 1);
}
}
return tokens;
}
use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class RegexUtil method isMatch.
/**
* 检查src与正则表达式regex匹配结果
* @param src String
* @param regex String
* @return boolean
*/
public static boolean isMatch(String src, String regex) {
if (src == null)
return false;
boolean flag = false;
String patternStr = regex;
/**
* 编译正则表达式patternStr,并用该表达式与传入的src字符串进行模式匹配,
* 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回
* 该数组
*/
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
pattern = compiler.compile(patternStr, default_mask);
} catch (MalformedPatternException e) {
e.printStackTrace();
return false;
}
PatternMatcher matcher = new Perl5Matcher();
// log.debug("src:" + src);;
// log.debug("pattern:" + pattern);
// log.debug("regex:" + regex);
flag = matcher.matches(src, pattern);
return flag;
}
use of org.apache.oro.text.regex.Perl5Matcher in project bboss by bbossgroups.
the class RegexUtil method isContain.
public static boolean isContain(String src, String regex) {
if (src == null)
return false;
String patternStr = regex;
/**
* 编译正则表达式patternStr,并用该表达式与传入的src字符串进行模式匹配,
* 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回
* 该数组
*/
PatternCompiler compiler = new Perl5Compiler();
Pattern pattern = null;
try {
pattern = compiler.compile(patternStr, default_mask);
} catch (MalformedPatternException e) {
e.printStackTrace();
return false;
}
PatternMatcher matcher = new Perl5Matcher();
return matcher.contains(src, pattern);
}
Aggregations