Java Code Examples for org.apache.commons.configuration2.Configuration#getString()

The following examples show how to use org.apache.commons.configuration2.Configuration#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TinkerGraph.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * An empty private constructor that initializes {@link TinkerGraph}.
 */
private TinkerGraph(final Configuration configuration) {
    this.configuration = configuration;
    vertexIdManager = selectIdManager(configuration, GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, Vertex.class);
    edgeIdManager = selectIdManager(configuration, GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, Edge.class);
    vertexPropertyIdManager = selectIdManager(configuration, GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, VertexProperty.class);
    defaultVertexPropertyCardinality = VertexProperty.Cardinality.valueOf(
            configuration.getString(GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.single.name()));
    allowNullPropertyValues = configuration.getBoolean(GREMLIN_TINKERGRAPH_ALLOW_NULL_PROPERTY_VALUES, false);

    graphLocation = configuration.getString(GREMLIN_TINKERGRAPH_GRAPH_LOCATION, null);
    graphFormat = configuration.getString(GREMLIN_TINKERGRAPH_GRAPH_FORMAT, null);

    if ((graphLocation != null && null == graphFormat) || (null == graphLocation && graphFormat != null))
        throw new IllegalStateException(String.format("The %s and %s must both be specified if either is present",
                GREMLIN_TINKERGRAPH_GRAPH_LOCATION, GREMLIN_TINKERGRAPH_GRAPH_FORMAT));

    if (graphLocation != null) loadGraph();
}
 
Example 2
Source File: ConfigurationProviderImplTest.java    From cryptotrader with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testGet() throws Exception {

    // Proxy (Invoke to initialize delegate)
    Configuration c = target.get();
    String version = c.getString(KEY);

    // Same proxy, same delegate.
    assertSame(target.get(), c);
    assertEquals(c.getString(KEY), version);

    // Same proxy, new delegate.
    target.clear();
    assertSame(target.get(), c);
    assertEquals(c.getString(KEY), version);

}
 
Example 3
Source File: DriverRemoteConnection.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public DriverRemoteConnection(final Configuration conf) {
    final boolean hasClusterConf = IteratorUtils.anyMatch(conf.getKeys(), k -> k.startsWith("clusterConfiguration"));
    if (conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && hasClusterConf)
        throw new IllegalStateException(String.format("A configuration should not contain both '%s' and 'clusterConfiguration'", GREMLIN_REMOTE_DRIVER_CLUSTERFILE));

    remoteTraversalSourceName = conf.getString(GREMLIN_REMOTE_DRIVER_SOURCENAME, DEFAULT_TRAVERSAL_SOURCE);

    try {
        final Cluster cluster;
        if (!conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && !hasClusterConf)
            cluster = Cluster.open();
        else
            cluster = conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) ?
                    Cluster.open(conf.getString(GREMLIN_REMOTE_DRIVER_CLUSTERFILE)) : Cluster.open(conf.subset("clusterConfiguration"));

        client = cluster.connect(Client.Settings.build().create()).alias(remoteTraversalSourceName);
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }

    attachElements = false;

    tryCloseCluster = true;
    tryCloseClient = true;
    this.conf = Optional.of(conf);
}
 
Example 4
Source File: Version.java    From batfish with Apache License 2.0 5 votes vote down vote up
/** Returns the version corresponding to the specified key, in the specified properties file */
public static String getPropertiesVersion(String propertiesPath, String key) {
  try {
    Configuration config = new Configurations().properties(propertiesPath);
    String version = config.getString(key);
    if (version.contains("project.version")) {
      // For whatever reason, resource filtering didn't work.
      return UNKNOWN_VERSION;
    }
    return version;
  } catch (Exception e) {
    return UNKNOWN_VERSION;
  }
}
 
Example 5
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the name of a page's index file, or {@link #DEFAULT_INDEX_FILE_NAME} if not in configuration.
 */
public static final String getIndexFileName() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        return config.getString(INDEX_FILE_NAME_CONFIG_KEY, DEFAULT_INDEX_FILE_NAME);
    } else {
        return DEFAULT_INDEX_FILE_NAME;
    }
}
 
Example 6
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the fallback target ID. The fallback target ID is used in case none of the resolved candidate targeted
 * URLs map to existing content.
 */
public static String getFallbackTargetId() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        return config.getString(FALLBACK_ID_CONFIG_KEY);
    } else {
        return null;
    }
}
 
Example 7
Source File: TinkerGraphProvider.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
    if (graph != null)
        graph.close();

    // in the even the graph is persisted we need to clean up
    final String graphLocation = null != configuration ? configuration.getString(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, null) : null;
    if (graphLocation != null) {
        final File f = new File(graphLocation);
        f.delete();
    }
}
 
