Search in sources :

Example 71 with Perl5Matcher

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);
}
Also used : Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 72 with Perl5Matcher

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;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 73 with Perl5Matcher

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;
}
Also used : PluginException(org.apache.wiki.api.exceptions.PluginException) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) IOException(java.io.IOException) MatchResult(org.apache.oro.text.regex.MatchResult) InternalWikiException(org.apache.wiki.InternalWikiException) PluginManager(org.apache.wiki.api.engine.PluginManager) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) NoSuchElementException(java.util.NoSuchElementException)

Example 74 with Perl5Matcher

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;
}
Also used : PluginException(org.apache.wiki.api.exceptions.PluginException) ResourceBundle(java.util.ResourceBundle) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) IOException(java.io.IOException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) MatchResult(org.apache.oro.text.regex.MatchResult) NoSuchElementException(java.util.NoSuchElementException)

Example 75 with Perl5Matcher

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;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Aggregations

Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)88 Pattern (org.apache.oro.text.regex.Pattern)64 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)36 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)36 MatchResult (org.apache.oro.text.regex.MatchResult)32 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)32 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)20 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)17 ArrayList (java.util.ArrayList)16 IOException (java.io.IOException)8 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)7 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)5 PluginException (org.apache.wiki.api.exceptions.PluginException)5 MalformedURLException (java.net.MalformedURLException)4 NoSuchElementException (java.util.NoSuchElementException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SampleResult (org.apache.jmeter.samplers.SampleResult)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 PatternCacheLRU (org.apache.oro.text.PatternCacheLRU)3 BufferedReader (java.io.BufferedReader)2