use of org.apache.oro.text.regex.Pattern in project ofbiz-framework by apache.
the class UrlRegexpTransform method forwardUri.
/**
* Forward a uri according to forward pattern regular expressions. Note: this is developed for Filter usage.
*
* @param uri
* String to reverse transform
* @return String
*/
public static boolean forwardUri(HttpServletResponse response, String uri) {
Perl5Matcher matcher = new Perl5Matcher();
boolean foundMatch = false;
Integer responseCodeInt = null;
if (SeoConfigUtil.checkUseUrlRegexp() && SeoConfigUtil.getSeoPatterns() != null && SeoConfigUtil.getForwardReplacements() != null) {
Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
String replacement = SeoConfigUtil.getForwardReplacements().get(key);
if (matcher.matches(uri, pattern)) {
for (int i = 1; i < matcher.getMatch().groups(); i++) {
replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
}
// break if found any matcher
uri = replacement;
responseCodeInt = SeoConfigUtil.getForwardResponseCodes().get(key);
foundMatch = true;
break;
}
}
}
if (foundMatch) {
if (responseCodeInt == null) {
response.setStatus(SeoConfigUtil.getDefaultResponseCode());
} else {
response.setStatus(responseCodeInt.intValue());
}
response.setHeader("Location", uri);
} else {
Debug.logInfo("Can NOT forward this url: " + uri, module);
}
return foundMatch;
}
use of org.apache.oro.text.regex.Pattern in project ofbiz-framework by apache.
the class SeoContextFilter method forwardUri.
/**
* Forward a uri according to forward pattern regular expressions. Note: this is developed for Filter usage.
*
* @param uri String to reverse transform
* @return String
*/
protected static boolean forwardUri(HttpServletResponse response, String uri) {
Perl5Matcher matcher = new Perl5Matcher();
boolean foundMatch = false;
Integer responseCodeInt = null;
if (SeoConfigUtil.checkUseUrlRegexp() && SeoConfigUtil.getSeoPatterns() != null && SeoConfigUtil.getForwardReplacements() != null) {
Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
String replacement = SeoConfigUtil.getForwardReplacements().get(key);
if (matcher.matches(uri, pattern)) {
for (int i = matcher.getMatch().groups(); i > 0; i--) {
replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
}
uri = replacement;
responseCodeInt = SeoConfigUtil.getForwardResponseCodes().get(key);
foundMatch = true;
// be careful, we don't break after finding a match
}
}
}
if (foundMatch) {
if (responseCodeInt == null) {
response.setStatus(SeoConfigUtil.getDefaultResponseCode());
} else {
response.setStatus(responseCodeInt.intValue());
}
response.setHeader("Location", uri);
} else {
Debug.logInfo("Can NOT forward this url: " + uri, module);
}
return foundMatch;
}
use of org.apache.oro.text.regex.Pattern in project jmeter by apache.
the class JSONPathAssertion method isEquals.
private boolean isEquals(Object subj) {
if (isUseRegex()) {
String str = objectToString(subj);
Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue());
return JMeterUtils.getMatcher().matches(str, pattern);
} else {
Object expected = JSONValue.parse(getExpectedValue());
return Objects.equals(expected, subj);
}
}
use of org.apache.oro.text.regex.Pattern 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;
}
use of org.apache.oro.text.regex.Pattern in project jmeter by apache.
the class HtmlParsingUtils method extractStyleURLs.
public static void extractStyleURLs(final URL baseUrl, final URLCollection urls, String styleTagStr) {
Perl5Matcher matcher = JMeterUtils.getMatcher();
Pattern pattern = JMeterUtils.getPatternCache().getPattern(// $NON-NLS-1$
"URL\\(\\s*('|\")(.*)('|\")\\s*\\)", Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK);
PatternMatcherInput input;
input = new PatternMatcherInput(styleTagStr);
while (matcher.contains(input, pattern)) {
MatchResult match = matcher.getMatch();
// The value is in the second group
String styleUrl = match.group(2);
urls.addURL(styleUrl, baseUrl);
}
}
Aggregations