use of org.apache.oro.text.regex.Perl5Matcher in project ofbiz-framework by apache.
the class CatalogUrlSeoTransform method initCategoryMap.
public static synchronized void initCategoryMap(HttpServletRequest request, Delegator delegator) {
if (SeoConfigUtil.checkCategoryUrl()) {
categoryNameIdMap = new Hashtable<>();
categoryIdNameMap = new Hashtable<>();
Perl5Matcher matcher = new Perl5Matcher();
try {
Collection<GenericValue> allCategories = delegator.findList("ProductCategory", null, UtilMisc.toSet("productCategoryId", "categoryName"), null, null, false);
for (GenericValue category : allCategories) {
String categoryName = category.getString("categoryName");
String categoryNameId = null;
String categoryIdName = null;
String categoryId = category.getString("productCategoryId");
if (UtilValidate.isNotEmpty(categoryName)) {
categoryName = SeoUrlUtil.replaceSpecialCharsUrl(categoryName.trim());
if (matcher.matches(categoryName, asciiPattern)) {
categoryIdName = categoryName.replaceAll(" ", URL_HYPHEN);
categoryNameId = categoryIdName + URL_HYPHEN + categoryId.trim().replaceAll(" ", URL_HYPHEN);
} else {
categoryIdName = categoryId.trim().replaceAll(" ", URL_HYPHEN);
categoryNameId = categoryIdName;
}
} else {
GenericValue productCategory = EntityQuery.use(delegator).from("ProductCategory").where("productCategoryId", categoryId).cache().queryOne();
CategoryContentWrapper wrapper = new CategoryContentWrapper(productCategory, request);
StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL", "url");
if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) {
categoryIdName = SeoUrlUtil.replaceSpecialCharsUrl(alternativeUrl.toString());
categoryNameId = categoryIdName + URL_HYPHEN + categoryId.trim().replaceAll(" ", URL_HYPHEN);
} else {
categoryNameId = categoryId.trim().replaceAll(" ", URL_HYPHEN);
categoryIdName = categoryNameId;
}
}
if (categoryNameIdMap.containsKey(categoryNameId)) {
categoryNameId = categoryId.trim().replaceAll(" ", URL_HYPHEN);
categoryIdName = categoryNameId;
}
if (!matcher.matches(categoryNameId, asciiPattern) || categoryNameIdMap.containsKey(categoryNameId)) {
continue;
}
categoryNameIdMap.put(categoryNameId, categoryId);
categoryIdNameMap.put(categoryId, categoryIdName);
}
} catch (GenericEntityException e) {
Debug.logError(e, MODULE);
}
}
categoryMapInitialed = true;
}
use of org.apache.oro.text.regex.Perl5Matcher 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);
}
response.setHeader("Location", uri);
} else {
Debug.logInfo("Can NOT forward this url: " + uri, MODULE);
}
return foundMatch;
}
use of org.apache.oro.text.regex.Perl5Matcher in project ofbiz-framework by apache.
the class UrlRegexpTransform method seoUrl.
/**
* Transform a url according to seo pattern regular expressions.
* @param url
* String to do the seo transform
* @param isAnon
* boolean to indicate whether it's an anonymous visit.
* @return String the transformed url.
*/
public static String seoUrl(String url, boolean isAnon) {
Perl5Matcher matcher = new Perl5Matcher();
if (SeoConfigUtil.checkUseUrlRegexp() && matcher.matches(url, SeoConfigUtil.getGeneralRegexpPattern())) {
Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
boolean foundMatch = false;
while (keys.hasNext()) {
String key = keys.next();
Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
if (pattern.getPattern().contains(";jsessionid=")) {
if (isAnon) {
if (SeoConfigUtil.isJSessionIdAnonEnabled()) {
continue;
}
} else {
if (SeoConfigUtil.isJSessionIdUserEnabled()) {
continue;
}
boolean foundException = false;
for (int i = 0; i < SeoConfigUtil.getUserExceptionPatterns().size(); i++) {
if (matcher.matches(url, SeoConfigUtil.getUserExceptionPatterns().get(i))) {
foundException = true;
break;
}
}
if (foundException) {
continue;
}
}
}
String replacement = SeoConfigUtil.getSeoReplacements().get(key);
if (matcher.matches(url, pattern)) {
for (int i = 1; i < matcher.getMatch().groups(); i++) {
replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
}
// break if found any matcher
url = replacement;
foundMatch = true;
break;
}
}
if (!foundMatch) {
if (Debug.verboseOn()) {
Debug.logVerbose("Can NOT find a seo transform pattern for this url: " + url, MODULE);
}
}
}
return url;
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class SessionFilter method getIpAddress.
protected String getIpAddress(String logLine) {
Pattern incIp = JMeterUtils.getPatternCache().getPattern("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
Perl5Matcher matcher = JMeterUtils.getMatcher();
matcher.contains(logLine, incIp);
return matcher.getMatch().group(0);
}
use of org.apache.oro.text.regex.Perl5Matcher in project jmeter by apache.
the class HttpMirrorThread method getRequestHeaderValue.
private static String getRequestHeaderValue(String requestHeaders, String headerName) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
// We use multi-line mask so can prefix the line with ^
// $NON-NLS-1$ $NON-NLS-2$
String expression = "^" + headerName + ":\\s+([^\\r\\n]+)";
Pattern pattern = JMeterUtils.getPattern(expression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
if (localMatcher.contains(requestHeaders, pattern)) {
// The value is in the first group, group 0 is the whole match
return localMatcher.getMatch().group(1);
} else {
return null;
}
}
Aggregations