org.apache.commons.configuration.HierarchicalINIConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration.HierarchicalINIConfiguration. 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: Bundles.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
public static URI getReference(Path path) throws IOException {
	if (path == null || isMissing(path))
		return null;
	if (!isReference(path))
		throw new IllegalArgumentException("Not a reference: " + path);
	// Note: Latin1 is chosen here because it would not bail out on
	// "strange" characters. We actually parse the URL as ASCII
	path = withExtension(path, DOT_URL);
	try (BufferedReader r = newBufferedReader(path, LATIN1)) {
		HierarchicalINIConfiguration ini = new HierarchicalINIConfiguration();
		ini.load(r);

		String urlStr = ini.getSection(INI_INTERNET_SHORTCUT).getString(
				INI_URL);

		// String urlStr = ini.get(INI_INTERNET_SHORTCUT, INI_URL);
		if (urlStr == null)
			throw new IOException("Invalid/unsupported URL format: " + path);
		return URI.create(urlStr);
	} catch (ConfigurationException e) {
		throw new IOException("Can't parse reference: " + path, e);
	}
}
 
Example #2
Source File: Yfiton.java    From yfiton with Apache License 2.0 6 votes vote down vote up
protected Yfiton(Notifier notifier, HierarchicalINIConfiguration configuration, boolean displayStackTraces) throws ConversionException {
    this.configurationParameters = loadPreferences(configuration, notifier);
    this.displayStackTraces = displayStackTraces;

    configurationFilePath = configuration.getFile().getAbsolutePath();

    if (log.isTraceEnabled()) {
        if (!Files.exists(Paths.get(configurationFilePath))) {
            log.trace("No configuration file detected in '{}'", configurationFilePath);
        } else {
            log.trace("Configuration loaded from '{}': {}", configurationFilePath, configurationParameters);
        }
    }

    this.notifier = notifier;
    this.supportedParameters = AnnotationProcessor.analyze(ImmutableSet.of(notifier));
}
 
Example #3
Source File: AbstractMapper.java    From cqlkit with Apache License 2.0 6 votes vote down vote up
private HierarchicalINIConfiguration parseCqlRc() {



        File file = new File(System.getProperty("user.home") + "/.cassandra/cqlshrc");
        if (commandLine.hasOption("cqlshrc")) {
            file = new File(commandLine.getOptionValue("cqlshrc"));
            if(!file.exists()) {
                System.err.println("cqlshrc file not found: " + file);
                System.exit(-1);
            }
        }

        if(file.exists()) {
            try {
                HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(file);
                return configuration;
            } catch (ConfigurationException e) {
                throw new RuntimeException(e);
            }
        }

        return null;
    }
 
Example #4
Source File: YfitonBuilder.java    From yfiton with Apache License 2.0 6 votes vote down vote up
public Yfiton build() throws ConversionException, ConfigurationException {
    Notifier notifier = this.notifier;

    if (notifier == null) {
        notifier = resolve(this.notifierKey);
    }

    if (configurationFile == null) {
        try {
            configurationFile = Configuration.getNotifierConfigurationFilePath(notifier.getKey());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    HierarchicalINIConfiguration hierarchicalConfiguration =
            new HierarchicalINIConfiguration(configurationFile.toFile());

    return new Yfiton(notifier, hierarchicalConfiguration, displayStackTraces);
}
 
Example #5
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
private void writeWp43Configs(List<Contingency> contingencies, Path workingDir) throws IOException, ConfigurationException {
    Path baseWp43ConfigFile = PlatformConfig.defaultConfig().getConfigDir().resolve(WP43_CONFIGS_FILE_NAME);

    // generate one variant of the base config for all the contingency
    // this allow to add extra variables for some indexes
    HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(baseWp43ConfigFile.toFile());
    SubnodeConfiguration node = configuration.getSection("smallsignal");
    node.setProperty("f_instant", parameters.getFaultEventInstant());
    for (int i = 0; i < contingencies.size(); i++) {
        Contingency contingency = contingencies.get(i);
        if (contingency.getElements().isEmpty()) {
            throw new AssertionError("Empty contingency " + contingency.getId());
        }
        Iterator<ContingencyElement> it = contingency.getElements().iterator();
        // compute the maximum fault duration
        double maxDuration = getFaultDuration(contingency, it.next());
        while (it.hasNext()) {
            maxDuration = Math.max(maxDuration, getFaultDuration(contingency, it.next()));
        }
        node.setProperty("f_duration", maxDuration);
        Path wp43Config = workingDir.resolve(WP43_CONFIGS_PER_FAULT_FILE_NAME.replace(CommandConstants.EXECUTION_NUMBER_PATTERN, Integer.toString(i)));
        try (Writer writer = Files.newBufferedWriter(wp43Config, StandardCharsets.UTF_8)) {
            configuration.save(writer);
        }
    }
}
 
Example #6
Source File: SlackNotifier.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    String teamId = accessTokenData.get("teamId");
    configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId);

    SubnodeConfiguration section = configuration.getSection(teamId);

    section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());
    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        section.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}
 