Example 8
Source File: RabbitMQConfiguration.java    From james-project with Apache License 2.0 5 votes vote down vote up
static ManagementCredentials from(Configuration configuration) {
    String user = configuration.getString(MANAGEMENT_CREDENTIAL_USER_PROPERTY);
    Preconditions.checkState(!Strings.isNullOrEmpty(user), "You need to specify the " +
        MANAGEMENT_CREDENTIAL_USER_PROPERTY + " property as username of rabbitmq management admin account");

    String passwordString = configuration.getString(MANAGEMENT_CREDENTIAL_PASSWORD_PROPERTY);
    Preconditions.checkState(!Strings.isNullOrEmpty(passwordString), "You need to specify the " +
        MANAGEMENT_CREDENTIAL_PASSWORD_PROPERTY + " property as password of rabbitmq management admin account");

    return new ManagementCredentials(user, passwordString.toCharArray());
}
 
Example 9
Source File: UiServiceInternalImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
protected String getRequiredStringProperty(Configuration config, String key) throws ConfigurationException {
    String property = config.getString(key);
    if (StringUtils.isEmpty(property)) {
        throw new ConfigurationException("Missing required property '" + key + "'");
    } else {
        return property;
    }
}
 
Example 10
Source File: AssetProcessingConfigReaderImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private String getRequiredStringProperty(Configuration config, String key) throws AssetProcessingConfigurationException {
    String property = config.getString(key);
    if (StringUtils.isEmpty(property)) {
        throw new AssetProcessingConfigurationException("Missing required property '" + key + "'");
    } else {
        return property;
    }
}
 
Example 11
Source File: ElasticSearchConfiguration.java    From james-project with Apache License 2.0 5 votes vote down vote up
private static Optional<Credential> getCredential(Configuration configuration) {
    String username = configuration.getString(ELASTICSEARCH_USER);
    String password = configuration.getString(ELASTICSEARCH_PASSWORD);

    if (username == null && password == null) {
        return Optional.empty();
    }

    return Optional.of(Credential.of(username, password));
}
 
Example 12
Source File: DbMergeInfo.java    From obevo with Apache License 2.0 5 votes vote down vote up
public static RichIterable<DbMergeInfo> parseFromProperties(Configuration config) {
    MutableSet<String> dbs = CollectionAdapter.wrapSet(config.getList(String.class, "instances", Lists.mutable.<String>empty()));

    MutableList<String> exceptions = Lists.mutable.empty();
    MutableList<DbMergeInfo> dbMergeInfos = Lists.mutable.empty();
    for (String db : dbs) {
        Configuration subset = config.subset(db);
        if (subset.containsKey("inputDir")) {
            File inputDir = new File(subset.getString("inputDir"));
            if (!inputDir.canRead()) {
                if (inputDir.getPath().contains("\r")) {
                    exceptions.add("Could not find " + db + "." + "inputDir file (use forward-slash instead of back-slash in path): " + inputDir.getPath().replaceAll("\r", ""));
                } else {
                    exceptions.add("Could not find " + db + "." + "inputDir file: " + inputDir);
                }
            }
            DbMergeInfo mergeInfo = new DbMergeInfo(db, inputDir);
            if (subset.containsKey("driverClassName")) {
                mergeInfo.setDriverClassName(subset.getString("driverClassName"));
                mergeInfo.setUrl(subset.getString("url"));
                mergeInfo.setUsername(subset.getString("username"));
                mergeInfo.setPassword(subset.getString("password"));
                mergeInfo.setPhysicalSchema(subset.getString("physicalSchema"));
            }

            dbMergeInfos.add(mergeInfo);
        }
    }

    if (exceptions.notEmpty()) {
        throw new IllegalArgumentException("Invalid properties found in configuration:\n" + exceptions.collect(new Function<String, String>() {
            @Override
            public String valueOf(String it) {
                return "* " + it;
            }
        }).makeString("\n"));
    }
    return dbMergeInfos;
}
 
