svn commit: r1542960 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/ entity/src/org/ofbiz/entity/condition/ minilang/src/org/ofbiz/minilang/method/conditional/ minilang/src/org/ofbiz/minilang/operation/ widget/src/org/ofbiz/widget/menu/ widg...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1542960 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/ entity/src/org/ofbiz/entity/condition/ minilang/src/org/ofbiz/minilang/method/conditional/ minilang/src/org/ofbiz/minilang/operation/ widget/src/org/ofbiz/widget/menu/ widg...

jleroux@apache.org
Author: jleroux
Date: Mon Nov 18 09:46:35 2013
New Revision: 1542960

URL: http://svn.apache.org/r1542960
Log:
This closes "Introduce Tomcat's JreMemoryLeakPreventionListener and why" https://issues.apache.org/jira/browse/OFBIZ-5395
The idea is to avoid ThreadLocal with custom classes, this can lead to memory leaks when an external application server is used.
Reverts r1075322 (commit for OFBIZ-4107) hence removes CompilerMatcher
Uses PatternFactory instead of CompilerMatcher class (from CompilerMatcher keeps the compiled patterns cache idea)
In UtilHttp.java
  Removes dead code
  Removes useless "UtilHttp." for class methods and constants calls (moot point, have we conventions on this?).

Removed:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/CompilerMatcher.java
Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/operation/Regexp.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java?rev=1542960&r1=1542959&r2=1542960&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java Mon Nov 18 09:46:35 2013
@@ -52,6 +52,9 @@ import javolution.util.FastMap;
 
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.oro.text.regex.MalformedPatternException;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternMatcher;
+import org.apache.oro.text.regex.Perl5Matcher;
 import org.owasp.esapi.errors.EncodingException;
 import org.owasp.esapi.errors.IntrusionException;
 
@@ -550,9 +553,9 @@ public class UtilHttp {
             return;
         }
 
-        StringBuffer fullRequestUrl = UtilHttp.getFullRequestUrl(request);
+        StringBuffer fullRequestUrl = getFullRequestUrl(request);
 
-        session.setAttribute("_WEBAPP_NAME_", UtilHttp.getApplicationName(request));
+        session.setAttribute("_WEBAPP_NAME_", getApplicationName(request));
         session.setAttribute("_CLIENT_LOCALE_", request.getLocale());
         session.setAttribute("_CLIENT_REQUEST_", fullRequestUrl.toString());
         session.setAttribute("_CLIENT_USER_AGENT_", request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "");
@@ -586,7 +589,7 @@ public class UtilHttp {
     }
 
     public static StringBuffer getFullRequestUrl(HttpServletRequest request) {
-        StringBuffer requestUrl = UtilHttp.getServerRootUrl(request);
+        StringBuffer requestUrl = getServerRootUrl(request);
         requestUrl.append(request.getRequestURI());
         if (request.getQueryString() != null) {
             requestUrl.append("?" + request.getQueryString());
@@ -630,7 +633,7 @@ public class UtilHttp {
      */
     public static Locale getLocale(HttpServletRequest request) {
         if (request == null) return Locale.getDefault();
-        return UtilHttp.getLocale(request, request.getSession(), null);
+        return getLocale(request, request.getSession(), null);
     }
 
     /**
@@ -641,11 +644,11 @@ public class UtilHttp {
      */
     public static Locale getLocale(HttpSession session) {
         if (session == null) return Locale.getDefault();
-        return UtilHttp.getLocale(null, session, null);
+        return getLocale(null, session, null);
     }
 
     public static void setLocale(HttpServletRequest request, String localeString) {
-        UtilHttp.setLocale(request.getSession(), UtilMisc.parseLocale(localeString));
+        setLocale(request.getSession(), UtilMisc.parseLocale(localeString));
     }
 
     public static void setLocale(HttpSession session, Locale locale) {
@@ -654,12 +657,12 @@ public class UtilHttp {
 
     public static void setLocaleIfNone(HttpSession session, String localeString) {
         if (UtilValidate.isNotEmpty(localeString) && session.getAttribute("locale") == null) {
-            UtilHttp.setLocale(session, UtilMisc.parseLocale(localeString));
+            setLocale(session, UtilMisc.parseLocale(localeString));
         }
     }
 
     public static void setTimeZone(HttpServletRequest request, String tzId) {
-        UtilHttp.setTimeZone(request.getSession(), UtilDateTime.toTimeZone(tzId));
+        setTimeZone(request.getSession(), UtilDateTime.toTimeZone(tzId));
     }
 
     public static void setTimeZone(HttpSession session, TimeZone timeZone) {
@@ -768,8 +771,6 @@ public class UtilHttp {
                     col = Arrays.asList(value);
                 } else if (value instanceof Collection) {
                     col = UtilGenerics.cast(value);
-                } else if (value == null) {
-                    continue;
                 } else if (value.getClass().isArray()) {
                     col = Arrays.asList((Object[]) value);
                 } else {
@@ -1286,20 +1287,21 @@ public class UtilHttp {
         } else {
             String initialUserAgent = request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "";
             List<String> spiderList = StringUtil.split(UtilProperties.getPropertyValue("url", "link.remove_lsessionid.user_agent_list"), ",");
-            if (UtilValidate.isNotEmpty(spiderList)) {
 
-                CompilerMatcher compilerMatcher = new CompilerMatcher();
+            if (UtilValidate.isNotEmpty(spiderList)) {
                 for (String spiderNameElement : spiderList) {
+                    Pattern pattern = null;
                     try {
-                        if (compilerMatcher.matches(initialUserAgent, "^.*" + spiderNameElement + ".*$", false)) {
-                            request.setAttribute("_REQUEST_FROM_SPIDER_", "Y");
-                            result = true;
-                            break;
-                        }
-                    }
-                    catch (MalformedPatternException e) {
+                        pattern = PatternFactory.createOrGetPerl5CompiledPattern(spiderNameElement, false);
+                    } catch (MalformedPatternException e) {
                         Debug.logError(e, module);
                     }
+                    PatternMatcher matcher = new Perl5Matcher();
+                    if (matcher.contains(initialUserAgent, pattern)) {
+                        request.setAttribute("_REQUEST_FROM_SPIDER_", "Y");
+                        result = true;
+                        break;
+                    }
                 }
             }
         }
@@ -1327,7 +1329,7 @@ public class UtilHttp {
     /** Returns the number or rows submitted by a multi form.
      */
     public static int getMultiFormRowCount(HttpServletRequest request) {
-        return UtilHttp.getMultiFormRowCount(UtilHttp.getParameterMap(request));
+        return getMultiFormRowCount(getParameterMap(request));
     }
     /** Returns the number or rows submitted by a multi form.
      */
@@ -1335,9 +1337,9 @@ public class UtilHttp {
         // The number of multi form rows is computed selecting the maximum index
         int rowCount = 0;
         String maxRowIndex = "";
-        int rowDelimiterLength = UtilHttp.MULTI_ROW_DELIMITER.length();
+        int rowDelimiterLength = MULTI_ROW_DELIMITER.length();
         for (String parameterName: requestMap.keySet()) {
-            int rowDelimiterIndex = (parameterName != null? parameterName.indexOf(UtilHttp.MULTI_ROW_DELIMITER): -1);
+            int rowDelimiterIndex = (parameterName != null? parameterName.indexOf(MULTI_ROW_DELIMITER): -1);
             if (rowDelimiterIndex > 0) {
                 String thisRowIndex = parameterName.substring(rowDelimiterIndex + rowDelimiterLength);
                 if (thisRowIndex.indexOf("_") > -1) {
@@ -1368,7 +1370,7 @@ public class UtilHttp {
             paramMapStore = FastMap.newInstance();
             session.setAttribute("_PARAM_MAP_STORE_", paramMapStore);
         }
-        Map<String, Object> parameters = UtilHttp.getParameterMap(request);
+        Map<String, Object> parameters = getParameterMap(request);
         String paramMapId = RandomStringUtils.randomAlphanumeric(10);
         paramMapStore.put(paramMapId, parameters);
         return paramMapId;

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java?rev=1542960&r1=1542959&r2=1542960&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java Mon Nov 18 09:46:35 2013
@@ -23,9 +23,13 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.oro.text.perl.Perl5Util;
 import org.apache.oro.text.regex.MalformedPatternException;
-import org.ofbiz.base.util.CompilerMatcher;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternMatcher;
+import org.apache.oro.text.regex.Perl5Matcher;
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.PatternFactory;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
@@ -42,19 +46,23 @@ public abstract class EntityComparisonOp
 
     public static final String module = EntityComparisonOperator.class.getName();
 
-    protected transient static ThreadLocal<CompilerMatcher> compilerMatcher = CompilerMatcher.getThreadLocal();
-
-    public static String makeOroPattern(String sqlLike) {
+    public static Pattern makeOroPattern(String sqlLike) {
+        Perl5Util perl5Util = new Perl5Util();
         try {
-            sqlLike = compilerMatcher.get().substitute("s/([$^.+*?])/\\\\$1/g", sqlLike);
-            sqlLike = compilerMatcher.get().substitute("s/%/.*/g", sqlLike);
-            sqlLike = compilerMatcher.get().substitute("s/_/./g", sqlLike);
+            sqlLike = perl5Util.substitute("s/([$^.+*?])/\\\\$1/g", sqlLike);
+            sqlLike = perl5Util.substitute("s/%/.*/g", sqlLike);
+            sqlLike = perl5Util.substitute("s/_/./g", sqlLike);
         } catch (Throwable t) {
             String errMsg = "Error in ORO pattern substitution for SQL like clause [" + sqlLike + "]: " + t.toString();
             Debug.logError(t, errMsg, module);
             throw new IllegalArgumentException(errMsg);
         }
-        return sqlLike;
+        try {
+            return PatternFactory.createOrGetPerl5CompiledPattern(sqlLike, true);
+        } catch (MalformedPatternException e) {
+            Debug.logError(e, module);
+        }
+        return null;
     }
 
     @Override
@@ -258,19 +266,14 @@ public abstract class EntityComparisonOp
     }
 
     public static final <L,R> boolean compareLike(L lhs, R rhs) {
+        PatternMatcher matcher = new Perl5Matcher();
         if (lhs == null) {
             if (rhs != null) {
                 return false;
             }
         } else if (lhs instanceof String && rhs instanceof String) {
             //see if the lhs value is like the rhs value, rhs will have the pattern characters in it...
-            try {
-                return compilerMatcher.get().matches((String) lhs, makeOroPattern((String) rhs));
-            }
-            catch (MalformedPatternException e) {
-                Debug.logError(e, module);
-                return false;
-            }
+            return matcher.matches((String) lhs, makeOroPattern((String) rhs));
         }
         return true;
     }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java?rev=1542960&r1=1542959&r2=1542960&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java Mon Nov 18 09:46:35 2013
@@ -22,7 +22,11 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.oro.text.regex.MalformedPatternException;
-import org.ofbiz.base.util.CompilerMatcher;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternMatcher;
+import org.apache.oro.text.regex.Perl5Matcher;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.PatternFactory;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
@@ -44,7 +48,6 @@ import org.w3c.dom.Element;
 public class RegexpCondition extends MethodOperation implements Conditional {
 
     public static final String module = RegexpCondition.class.getName();
-    private transient static ThreadLocal<CompilerMatcher> compilerMatcher = CompilerMatcher.getThreadLocal();
 
     private final FlexibleMapAccessor<Object> fieldFma;
     private final FlexibleStringExpander exprFse;
@@ -88,11 +91,23 @@ public class RegexpCondition extends Met
             }
         }
         String regExp = exprFse.expandString(methodContext.getEnvMap());
+        Pattern pattern = null;
+
         try {
-            return compilerMatcher.get().matches((String) fieldVal, regExp);
+            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;
+        }
     }
 
     @Override
@@ -123,6 +138,7 @@ public class RegexpCondition extends Met
         }
     }
 
+    @Override
     public void prettyPrint(StringBuilder messageBuffer, MethodContext methodContext) {
         messageBuffer.append("regexp[");
         messageBuffer.append("[");

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/operation/Regexp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/operation/Regexp.java?rev=1542960&r1=1542959&r2=1542960&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/operation/Regexp.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/operation/Regexp.java Mon Nov 18 09:46:35 2013
@@ -23,10 +23,13 @@ import java.util.Locale;
 import java.util.Map;
 
 import org.apache.oro.text.regex.MalformedPatternException;
-import org.ofbiz.base.util.CompilerMatcher;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternMatcher;
+import org.apache.oro.text.regex.Perl5Matcher;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.PatternFactory;
 import org.w3c.dom.Element;
 
 /**
@@ -35,13 +38,17 @@ import org.w3c.dom.Element;
 public class Regexp extends SimpleMapOperation {
 
     public static final String module = Regexp.class.getName();
-    private transient static ThreadLocal<CompilerMatcher> compilerMatcher = CompilerMatcher.getThreadLocal();
-
+    private Pattern pattern = null;
     String expr;
 
     public Regexp(Element element, SimpleMapProcess simpleMapProcess) {
         super(element, simpleMapProcess);
         expr = element.getAttribute("expr");
+        try {
+            pattern = PatternFactory.createOrGetPerl5CompiledPattern(expr, true);
+        } catch (MalformedPatternException e) {
+            Debug.logError(e, module);
+        }
     }
 
     @Override
@@ -54,14 +61,12 @@ public class Regexp extends SimpleMapOpe
             messages.add("Could not convert field value for comparison: " + e.getMessage());
             return;
         }
-        boolean matches = false;
-        try {
-            matches = compilerMatcher.get().matches(fieldValue, expr);
-        } catch (MalformedPatternException e) {
-            Debug.logError(e, "Regular Expression [" + this.expr + "] is mal-formed: " + e.toString(), module);
+        if (pattern == null) {
+            messages.add("Could not compile regular expression \"" + expr + "\" for validation");
             return;
         }
-        if (!matches) {
+        PatternMatcher matcher = new Perl5Matcher();
+        if (!matcher.matches(fieldValue, pattern)) {
             addMessage(messages, loader, locale);
         }
     }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java?rev=1542960&r1=1542959&r2=1542960&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuCondition.java Mon Nov 18 09:46:35 2013
@@ -27,10 +27,13 @@ import java.util.TimeZone;
 import javolution.util.FastList;
 
 import org.apache.oro.text.regex.MalformedPatternException;
-import org.ofbiz.base.util.CompilerMatcher;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternMatcher;
+import org.apache.oro.text.regex.Perl5Matcher;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.PatternFactory;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
@@ -489,8 +492,6 @@ public class ModelMenuCondition {
     }
 
     public static class IfRegexp extends MenuCondition {
-        private transient static ThreadLocal<CompilerMatcher> compilerMatcher = CompilerMatcher.getThreadLocal();
-
         protected FlexibleMapAccessor<Object> fieldAcsr;
         protected FlexibleStringExpander exprExdr;
 
@@ -504,6 +505,16 @@ public class ModelMenuCondition {
         @Override
         public boolean eval(Map<String, Object> context) {
             Object fieldVal = this.fieldAcsr.get(context);
+            String expr = this.exprExdr.expandString(context);
+            Pattern pattern = null;
+
+            try {
+                pattern = PatternFactory.createOrGetPerl5CompiledPattern(expr, true);
+            } catch (MalformedPatternException e) {
+                String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString();
+                Debug.logError(e, errMsg, module);
+                throw new IllegalArgumentException(errMsg);
+            }
 
             String fieldString = null;
             try {
@@ -514,13 +525,8 @@ public class ModelMenuCondition {
             // always use an empty string by default
             if (fieldString == null) fieldString = "";
 
-            try {
-                return compilerMatcher.get().matches(fieldString, this.exprExdr.expandString(context));
-            } catch (MalformedPatternException e) {
-                String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString();
-                Debug.logError(e, errMsg, module);
-                throw new IllegalArgumentException(errMsg);
-            }
+            PatternMatcher matcher = new Perl5Matcher();
+            return matcher.matches(fieldString, pattern);
         }
     }
 

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java?rev=1542960&r1=1542959&r2=1542960&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java Mon Nov 18 09:46:35 2013
@@ -28,10 +28,13 @@ import java.util.TimeZone;
 import javolution.util.FastList;
 
 import org.apache.oro.text.regex.MalformedPatternException;
-import org.ofbiz.base.util.CompilerMatcher;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternMatcher;
+import org.apache.oro.text.regex.Perl5Matcher;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.PatternFactory;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
@@ -487,8 +490,6 @@ public class ModelScreenCondition implem
     }
 
     public static class IfRegexp extends ScreenCondition {
-        private transient static ThreadLocal<CompilerMatcher> compilerMatcher = CompilerMatcher.getThreadLocal();
-
         protected FlexibleMapAccessor<Object> fieldAcsr;
         protected FlexibleStringExpander exprExdr;
 
@@ -502,6 +503,16 @@ public class ModelScreenCondition implem
         @Override
         public boolean eval(Map<String, Object> context) {
             Object fieldVal = this.fieldAcsr.get(context);
+            String expr = this.exprExdr.expandString(context);
+            Pattern pattern;
+
+            try {
+                pattern = PatternFactory.createOrGetPerl5CompiledPattern(expr, true);
+            } catch (MalformedPatternException e) {
+                String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString();
+                Debug.logError(e, errMsg, module);
+                throw new IllegalArgumentException(errMsg);
+            }
 
             String fieldString = null;
             try {
@@ -512,13 +523,8 @@ public class ModelScreenCondition implem
             // always use an empty string by default
             if (fieldString == null) fieldString = "";
 
-            try {
-                return compilerMatcher.get().matches(fieldString, this.exprExdr.expandString(context));
-            } catch (MalformedPatternException e) {
-                String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString();
-                Debug.logError(e, errMsg, module);
-                throw new IllegalArgumentException(errMsg);
-            }
+            PatternMatcher matcher = new Perl5Matcher();
+            return matcher.matches(fieldString, pattern);
         }
     }
 

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java?rev=1542960&r1=1542959&r2=1542960&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTreeCondition.java Mon Nov 18 09:46:35 2013
@@ -27,10 +27,13 @@ import java.util.TimeZone;
 import javolution.util.FastList;
 
 import org.apache.oro.text.regex.MalformedPatternException;
-import org.ofbiz.base.util.CompilerMatcher;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.PatternMatcher;
+import org.apache.oro.text.regex.Perl5Matcher;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.PatternFactory;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
@@ -390,8 +393,6 @@ public class ModelTreeCondition {
     }
 
     public static class IfRegexp extends TreeCondition {
-        private transient static ThreadLocal<CompilerMatcher> compilerMatcher = CompilerMatcher.getThreadLocal();
-
         protected FlexibleMapAccessor<Object> fieldAcsr;
         protected FlexibleStringExpander exprExdr;
 
@@ -405,6 +406,16 @@ public class ModelTreeCondition {
         @Override
         public boolean eval(Map<String, ? extends Object> context) {
             Object fieldVal = this.fieldAcsr.get(context);
+            String expr = this.exprExdr.expandString(context);
+            Pattern pattern = null;
+
+            try {
+                pattern = PatternFactory.createOrGetPerl5CompiledPattern(expr, true);
+            } catch (MalformedPatternException e) {
+                String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString();
+                Debug.logError(e, errMsg, module);
+                throw new IllegalArgumentException(errMsg);
+            }
 
             String fieldString = null;
             try {
@@ -415,13 +426,8 @@ public class ModelTreeCondition {
             // always use an empty string by default
             if (fieldString == null) fieldString = "";
 
-            try {
-                return compilerMatcher.get().matches(fieldString, this.exprExdr.expandString(context));
-            } catch (MalformedPatternException e) {
-                String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString();
-                Debug.logError(e, errMsg, module);
-                throw new IllegalArgumentException(errMsg);
-            }
+            PatternMatcher matcher = new Perl5Matcher();
+            return matcher.matches(fieldString, pattern);
         }
     }