Example #7
Source File: SlackNotifier.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    String teamId = accessTokenData.get("teamId");
    configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId);

    SubnodeConfiguration section = configuration.getSection(teamId);

    section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());
    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        section.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}
 
Example #8
Source File: Yfiton.java    From yfiton with Apache License 2.0 6 votes vote down vote up
protected Yfiton(Notifier notifier, HierarchicalINIConfiguration configuration, boolean displayStackTraces) throws ConversionException {
    this.configurationParameters = loadPreferences(configuration, notifier);
    this.displayStackTraces = displayStackTraces;

    configurationFilePath = configuration.getFile().getAbsolutePath();

    if (log.isTraceEnabled()) {
        if (!Files.exists(Paths.get(configurationFilePath))) {
            log.trace("No configuration file detected in '{}'", configurationFilePath);
        } else {
            log.trace("Configuration loaded from '{}': {}", configurationFilePath, configurationParameters);
        }
    }

    this.notifier = notifier;
    this.supportedParameters = AnnotationProcessor.analyze(ImmutableSet.of(notifier));
}
 
Example #9
Source File: YfitonBuilder.java    From yfiton with Apache License 2.0 6 votes vote down vote up
public Yfiton build() throws ConversionException, ConfigurationException {
    Notifier notifier = this.notifier;

    if (notifier == null) {
        notifier = resolve(this.notifierKey);
    }

    if (configurationFile == null) {
        try {
            configurationFile = Configuration.getNotifierConfigurationFilePath(notifier.getKey());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    HierarchicalINIConfiguration hierarchicalConfiguration =
            new HierarchicalINIConfiguration(configurationFile.toFile());

    return new Yfiton(notifier, hierarchicalConfiguration, displayStackTraces);
}
 
Example #10
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 6 votes vote down vote up
private void readHierarchicalIniConfigurationFile(File hierarchicalIniFile) {
    
    if (hierarchicalIniFile == null) {
        return;
    }
    
    try {
        if (hierarchicalIniFile.exists()) {
            configurationDirectory_ = hierarchicalIniFile.getParent();
            configurationFilename_ = hierarchicalIniFile.getName();

            hierarchicalIniConfiguration_ = new HierarchicalINIConfiguration();
            hierarchicalIniConfiguration_.setDelimiterParsingDisabled(true);
            hierarchicalIniConfiguration_.setAutoSave(false);
            hierarchicalIniConfiguration_.load(hierarchicalIniFile);
        }
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        
        configurationDirectory_ = null;
        configurationFilename_ = null;
        hierarchicalIniConfiguration_ = null;
    }
}
 
Example #11
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 6 votes vote down vote up
private void readHierarchicalIniConfigurationFile(InputStream configurationInputStream) {
    
    if (configurationInputStream == null) {
        return;
    }
    
    try {
        configurationInputStream_ = configurationInputStream;
        
        hierarchicalIniConfiguration_ = new HierarchicalINIConfiguration();
        hierarchicalIniConfiguration_.setDelimiterParsingDisabled(true);
        hierarchicalIniConfiguration_.setAutoSave(false);
        hierarchicalIniConfiguration_.load(configurationInputStream, null);
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        
        configurationInputStream_ = null;
        hierarchicalIniConfiguration_ = null;
    }
}
 
Example #12
Source File: Notifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
public Notifier() {
    try {
        configuration = new HierarchicalINIConfiguration(getConfigurationFilePath().toFile());
    } catch (ConfigurationException | IOException e) {
        log.warn(e.getMessage(), e);
    }
}
 
Example #13
Source File: OAuthNotifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    configuration.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());

    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        configuration.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}
 
