Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specialized filter on system property #87

Open
charphi opened this issue Aug 13, 2021 · 0 comments
Open

Add specialized filter on system property #87

charphi opened this issue Aug 13, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@charphi
Copy link
Member

charphi commented Aug 13, 2021

Allow to filter providers using a system property.

Examples:

  • javax.net.ssl.trustStoreType=Windows-ROOT
  • jdk.tls.disabledAlgorithms=SSLv3, RC4
  • https.cipherSuites=SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,SSL_DHE_DSS_WITH_DES_CBC_SHA

The following code ...

@ServiceDefinition(quantifier = Quantifier.MULTIPLE)
public interface Translator {

    String translate(String text);

    String getName();

    @ServiceFilter
    default boolean isEnabled() {
        return FILTER_ON_PROPERTY.apply(getName());
    }

    static Predicate<String> FILTER_ON_PROPERTY = getFilter("translators", ',', true, true, false);
}

static Predicate<String> getFilter(String key, char separator, boolean onMatch, boolean onMiss, boolean caseSensitive) {
    String property = System.getProperty(key);
    if (property == null) return value -> onMiss;
    String[] values = property.split(String.valueOf(separator), -1);
    return value -> Stream.of(values).anyMatch(caseSensitive ? value::equals : value::equalsIgnoreCase) ^ onMatch;
}

... could be simplified as :

@ServiceDefinition(quantifier = Quantifier.MULTIPLE)
public interface Translator {

    String translate(String text);

    @ServiceFilterOnProperty(key = "translators", separator = ',', onMatch = true, onMiss = true, caseSensitive = false)
    String getName();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant