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);
}
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;
}
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;
}
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());
}
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;
}
Aggregations