Example #14
Source File: Yfiton.java    From yfiton with Apache License 2.0 5 votes vote down vote up
private Map<String, Map<String, String>> loadPreferences(HierarchicalINIConfiguration configuration, Notifier notifier) {
    Set<String> sections = configuration.getSections();

    return sections.stream().filter(isEqual(null).negate().and(section -> notifier.getKey().equals(section)))
            .collect(Collectors.toMap(Function.identity(),
                    section -> configuration.getSection(section).
                            getRootNode().getChildren().stream().collect(
                            Collectors.toMap(ConfigurationNode::getName, node -> (String) node.getValue()))));
}
 
Example #15
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
public static String saveHierarchicalIniConfigurationToString(HierarchicalINIConfiguration hierarchicalIniConfiguration) {
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        hierarchicalIniConfiguration.save(byteArrayOutputStream);
        return byteArrayOutputStream.toString();
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        return null;
    }
}
 
Example #16
Source File: PushbulletNotifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
private String getAccessToken() throws NotificationException {
    HierarchicalINIConfiguration configuration = getConfiguration();

    if (accessToken != null) {
        return accessToken;
    }

    return configuration.getString(KEY_ACCESS_TOKEN);
}
 
Example #17
Source File: SessionFactory.java    From cqlkit with Apache License 2.0 5 votes vote down vote up
public static SessionFactory newInstance(
        CommandLine commandLine,
        HierarchicalINIConfiguration cqlshrc)
{
    if(instance == null) {
        instance = new SessionFactory(commandLine, cqlshrc);
    }
    return instance;
}
 
Example #18
Source File: ConfigHandler.java    From DDF with Apache License 2.0 5 votes vote down vote up
/**
 * Load configuration from ddf.ini, or the file name specified by the environment variable DDF_INI.
 *
 * @return the {@link Configuration} object loaded
 * @throws Exception
 * @throws ConfigurationException , {@link IOException}
 */
@Override
public Configuration loadConfig() throws ConfigurationException, IOException {

  Configuration resultConfig = new Configuration();

  if (!Utils.localFileExists(this.getConfigFileName())) {
    // String configFileName = System.getenv(ConfigConstant.DDF_INI_ENV_VAR.getValue());
    File file = new File(this.locateConfigFileName(this.getConfigDir(), this.getConfigFileName()));
    mConfigDir = file.getParentFile().getName();
    mConfigFileName = file.getCanonicalPath();
  }

  if (!Utils.localFileExists(this.getConfigFileName())) return null;

  HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(this.getConfigFileName());

  @SuppressWarnings("unchecked")
  Set<String> sectionNames = config.getSections();
  for (String sectionName : sectionNames) {
    SubnodeConfiguration section = config.getSection(sectionName);
    if (section != null) {
      Configuration.Section resultSection = resultConfig.getSection(sectionName);

      @SuppressWarnings("unchecked")
      Iterator<String> keys = section.getKeys();
      while (keys.hasNext()) {
        String key = keys.next();
        String value = section.getString(key);
        if (value != null) {
          resultSection.set(key, value);
        }
      }
    }
  }

  mConfig = resultConfig;
  return mConfig;
}
 
