All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.qsy7.property.api.enumeration.SystemProxy Maven / Gradle / Ivy

package io.github.qsy7.property.api.enumeration;

import io.github.qsy7.property.api.annotation.Optional;
import io.github.qsy7.property.api.property.ConfigurableProperty;
import io.github.qsy7.property.api.property.MappedEnvironmentProperty;
import io.github.qsy7.property.api.property.NoProxy;
import io.github.qsy7.property.api.property.ProxyHost;
import io.github.qsy7.property.api.property.ProxyPort;

@Optional
public enum SystemProxy implements MappedEnvironmentProperty {
  HttpProxy("http_proxy", ProxyHost.class, ProxyPort.class) {
    protected String getValue(
        String environmentValue, Class propertyClass) {
      if (environmentValue == null) return null;

      if (ProxyHost.class.equals(propertyClass))
        return (environmentValue.substring(
            environmentValue.indexOf("://") + 3, environmentValue.lastIndexOf(":")));

      return (environmentValue.substring(environmentValue.lastIndexOf(":") + 1));
    }
  },
  HttpsProxy("https_proxy", ProxyHost.class, ProxyPort.class) {
    protected String getValue(
        String environmentValue, Class propertyClass) {
      if (environmentValue == null) return null;

      if (ProxyHost.class.equals(propertyClass))
        return (environmentValue.substring(
            environmentValue.indexOf("://") + 3, environmentValue.lastIndexOf(":")));

      return (environmentValue.substring(environmentValue.lastIndexOf(":") + 1));
    }
  },
  NoProxy("no_proxy", NoProxy.class) {
    protected String getValue(
        String environmentValue, Class propertyClass) {
      return (environmentValue);
    }
  };

  protected final String key;
  protected final Class[] supportedProperties;

  SystemProxy(String key, Class... supportedProperties) {
    this.key = key;
    this.supportedProperties = supportedProperties;
  }

  protected abstract String getValue(
      final String environmentValue, Class propertyClass);

  @Override
  public String getKey() {
    return key;
  }

  @Override
  public Class[] getSupportedProperties() {
    return supportedProperties;
  }

  @Override
  public String getValue(Class propertyClass) {
    return getValue(System.getenv().get(getKey()), propertyClass);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy