tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschu...@apache.org
Subject svn commit: r614655 - in /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator: Email.java Pattern.java
Date Wed, 23 Jan 2008 20:36:12 GMT
Author: mschulte
Date: Wed Jan 23 12:36:08 2008
New Revision: 614655

URL: http://svn.apache.org/viewvc?rev=614655&view=rev
Log:
fixes TAPESTRY-2071, don't use a pattern-pool for each validator instance.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java?rev=614655&r1=614654&r2=614655&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
Wed Jan 23 12:36:08 2008
@@ -21,7 +21,6 @@
 import org.apache.tapestry.form.ValidationMessages;
 import org.apache.tapestry.json.JSONLiteral;
 import org.apache.tapestry.json.JSONObject;
-import org.apache.tapestry.util.RegexpMatcher;
 import org.apache.tapestry.valid.ValidationConstants;
 import org.apache.tapestry.valid.ValidationConstraint;
 import org.apache.tapestry.valid.ValidationStrings;
@@ -49,13 +48,9 @@
     public static final String DOMAIN_PATTERN = "([0-9a-z]([-0-9a-z]{0,61}[0-9a-z])?\\.)+"
+ "(" + TLD_PATTERN + ")";
     public static final String USERNAME_PATTERN = "([-/!\\#$*?=_+&'\\da-z]+[.])*[-/!\\#$*?=_+&'\\da-z]+";
     public static final String PATTERN = "^(?i)"+ USERNAME_PATTERN + "@" + "(" + DOMAIN_PATTERN
+ ")$";
-                
-    // TODO: Possible thread safety issue if the validator
-    // is shared across threads, because the matcher
-    // will be too.
-    
-    private RegexpMatcher _matcher = new RegexpMatcher();
-    
+
+    private static final java.util.regex.Pattern PATTERN_COMPILED = java.util.regex.Pattern.compile(PATTERN);
+
     public Email()
     {
     }
@@ -70,7 +65,7 @@
     {
         String input = (String) object;
 
-        if (!_matcher.matches(PATTERN, input))
+        if ( !PATTERN_COMPILED.matcher(input).matches() )
             throw new ValidatorException(buildMessage(messages, field),
                     ValidationConstraint.EMAIL_FORMAT);
     }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java?rev=614655&r1=614654&r2=614655&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java
Wed Jan 23 12:36:08 2008
@@ -21,11 +21,11 @@
 import org.apache.tapestry.form.ValidationMessages;
 import org.apache.tapestry.json.JSONLiteral;
 import org.apache.tapestry.json.JSONObject;
-import org.apache.tapestry.util.RegexpMatcher;
 import org.apache.tapestry.valid.ValidationConstants;
 import org.apache.tapestry.valid.ValidationConstraint;
 import org.apache.tapestry.valid.ValidationStrings;
 import org.apache.tapestry.valid.ValidatorException;
+import org.apache.oro.text.regex.Perl5Compiler;
 
 /**
  * Validates a user input string against a regular expression pattern.
@@ -38,10 +38,10 @@
 {
     // It is expectd that each Pattern instance will be used by a single component instance,
     // and therefore be restricted to a single thread.
-    
-    private RegexpMatcher _matcher = new RegexpMatcher();
 
     private String _pattern;
+    private String _quotedPattern;
+    private java.util.regex.Pattern _compiledPattern;
 
     public Pattern()
     {
@@ -57,7 +57,7 @@
     {
         String input = (String) object;
 
-        if (!_matcher.matches(_pattern, input))
+        if (! _compiledPattern.matcher(input).matches() )
             throw new ValidatorException(buildMessage(messages, field),
                     ValidationConstraint.PATTERN_MISMATCH);
     }
@@ -74,9 +74,7 @@
     public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
             FormComponentContributorContext context, IFormComponent field)
     {
-        String pattern = _matcher.getEscapedPatternString(_pattern);
-        
-        JSONObject profile = context.getProfile();
+       JSONObject profile = context.getProfile();
         
         if (!profile.has(ValidationConstants.CONSTRAINTS)) {
             profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
@@ -85,7 +83,7 @@
         
         accumulateProperty(cons, field.getClientId(), 
                 new JSONLiteral("[tapestry.form.validation.isValidPattern,\""
-                        + pattern + "\"]"));
+                        + _quotedPattern + "\"]"));
         
         accumulateProfileProperty(field, profile, 
                 ValidationConstants.CONSTRAINTS, buildMessage(context, field));
@@ -94,6 +92,8 @@
     public void setPattern(String pattern)
     {
         _pattern = pattern;
+        _compiledPattern = java.util.regex.Pattern.compile(pattern);
+        _quotedPattern =  Perl5Compiler.quotemeta(_pattern);
     }
 
     public String getPattern()



Mime
View raw message