use of org.apache.oro.text.regex.Perl5Matcher in project canal by alibaba.
the class RegexFunction method call.
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
String pattern = FunctionUtils.getStringValue(arg1, env);
String text = FunctionUtils.getStringValue(arg2, env);
Perl5Matcher matcher = new Perl5Matcher();
boolean isMatch = matcher.matches(text, PatternUtils.getPattern(pattern));
return AviatorBoolean.valueOf(isMatch);
}
use of org.apache.oro.text.regex.Perl5Matcher in project jspwiki by apache.
the class LinkParsingOperations method isImageLink.
/**
* Matches the given link to the list of image name patterns to
* determine whether it should be treated as an inline image or not.
*/
public boolean isImageLink(String link) {
if (wikiContext.getEngine().getRenderingManager().getParser(wikiContext, link).isImageInlining()) {
link = link.toLowerCase();
List<Pattern> inlineImagePatterns = wikiContext.getEngine().getRenderingManager().getParser(wikiContext, link).getInlineImagePatterns();
for (Pattern p : inlineImagePatterns) {
if (new Perl5Matcher().matches(link, p)) {
return true;
}
}
}
return false;
}
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(WikiContext context, String commandline, int pos) throws PluginException {
PatternMatcher matcher = new Perl5Matcher();
try {
PluginManager pm = context.getEngine().getPluginManager();
if (matcher.contains(commandline, pm.getPluginPattern())) {
MatchResult res = matcher.getMatch();
String plugin = res.group(2);
String args = commandline.substring(res.endOffset(0), commandline.length() - (commandline.charAt(commandline.length() - 1) == '}' ? 1 : 0));
Map<String, String> arglist = pm.parseArgs(args);
// set wikitext bounds of plugin as '_bounds' parameter, e.g., [345,396]
if (pos != -1) {
int end = pos + commandline.length() + 2;
String bounds = pos + "|" + end;
arglist.put(PluginManager.PARAM_BOUNDS, bounds);
}
PluginContent result = new PluginContent(plugin, arglist);
return result;
}
} catch (ClassCastException e) {
log.error("Invalid type offered in parsing plugin arguments.", e);
throw new InternalWikiException("Oops, someone offered !String!", e);
} catch (NoSuchElementException e) {
String msg = "Missing parameter in plugin definition: " + commandline;
log.warn(msg, e);
throw new PluginException(msg);
} catch (IOException e) {
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 DefaultPluginManager method execute.
/**
* Parses a plugin. Plugin commands are of the form:
* [{INSERT myplugin WHERE param1=value1, param2=value2}]
* myplugin may either be a class name or a plugin alias.
* <P>
* This is the main entry point that is used.
*
* @param context The current WikiContext.
* @param commandline The full command line, including plugin name, parameters and body.
*
* @return HTML as returned by the plugin, or possibly an error message.
*
* @throws PluginException From the plugin itself, it propagates, waah!
*/
public String execute(WikiContext context, String commandline) throws PluginException {
if (!m_pluginsEnabled) {
return "";
}
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
PatternMatcher matcher = new Perl5Matcher();
try {
if (matcher.contains(commandline, m_pluginPattern)) {
MatchResult res = matcher.getMatch();
String plugin = res.group(2);
String args = commandline.substring(res.endOffset(0), commandline.length() - (commandline.charAt(commandline.length() - 1) == '}' ? 1 : 0));
Map<String, String> arglist = parseArgs(args);
return execute(context, plugin, arglist);
}
} catch (NoSuchElementException e) {
String msg = "Missing parameter in plugin definition: " + commandline;
log.warn(msg, e);
throw new PluginException(MessageFormat.format(rb.getString("plugin.error.missingparameter"), commandline));
} catch (IOException e) {
String msg = "Zyrf. Problems with parsing arguments: " + commandline;
log.warn(msg, e);
throw new PluginException(MessageFormat.format(rb.getString("plugin.error.parsingarguments"), commandline));
}
// to be invisible, then we should return an empty string.
return commandline;
}
use of org.apache.oro.text.regex.Perl5Matcher 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;
}
Aggregations