Example #19
Source File: ModelConfig.java    From modernmt with Apache License 2.0 5 votes vote down vote up
public static ModelConfig load(File path) throws IOException {
    try {
        return new ModelConfig(new HierarchicalINIConfiguration(path), path.getParentFile());
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
}
 
Example #20
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
public static void saveHierarchicalIniConfigurationFile(File hierarchicalIniConfigurationFile, HierarchicalINIConfiguration hierarchicalIniConfiguration) {
    try {
        hierarchicalIniConfiguration.save(hierarchicalIniConfigurationFile);
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
    }
}
 
Example #21
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
public static void saveHierarchicalIniConfigurationFile(String filePath, String filename, HierarchicalINIConfiguration hierarchicalIniConfiguration) {
    try {
        File hierarchicalIniConfigurationFile = new File(filePath + File.separator + filename);
        hierarchicalIniConfiguration.save(hierarchicalIniConfigurationFile);
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
    }
}
 
Example #22
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
private void readHierarchicalIniConfigurationFile(String filePathAndFilename) {
    
    if (filePathAndFilename == null) {
        return;
    }
    
    try {
        File hierarchicalIniConfigurationFile_ = new File(filePathAndFilename);
        boolean doesFileExist = FileIo.doesFileExist(filePathAndFilename);
        
        if (doesFileExist) {
            configurationDirectory_ = hierarchicalIniConfigurationFile_.getParent();
            configurationFilename_ = hierarchicalIniConfigurationFile_.getName();

            hierarchicalIniConfiguration_ = new HierarchicalINIConfiguration();
            hierarchicalIniConfiguration_.setDelimiterParsingDisabled(true);
            hierarchicalIniConfiguration_.setAutoSave(false);
            hierarchicalIniConfiguration_.load(hierarchicalIniConfigurationFile_);
        }
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        
        configurationDirectory_ = null;
        configurationFilename_ = null;
        hierarchicalIniConfiguration_ = null;
    }
}
 
Example #23
Source File: PushbulletNotifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
private String getAccessToken() throws NotificationException {
    HierarchicalINIConfiguration configuration = getConfiguration();

    if (accessToken != null) {
        return accessToken;
    }

    return configuration.getString(KEY_ACCESS_TOKEN);
}
 
Example #24
Source File: Notifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
public Notifier() {
    try {
        configuration = new HierarchicalINIConfiguration(getConfigurationFilePath().toFile());
    } catch (ConfigurationException | IOException e) {
        log.warn(e.getMessage(), e);
    }
}
 
Example #25
Source File: Yfiton.java    From yfiton with Apache License 2.0 5 votes vote down vote up
private Map<String, Map<String, String>> loadPreferences(HierarchicalINIConfiguration configuration, Notifier notifier) {
    Set<String> sections = configuration.getSections();

    return sections.stream().filter(isEqual(null).negate().and(section -> notifier.getKey().equals(section)))
            .collect(Collectors.toMap(Function.identity(),
                    section -> configuration.getSection(section).
                            getRootNode().getChildren().stream().collect(
                            Collectors.toMap(ConfigurationNode::getName, node -> (String) node.getValue()))));
}
 
Example #26
Source File: OAuthNotifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    configuration.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());

    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        configuration.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}
 
Example #27
Source File: DymolaAdaptersMatParamsWriter.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public DymolaAdaptersMatParamsWriter(HierarchicalINIConfiguration configuration)  {
    if (configuration == null) {
        throw new RuntimeException("null config");
    }
    this.configuration = configuration;
    //this below will simply log parameters ..
    for (String section : configuration.getSections()) {
        SubnodeConfiguration node = configuration.getSection(section);
        List<String> paramsSummary = StreamSupport.stream(
                Spliterators.spliteratorUnknownSize(node.getKeys(),
                        Spliterator.ORDERED), false).map(p -> p + "=" + node.getString(p)).collect(Collectors.<String>toList());
        LOGGER.info("index {}: {}", section, paramsSummary);
    }
}
 
Example #28
Source File: ModelConfig.java    From modernmt with Apache License 2.0 4 votes vote down vote up
protected ModelConfig(HierarchicalINIConfiguration config, File basePath) {
    this.config = config;
    this.basePath = basePath;
}
 
Example #29
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 4 votes vote down vote up
public HierarchicalINIConfiguration getHierarchicalIniConfiguration() {
    return hierarchicalIniConfiguration_;
}
 
Example #30
Source File: Notifier.java    From yfiton with Apache License 2.0 4 votes vote down vote up
protected HierarchicalINIConfiguration getConfiguration() {
    return configuration;
}