You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ms...@apache.org on 2008/01/29 18:06:10 UTC
svn commit: r616448 -
/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java
Author: mschulte
Date: Tue Jan 29 09:06:09 2008
New Revision: 616448
URL: http://svn.apache.org/viewvc?rev=616448&view=rev
Log:
fixes TAPESTRY-2071: don't use a throw-away commons-pool
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java?rev=616448&r1=616447&r2=616448&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/ValidatorFactoryImpl.java Tue Jan 29 09:06:09 2008
@@ -19,13 +19,12 @@
import org.apache.hivemind.util.Defense;
import org.apache.hivemind.util.PropertyUtils;
import org.apache.tapestry.IComponent;
-import org.apache.tapestry.util.RegexpMatch;
-import org.apache.tapestry.util.RegexpMatcher;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.regex.Matcher;
/**
* Implementation of the tapestry.form.validator.ValidatorFactory service, which builds and caches
@@ -37,6 +36,7 @@
public class ValidatorFactoryImpl implements ValidatorFactory
{
private static final String PATTERN = "^\\s*(\\$?\\w+)\\s*(=\\s*(((?!,|\\[).)*))?";
+ private static final java.util.regex.Pattern PATTERN_COMPILED = java.util.regex.Pattern.compile(PATTERN);
/**
* Injected map of validator names to ValidatorContribution.
@@ -54,8 +54,6 @@
List result = new ArrayList();
String chopped = specification;
- RegexpMatcher matcher = new RegexpMatcher();
-
while (true)
{
if (chopped.length() == 0)
@@ -64,24 +62,22 @@
if (!result.isEmpty())
{
if (chopped.charAt(0) != ',')
- throw new ApplicationRuntimeException(ValidatorMessages
- .badSpecification(specification));
+ failBadSpec(specification);
chopped = chopped.substring(1);
}
- RegexpMatch[] matches = matcher.getMatches(PATTERN, chopped);
-
- if (matches.length != 1)
- throw new ApplicationRuntimeException(ValidatorMessages.badSpecification(specification));
+ Matcher matcher = PATTERN_COMPILED.matcher(chopped);
- RegexpMatch match = matches[0];
+ if (!matcher.find()) failBadSpec(specification);
- String name = match.getGroup(1);
- String value = match.getGroup(3);
+ String name = matcher.group(1);
+ String value = matcher.group(3);
String message = null;
- int length = match.getMatchLength();
+ int length = matcher.group().length();
+
+ if (matcher.find()) failBadSpec(specification);
if (chopped.length() > length)
{
@@ -108,6 +104,10 @@
}
return Collections.unmodifiableList(result);
+ }
+
+ private void failBadSpec(String specification) {
+ throw new ApplicationRuntimeException(ValidatorMessages.badSpecification(specification));
}
private Validator buildValidator(IComponent component, String name, String value, String message)