use of org.apache.oro.text.regex.PatternMatcher in project tdi-studio-se by Talend.
the class NodeQueryCheckUtil method apacheRegexMatch.
/**
* See bug 5836. java.util.regex works too slow here. Use apache oro regex library instead.
* <p>
* DOC xye Comment method "apacheRegexMatch".
*
* @param patternString
* @param flag
* @param input
* @return
*/
private static boolean apacheRegexMatch(final String patternString, final int flag, final String input) {
PatternCompiler pc = new Perl5Compiler();
org.apache.oro.text.regex.Pattern pattern = null;
try {
pattern = pc.compile(patternString, flag);
PatternMatcher columnMatcher = new Perl5Matcher();
return columnMatcher.matches(input, pattern);
} catch (MalformedPatternException e) {
return false;
}
}
use of org.apache.oro.text.regex.PatternMatcher in project tdi-studio-se by Talend.
the class MapperComponent method hasOrRenameData.
/**
*
* DOC amaumont Comment method "hasOrRenameData".
*
* @param oldName
* @param newName can be null if <code>renameAction</code> is false
* @param renameAction true to rename in all expressions, false to get boolean if present in one of the expressions
* @return
*/
@Override
protected boolean hasOrRenameData(String oldName, String newName, boolean renameAction) {
if (oldName == null || newName == null && renameAction) {
throw new NullPointerException();
}
if (externalData != null) {
List<ExternalMapperTable> tables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
tables.addAll(externalData.getOutputTables());
if (externalData.getVarsTables() != null) {
tables.addAll(externalData.getVarsTables());
}
for (ExternalMapperTable table : tables) {
if (table.getExpressionFilter() != null) {
Pattern pattern = getRenamePattern(oldName);
if (pattern != null) {
PatternMatcher matcher = new Perl5Matcher();
((Perl5Matcher) matcher).setMultiline(true);
if (renameAction) {
Perl5Substitution substitution = getRenameSubstitution(newName);
String expression = renameDataIntoExpression(pattern, matcher, substitution, table.getExpressionFilter());
table.setExpressionFilter(expression);
} else {
if (hasDataIntoExpression(pattern, matcher, table.getExpressionFilter())) {
return true;
}
}
}
}
List<ExternalMapperTableEntry> metadataTableEntries = table.getMetadataTableEntries();
if (metadataTableEntries != null) {
// loop on all entries of current table
for (ExternalMapperTableEntry entry : metadataTableEntries) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
// for (ExternalMapperTableEntry entry : metadataTableEntries) {
}
if (table.getConstraintTableEntries() != null) {
for (ExternalMapperTableEntry entry : table.getConstraintTableEntries()) {
if (hasOrRenameEntry(entry, oldName, newName, renameAction)) {
// existed
return true;
}
}
}
}
}
return false;
}
use of org.apache.oro.text.regex.PatternMatcher 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;
}
use of org.apache.oro.text.regex.PatternMatcher 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 Collection filterCollection(Collection c) {
ArrayList<Object> result = new ArrayList<Object>();
PatternMatcher pm = new Perl5Matcher();
for (Iterator i = c.iterator(); i.hasNext(); ) {
String pageName = null;
Object objectje = i.next();
if (objectje instanceof WikiPage) {
pageName = ((WikiPage) objectje).getName();
} else {
pageName = (String) objectje;
}
//
// 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 (int j = 0; j < m_include.length; j++) {
if (pm.matches(pageName, m_include[j])) {
includeThis = true;
break;
}
}
}
if (m_exclude != null) {
for (int j = 0; j < m_exclude.length; j++) {
if (pm.matches(pageName, m_exclude[j])) {
includeThis = false;
// The inner loop, continue on the next item
break;
}
}
}
if (includeThis) {
if (objectje instanceof WikiPage) {
result.add(objectje);
} else {
result.add(pageName);
}
//
// if we want to show the last modified date of the most recently change page, we keep a "high watermark" here:
WikiPage page = null;
if (m_lastModified) {
page = m_engine.getPage(pageName);
if (page != null) {
Date lastModPage = page.getLastModified();
if (log.isDebugEnabled()) {
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.PatternMatcher in project ofbiz-framework by apache.
the class RegexpCondition method checkCondition.
@Override
public boolean checkCondition(MethodContext methodContext) throws MiniLangException {
Object fieldVal = fieldFma.get(methodContext.getEnvMap());
if (fieldVal == null) {
fieldVal = "";
} else if (!(fieldVal instanceof String)) {
try {
fieldVal = MiniLangUtil.convertType(fieldVal, String.class, methodContext.getLocale(), methodContext.getTimeZone(), null);
} catch (Exception e) {
throw new MiniLangRuntimeException(e, this);
}
}
String regExp = exprFse.expandString(methodContext.getEnvMap());
Pattern pattern = null;
try {
pattern = PatternFactory.createOrGetPerl5CompiledPattern(regExp, true);
} catch (MalformedPatternException e) {
Debug.logError(e, "Regular Expression [" + regExp + "] is mal-formed: " + e.toString(), module);
throw new MiniLangRuntimeException(e, this);
}
PatternMatcher matcher = new Perl5Matcher();
if (matcher.matches((String) fieldVal, pattern)) {
// Debug.logInfo("The string [" + fieldVal + "] matched the pattern expr [" + pattern.getPattern() + "]", module);
return true;
} else {
// Debug.logInfo("The string [" + fieldVal + "] did NOT match the pattern expr [" + pattern.getPattern() + "]", module);
return false;
}
}
Aggregations