[ https://issues.apache.org/jira/browse/NIFI-2604?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15437714#comment-15437714 ]
ASF GitHub Bot commented on NIFI-2604: -------------------------------------- Github user brosander commented on a diff in the pull request: https://github.com/apache/nifi/pull/912#discussion_r76328438 --- 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 -- Why do we only trim if the string is blank? Shouldn't we trim anytime trimEntries is true? > JDBC Connection Pool support for lib directory and expression language > ---------------------------------------------------------------------- > > Key: NIFI-2604 > URL: https://issues.apache.org/jira/browse/NIFI-2604 > Project: Apache NiFi > Issue Type: Improvement > Reporter: Joseph Witt > Assignee: Matt Burgess > > It would be ideal if the JDBC Connection Service supported specifying a > directory instead of particular driver jars. It would also be helpful if it > accepted expression language statements so that it could refer to a location > that is based on variable registry values so it is more portable between > environments. > This stems from a user list thread titled "adding dependencies like jdbc > drivers to the build" on Aug 18 2016 -- This message was sent by Atlassian JIRA (v6.3.4#6332)