Search in sources :

Example 1 with MalformedPatternException

use of org.apache.oro.text.regex.MalformedPatternException in project otter by alibaba.

the class ConfigHelperTest method testWildCard.

@Test
public void testWildCard() {
    PatternMatcher matcher = new Perl5Matcher();
    Pattern pattern = null;
    PatternCompiler pc = new Perl5Compiler();
    try {
        pattern = pc.compile("havana_us_.*", Perl5Compiler.DEFAULT_MASK);
    } catch (MalformedPatternException e) {
        throw new ConfigException(e);
    }
    boolean ismatch = matcher.matches("havana_us_0001", pattern);
    System.out.println(ismatch);
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.shared.common.BaseOtterTest)

Example 2 with MalformedPatternException

use of org.apache.oro.text.regex.MalformedPatternException in project otter by alibaba.

the class ActionProtectedEditor method convertStringToPattern.

/**
     * 把字符串转成Pattern和UrlType
     * 
     * @param perl5RegExp
     * @return
     */
private ActionPatternHolder convertStringToPattern(String line) {
    ActionPatternHolder holder = new ActionPatternHolder();
    String[] strs = org.apache.commons.lang.StringUtils.split(line, "|");
    if (strs.length != 2) {
        throw new IllegalArgumentException("illegal expression: " + line);
    }
    Pattern compiledPattern;
    Perl5Compiler compiler = new Perl5Compiler();
    try {
        holder.setActionName(strs[0]);
        compiledPattern = compiler.compile(strs[0], Perl5Compiler.READ_ONLY_MASK);
        holder.setActionPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + strs[0]);
    }
    try {
        holder.setMethodName(strs[1]);
        compiledPattern = compiler.compile(strs[1], Perl5Compiler.READ_ONLY_MASK);
        holder.setMethodPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + strs[1]);
    }
    return holder;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 3 with MalformedPatternException

use of org.apache.oro.text.regex.MalformedPatternException in project otter by alibaba.

the class URLProtectedEditor method convertStringToPattern.

/**
     * 把字符串转成Pattern和UrlType
     * 
     * @param perl5RegExp
     * @return
     */
private URLPatternHolder convertStringToPattern(String line) {
    URLPatternHolder holder = new URLPatternHolder();
    Pattern compiledPattern;
    Perl5Compiler compiler = new Perl5Compiler();
    String perl5RegExp = line;
    try {
        compiledPattern = compiler.compile(perl5RegExp, Perl5Compiler.READ_ONLY_MASK);
        holder.setCompiledPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + perl5RegExp);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Added regular expression: " + compiledPattern.getPattern().toString());
    }
    return holder;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 4 with MalformedPatternException

use of org.apache.oro.text.regex.MalformedPatternException in project tdi-studio-se by Talend.

the class JavaRoutineSynchronizer method renamePigudfClass.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.codegen.AbstractRoutineSynchronizer#renamePigudfClass(org.talend.core.model.properties.
     * RoutineItem)
     */
@Override
public void renamePigudfClass(PigudfItem pigudfItem, String oldLabel) {
    if (pigudfItem == null) {
        return;
    }
    String routineContent = new String(pigudfItem.getContent().getInnerContent());
    String label = pigudfItem.getProperty().getLabel();
    //
    Perl5Matcher matcher = new Perl5Matcher();
    Perl5Compiler compiler = new Perl5Compiler();
    PatternMatcherInput patternMatcherInput = new PatternMatcherInput(routineContent);
    //$NON-NLS-1$//$NON-NLS-2$
    String regx = "public(\\s)+class(\\s)+" + oldLabel + "(\\s)(.+)\\{";
    String extendsText = "";
    try {
        org.apache.oro.text.regex.Pattern pattern = compiler.compile(regx);
        boolean contains = matcher.contains(patternMatcherInput, pattern);
        if (contains) {
            org.apache.oro.text.regex.MatchResult matchResult = matcher.getMatch();
            extendsText = matchResult.group(matchResult.groups() - 1);
        }
        //$NON-NLS-1$
        String regexp = "public(\\s)+class(\\s)+\\w+(\\s)\\{";
        if (extendsText != null) {
            extendsText = extendsText.trim();
            //$NON-NLS-1$//$NON-NLS-2$
            regexp = "public(\\s)+class(\\s)+\\w+(\\s)+" + extendsText + "(\\s)*\\{";
        }
        // rename class name
        //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        routineContent = routineContent.replaceFirst(regexp, "public class " + label + " " + extendsText + " {");
        // rename constructor
        String constructorRegx = "(\\s+)" + oldLabel + "(\\((.*)\\))";
        String toReplace = "$1" + label + "$1$2";
        pattern = compiler.compile(constructorRegx);
        Perl5Substitution substitution = new Perl5Substitution(toReplace, Perl5Substitution.INTERPOLATE_ALL);
        routineContent = Util.substitute(matcher, pattern, substitution, routineContent, Util.SUBSTITUTE_ALL);
    } catch (MalformedPatternException e) {
        ExceptionHandler.process(new Exception("Rename pigudf failed"));
    }
    pigudfItem.getContent().setInnerContent(routineContent.getBytes());
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) CoreException(org.eclipse.core.runtime.CoreException) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) IOException(java.io.IOException) SystemException(org.talend.commons.exception.SystemException) Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 5 with MalformedPatternException

use of org.apache.oro.text.regex.MalformedPatternException in project tdi-studio-se by Talend.

the class MapDataDelegateHelper method matchExpression.

private boolean matchExpression(String regex, String expression) {
    PatternCompiler compiler = new Perl5Compiler();
    try {
        //$NON-NLS-1$ //$NON-NLS-2$
        Pattern pattern = compiler.compile("\\b(" + UpdateContextVariablesHelper.replaceSpecialChar(regex) + ")(\\b|\\_)");
        PatternMatcher matcher = new Perl5Matcher();
        ((Perl5Matcher) matcher).setMultiline(true);
        if (matcher.contains(expression, pattern)) {
            return true;
        }
    } catch (MalformedPatternException e) {
    //
    }
    return false;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Aggregations

MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)24 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)22 Pattern (org.apache.oro.text.regex.Pattern)20 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)19 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)8 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)5 IOException (java.io.IOException)3 MatchResult (org.apache.oro.text.regex.MatchResult)3 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 BufferedReader (java.io.BufferedReader)2 EOFException (java.io.EOFException)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 MalformedURLException (java.net.MalformedURLException)2 Charset (java.nio.charset.Charset)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2