Example 13
Source File: Config.java    From bireme with Apache License 2.0 5 votes vote down vote up
private HashMap<String, String> fetchTableMap(String dataSource)
    throws ConfigurationException, BiremeException {
  Configurations configs = new Configurations();
  Configuration tableConfig = null;

  tableConfig = configs.properties(new File(DEFAULT_TABLEMAP_DIR + dataSource + ".properties"));

  String originTable, mappedTable;
  HashMap<String, String> localTableMap = new HashMap<String, String>();
  Iterator<String> tables = tableConfig.getKeys();

  while (tables.hasNext()) {
    originTable = tables.next();
    mappedTable = tableConfig.getString(originTable);

    if (originTable.split("\\.").length != 2 || mappedTable.split("\\.").length != 2) {
      String message = "Wrong format: " + originTable + ", " + mappedTable;
      logger.fatal(message);
      throw new BiremeException(message);
    }

    localTableMap.put(dataSource + "." + originTable, mappedTable);

    if (!tableMap.values().contains(mappedTable)) {
      loadersCount++;
    }
    tableMap.put(dataSource + "." + originTable, mappedTable);
  }

  return localTableMap;
}
 
Example 14
Source File: AbstractLineHandlerResultJMXMonitor.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public void init(Configuration config) throws ConfigurationException {
    this.jmxName = config.getString("jmxName", getDefaultJMXName());        
}
 
Example 15
Source File: ClusterPopulationMapReduce.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void loadState(final Graph graph, final Configuration configuration) {
    this.memoryKey = configuration.getString(CLUSTER_POPULATION_MEMORY_KEY, DEFAULT_MEMORY_KEY);
}
 
Example 16
Source File: ElasticSearchMetricReporterModule.java    From james-project with Apache License 2.0 4 votes vote down vote up
private String locateHost(Configuration propertiesReader) {
    return propertiesReader.getString("elasticsearch.http.host",
        propertiesReader.getString(ELASTICSEARCH_MASTER_HOST));
}
 
Example 17
Source File: AbstractRemoteGraphProvider.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Graph openTestGraph(final Configuration config) {
    final String serverGraphName = config.getString(DriverRemoteConnection.GREMLIN_REMOTE_DRIVER_SOURCENAME);
    return remoteCache.computeIfAbsent(serverGraphName,
            k -> RemoteGraph.open(new DriverRemoteConnection(cluster, config), config));
}
 
Example 18
Source File: GraphComputerTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void loadState(final Graph graph, final Configuration configuration) {
    this.state = configuration.getString("state");
}
 
Example 19
Source File: GraphComputerTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void loadState(final Graph graph, final Configuration configuration) {
    this.state = configuration.getString("state");
}
 
Example 20
Source File: SwiftTmpAuthConfigurationReader.java    From james-project with Apache License 2.0 4 votes vote down vote up
public static SwiftTempAuthObjectStorage.Configuration readSwiftConfiguration(Configuration configuration) {
    String endpointStr = configuration.getString(OBJECTSTORAGE_SWIFT_ENDPOINT, null);
    String crendentialsStr = configuration.getString(OBJECTSTORAGE_SWIFT_CREDENTIALS, null);
    String userNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_USERNAME, null);
    String tenantNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_TENANTNAME, null);

    Preconditions.checkArgument(endpointStr != null,
        "%s is a mandatory configuration value", OBJECTSTORAGE_SWIFT_ENDPOINT);
    Preconditions.checkArgument(crendentialsStr != null,
        "%s is a mandatory configuration value", OBJECTSTORAGE_SWIFT_CREDENTIALS);
    Preconditions.checkArgument(userNameStr != null,
        "%s is a mandatory configuration value", OBJECTSTORAGE_SWIFT_TEMPAUTH_USERNAME);
    Preconditions.checkArgument(tenantNameStr != null,
        "%s is a mandatory configuration value", OBJECTSTORAGE_SWIFT_TEMPAUTH_TENANTNAME);

    URI endpoint = URI.create(endpointStr);
    Credentials credentials = Credentials.of(crendentialsStr);
    UserName userName = UserName.of(userNameStr);
    TenantName tenantName = TenantName.of(tenantNameStr);
    Identity identity = Identity.of(tenantName, userName);

    Optional<Region> region = Optional.ofNullable(
            configuration.getString(SwiftConfiguration.OBJECTSTORAGE_SWIFT_REGION, null))
        .map(Region::of);

    Optional<PassHeaderName> passHeaderName = Optional.ofNullable(
            configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_PASS_HEADER_NAME, null))
        .map(PassHeaderName::of);

    Optional<UserHeaderName> userHeaderName = Optional.ofNullable(
            configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_USER_HEADER_NAME, null))
        .map(UserHeaderName::of);

    return SwiftTempAuthObjectStorage.configBuilder()
        .endpoint(endpoint)
        .credentials(credentials)
        .region(region)
        .identity(identity)
        .tempAuthHeaderPassName(passHeaderName)
        .tempAuthHeaderUserName(userHeaderName)
        .build();
}