/** * differs from standard file exists validator by supporting expression language values. TODO: maybe there is a bug in standard validator? */ public static Validator createFileExistsAndReadableValidator() { return (subject, input, context) -> { final String substituted; try { substituted = context.newPropertyValue(input).evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder() .subject(subject) .input(input) .valid(false) .explanation("Not a valid Expression Language value: " + e.getMessage()) .build(); } final File file = new File(substituted); final boolean valid = file.exists() && file.canRead(); final String explanation = valid ? null : "File " + file + " does not exist or cannot be read"; return new ValidationResult.Builder() .subject(subject) .input(input) .valid(valid) .explanation(explanation) .build(); }; } }
/** * Let's do validation by script compile at this point. * * @param context provides a mechanism for obtaining externally managed values, such as property values and supplies convenience methods for operating on those values * @return Collection of ValidationResult objects that will be added to any other validation findings - may be null */ protected Collection<ValidationResult> customValidate(final ValidationContext context) { this.scriptFile = asFile(context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue()); //SCRIPT_FILE this.scriptBody = context.getProperty(SCRIPT_BODY).getValue(); //SCRIPT_BODY this.addClasspath = context.getProperty(ADD_CLASSPATH).evaluateAttributeExpressions().getValue(); //ADD_CLASSPATH this.groovyClasspath = context.newPropertyValue(GROOVY_CLASSPATH).evaluateAttributeExpressions().getValue(); //evaluated from ${groovy.classes.path} global property final Collection<ValidationResult> results = new HashSet<>(); try { getGroovyScript(); } catch (Throwable t) { results.add(new ValidationResult.Builder().subject("GroovyScript").input(this.scriptFile != null ? this.scriptFile.toString() : null).valid(false).explanation(t.toString()).build()); } return results; }
if (allowEL) { try { substituted = context.newPropertyValue(value).evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(value).valid(false)
final String evaluatedInput = validationContext.newPropertyValue(input) .evaluateAttributeExpressions() .getValue();
@Override public ValidationResult validate(final String subject, final String value, final ValidationContext context) { if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) { return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build(); } final String substituted; if (allowEL) { try { substituted = context.newPropertyValue(value).evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(value).valid(false) .explanation("Not a valid Expression Language value: " + e.getMessage()).build(); } } else { substituted = value; } final File file = new File(substituted); final boolean valid = file.exists(); final String explanation = valid ? null : "File " + file + " does not exist"; return new ValidationResult.Builder().subject(subject).input(value).valid(valid).explanation(explanation).build(); } }
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { final String value = context.newPropertyValue(input).evaluateAttributeExpressions().getValue(); try { SiteToSiteRestApiClient.parseClusterUrls(value); return new ValidationResult.Builder() .input(input) .subject(subject) .valid(true) .build(); } catch (IllegalArgumentException ex) { return new ValidationResult.Builder() .input(input) .subject(subject) .valid(false) .explanation(ex.getLocalizedMessage()) .build(); } } }
if (supportAttributeExpressionLanguage) { try { substituted = context.newPropertyValue(value).evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder()
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(); } }; }
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { String evaluatedInput = input; if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) { try { PropertyValue propertyValue = context.newPropertyValue(input); evaluatedInput = (propertyValue == null) ? input : propertyValue.evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Not a valid expression").valid(false).build(); } } String reason = null; try { if (!Charset.isSupported(evaluatedInput)) { reason = "Character Set is not supported by this JVM."; } } catch (final IllegalArgumentException iae) { reason = "Character Set value is null or is not supported by this JVM."; } return new ValidationResult.Builder().subject(subject).input(evaluatedInput).explanation(reason).valid(reason == null).build(); } };
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build(); } try { final String evaluatedInput = context.newPropertyValue(input).evaluateAttributeExpressions().getValue(); new URL(evaluatedInput); return new ValidationResult.Builder().subject(subject).input(input).explanation("Valid URL").valid(true).build(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Not a valid URL").valid(false).build(); } } };
final String substituted = context.newPropertyValue(input).evaluateAttributeExpressions().getValue();
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { final String value = context.newPropertyValue(input).evaluateAttributeExpressions().getValue(); try { new URL(value); } catch (final Exception e) { return new ValidationResult.Builder().input(input).subject(subject).valid(false).explanation("Not a valid URL").build(); } return new ValidationResult.Builder().input(input).subject(subject).valid(true).build(); } }
if (allowEL) { try { substituted = context.newPropertyValue(value).evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(value).valid(false)
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { final String value = context.newPropertyValue(input).evaluateAttributeExpressions().getValue(); try { SiteToSiteRestApiClient.parseClusterUrls(value); return new ValidationResult.Builder() .input(input) .subject(subject) .valid(true) .build(); } catch (IllegalArgumentException ex) { return new ValidationResult.Builder() .input(input) .subject(subject) .valid(false) .explanation(ex.getLocalizedMessage()) .build(); } } }
@Override public ValidationResult validate(final String subject, final String value, final ValidationContext context) { if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) { return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build(); } final String substituted; if (allowEL) { try { substituted = context.newPropertyValue(value).evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(value).valid(false) .explanation("Not a valid Expression Language value: " + e.getMessage()).build(); } } else { substituted = value; } final File file = new File(substituted); final boolean valid = file.exists(); final String explanation = valid ? null : "File " + file + " does not exist"; return new ValidationResult.Builder().subject(subject).input(value).valid(valid).explanation(explanation).build(); } }
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(); } }; }
if (supportAttributeExpressionLanguage) { try { substituted = context.newPropertyValue(value).evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder()
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { String evaluatedInput = input; if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) { try { PropertyValue propertyValue = context.newPropertyValue(input); evaluatedInput = (propertyValue == null) ? input : propertyValue.evaluateAttributeExpressions().getValue(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Not a valid expression").valid(false).build(); } } String reason = null; try { if (!Charset.isSupported(evaluatedInput)) { reason = "Character Set is not supported by this JVM."; } } catch (final IllegalArgumentException iae) { reason = "Character Set value is null or is not supported by this JVM."; } return new ValidationResult.Builder().subject(subject).input(evaluatedInput).explanation(reason).valid(reason == null).build(); } };
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build(); } try { final String evaluatedInput = context.newPropertyValue(input).evaluateAttributeExpressions().getValue(); new URL(evaluatedInput); return new ValidationResult.Builder().subject(subject).input(input).explanation("Valid URL").valid(true).build(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Not a valid URL").valid(false).build(); } } };
final String substituted = context.newPropertyValue(input).evaluateAttributeExpressions().getValue();