Github user mattyb149 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/912#discussion_r76333878
--- Diff:
nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
---
@@ -379,6 +381,68 @@ public ValidationResult validate(final String subject,
final String input, final
};
}
+ public static Validator createURLorFileValidator() {
+ return (subject, input, context) -> {
+ if (context.isExpressionLanguageSupported(subject) &&
context.isExpressionLanguagePresent(input)) {
+ return new
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
Language Present").valid(true).build();
+ }
+
+ try {
+ PropertyValue propertyValue =
context.newPropertyValue(input);
+ String evaluatedInput = (propertyValue == null) ? input :
propertyValue.evaluateAttributeExpressions().getValue();
+
+ boolean validUrl = true;
+
+ // First check to see if it is a valid URL
+ try {
+ new URL(evaluatedInput);
+ } catch (MalformedURLException mue) {
+ validUrl = false;
+ }
+
+ boolean validFile = true;
+ if (!validUrl) {
+ // Check to see if it is a file and it exists
+ final File file = new File(evaluatedInput);
+ validFile = file.exists();
+ }
+
+ final boolean valid = validUrl || validFile;
+ final String reason = valid ? "Valid URL or file" : "Not a
valid URL or file";
+ return new
ValidationResult.Builder().subject(subject).input(input).explanation(reason).valid(valid).build();
+
+ } catch (final Exception e) {
+ return new
ValidationResult.Builder().subject(subject).input(input).explanation("Not a
valid URL or file").valid(false).build();
+ }
+ };
+ }
+
+ public static Validator createListValidator(boolean trimEntries,
boolean excludeEmptyEntries, Validator validator) {
+ return (subject, input, context) -> {
+ if (context.isExpressionLanguageSupported(subject) &&
context.isExpressionLanguagePresent(input)) {
+ return new
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
Language Present").valid(true).build();
+ }
+ try {
+ if (input == null) {
+ return new
ValidationResult.Builder().subject(subject).input(null).explanation("List must
have at least one non-empty element").valid(false).build();
+ }
+ final String[] list = input.split(",");
+ for (String item : list) {
+ String itemToValidate = (StringUtils.isBlank(item) &&
trimEntries) ? item.trim() : item;
--- End diff --
Good catch, will fix
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---