jfrazee commented on pull request #5136:
URL: https://github.com/apache/nifi/pull/5136#issuecomment-875841218
@timeabarna Let me see if I have it right. We know the existing one doesn't
evaluate the expression because it could be attributes and evaluating those
could produce nonsense because the attributes don't exist at the time of
evaluation so we're adding a new one that does evaluate.
But it should still be possible to just have something like the following
and push the responsibility on to the user:
```java
public static Validator createRegexMatchingValidator(final Pattern pattern) {
return createRegexMatchingValidator(pattern, false);
}
```
And:
```java
public static Validator createRegexMatchingValidator(final Pattern pattern,
final boolean evaluateExpressions) {
return new Validator() {
@Override
public ValidationResult validate(final String subject, final String
value, final ValidationContext context) {
String input = value;
if (context.isExpressionLanguageSupported(subject) &&
context.isExpressionLanguagePresent(value)) {
if (evaluateExpressions) {
try {
input =
property.evaluateAttributeExpressions().getValue();
} catch (final Exception e) {
return ...
}
} else {
return new
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
Language Present").valid(true).build();
}
}
final boolean matches = pattern.matcher(input).matches();
return new ValidationResult.Builder() ...
}
};
}
```
Is there a reason this doesn't work?
Also, I think the new EL variant might evaluate for
`ExpressionLanguageScope.NONE` since it doesn't check for
`context.isExpressionLanguageSupported(subject)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]