use of org.apache.oro.text.regex.Perl5Matcher 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.Perl5Matcher in project otter by alibaba.
the class ConfigHelper method parseMode.
/**
* 解析DataMedia中的namespace和name,支持offer[1-128]分库的定义
*/
public static ModeValue parseMode(String value) {
PatternMatcher matcher = new Perl5Matcher();
if (matcher.matches(value, patterns.get(MODE_PATTERN))) {
MatchResult matchResult = matcher.getMatch();
String prefix = matchResult.group(1);
String startStr = matchResult.group(3);
String ednStr = matchResult.group(4);
int start = Integer.valueOf(startStr);
int end = Integer.valueOf(ednStr);
String postfix = matchResult.group(5);
List<String> values = new ArrayList<String>();
for (int i = start; i <= end; i++) {
StringBuilder builder = new StringBuilder(value.length());
String str = String.valueOf(i);
// 处理0001类型
if (startStr.length() == ednStr.length() && startStr.startsWith("0")) {
str = StringUtils.leftPad(String.valueOf(i), startStr.length(), '0');
}
builder.append(prefix).append(str).append(postfix);
values.add(builder.toString());
}
return new ModeValue(Mode.MULTI, values);
} else if (isWildCard(value)) {
// 通配符支持
return new ModeValue(Mode.WILDCARD, Arrays.asList(value));
} else {
return new ModeValue(Mode.SINGLE, Arrays.asList(value));
}
}
use of org.apache.oro.text.regex.Perl5Matcher in project otter by alibaba.
the class ActionProtectedImpl method check.
public boolean check(String action, String method) {
if (!StringUtil.isBlank(action)) {
PatternMatcher matcher = new Perl5Matcher();
Iterator<ActionPatternHolder> iter = actionPatternList.iterator();
while (iter.hasNext()) {
ActionPatternHolder holder = (ActionPatternHolder) iter.next();
if (StringUtils.isNotEmpty(action) && matcher.matches(action, holder.getActionPattern()) && StringUtils.isNotEmpty(method) && matcher.matches(method, holder.getMethodPattern())) {
if (logger.isDebugEnabled()) {
logger.debug("Candidate is: '" + action + "|" + method + "'; pattern is " + holder.getActionName() + "|" + holder.getMethodName() + "; matched=true");
}
return true;
}
}
}
return false;
}
use of org.apache.oro.text.regex.Perl5Matcher in project otter by alibaba.
the class URLProtectedImpl method check.
public boolean check(String requestUrl) {
if (StringUtils.isBlank(requestUrl)) {
return false;
}
if (logger.isDebugEnabled()) {
logger.debug("Converted URL to lowercase, from: '" + requestUrl + "'; to: '" + requestUrl + "'");
}
PatternMatcher matcher = new Perl5Matcher();
Iterator<URLPatternHolder> iter = urlProtectedList.iterator();
while (iter.hasNext()) {
URLPatternHolder holder = (URLPatternHolder) iter.next();
if (matcher.matches(requestUrl, holder.getCompiledPattern())) {
if (logger.isDebugEnabled()) {
logger.debug("Candidate is: '" + requestUrl + "'; pattern is " + holder.getCompiledPattern().getPattern() + "; matched=true");
}
return true;
}
}
return false;
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class CSVSaveService method getSampleSaveConfiguration.
/**
* Parse a CSV header line
*
* @param headerLine
* from CSV file
* @param filename
* name of file (for log message only)
* @return config corresponding to the header items found or null if not a
* header line
*/
public static SampleSaveConfiguration getSampleSaveConfiguration(String headerLine, String filename) {
// Try
String[] parts = splitHeader(headerLine, _saveConfig.getDelimiter());
// default
// delimiter
String delim = null;
if (parts == null) {
Perl5Matcher matcher = JMeterUtils.getMatcher();
PatternMatcherInput input = new PatternMatcherInput(headerLine);
Pattern pattern = JMeterUtils.getPatternCache().getPattern(// $NON-NLS-1$
"\\w+((\\W)\\w+)?(\\2\\w+)*(\\2\"\\w+\")*", // last entries may be quoted strings
Perl5Compiler.READ_ONLY_MASK);
if (matcher.matches(input, pattern)) {
delim = matcher.getMatch().group(2);
// now validate the
parts = splitHeader(headerLine, delim);
// result
}
}
if (parts == null) {
// failed to recognise the header
return null;
}
// We know the column names all exist, so create the config
SampleSaveConfiguration saveConfig = new SampleSaveConfiguration(false);
int varCount = 0;
for (String label : parts) {
if (isVariableName(label)) {
varCount++;
} else {
Functor set = headerLabelMethods.get(label);
set.invoke(saveConfig, new Boolean[] { Boolean.TRUE });
}
}
if (delim != null) {
if (log.isWarnEnabled()) {
log.warn("Default delimiter '{}' did not work; using alternate '{}' for reading {}", _saveConfig.getDelimiter(), delim, filename);
}
saveConfig.setDelimiter(delim);
}
saveConfig.setVarCount(varCount);
return saveConfig;
}
Aggregations