Search in sources :

Example 21 with Ini

use of org.ini4j.Ini in project NoraUi by NoraUi.

the class Utilities method getSelectorValue.

/**
 * @param applicationKey
 *            is key of application
 * @param code
 *            is key of selector (CAUTION: if you use any % char. {@link String#format(String, Object...)})
 * @param args
 *            is list of args ({@link String#format(String, Object...)})
 * @return the selector
 */
public static String getSelectorValue(String applicationKey, String code, Object... args) {
    String selector = "";
    logger.debug("getLocator with this application key : {}", applicationKey);
    logger.debug("getLocator with this locator file : {}", Context.iniFiles.get(applicationKey));
    final Ini ini = Context.iniFiles.get(applicationKey);
    final Map<String, String> section = ini.get(code);
    if (section != null) {
        final Entry<String, String> entry = section.entrySet().iterator().next();
        selector = String.format(entry.getValue(), args);
    }
    return selector;
}
Also used : Ini(org.ini4j.Ini)

Example 22 with Ini

use of org.ini4j.Ini in project iri by iotaledger.

the class Configuration method init.

public boolean init() throws IOException {
    File confFile = new File(string(Configuration.DefaultConfSettings.CONFIG));
    if (confFile.exists()) {
        ini = new Ini(confFile);
        prefs = new IniPreferences(ini);
        return true;
    }
    return false;
}
Also used : Ini(org.ini4j.Ini) IniPreferences(org.ini4j.IniPreferences) File(java.io.File)

Example 23 with Ini

use of org.ini4j.Ini in project MSEC by Tencent.

the class ServiceFactory method getConfig.

public static String getConfig(String section, String key) {
    Ini ini = new Ini();
    try {
        ini.load(new File(SRPC_CONF_PATH));
        Profile.Section sec = ini.get(section);
        if (sec != null) {
            return sec.get(key);
        }
    } catch (IOException e) {
        log.error("get config " + section + ":" + key + " failed.", e);
    }
    return null;
}
Also used : Ini(org.ini4j.Ini) IOException(java.io.IOException) File(java.io.File) Profile(org.ini4j.Profile)

Example 24 with Ini

use of org.ini4j.Ini in project MSEC by Tencent.

the class AddSecondLevelServiceConfigTag method addPortConfig.

public void addPortConfig(String filename, int port) throws Exception {
    final String SECTION_NAME = "SRPC";
    final String KEY = "listen";
    // listen=e123/udp 234/tcp
    final String VALUE = String.format("%d/udp %d/tcp", port, port);
    Ini ini = new Ini();
    ini.load(new File(filename));
    Ini.Section section = ini.get(SECTION_NAME);
    boolean bChanged = false;
    if (section == null) {
        section = ini.add(SECTION_NAME);
        section.add(KEY, VALUE);
        bChanged = true;
    } else {
        String valueStr = section.get(KEY);
        if (valueStr == null) {
            section.add(KEY, VALUE);
            bChanged = true;
        } else {
            if (!valueStr.equalsIgnoreCase(VALUE)) {
                // logger.error("port config exists,but value mismatch!"+valueStr+"!="+VALUE);
                section.put(KEY, VALUE);
                bChanged = true;
            }
        }
    }
    if (bChanged) {
        ini.store(new File(filename));
    }
}
Also used : Ini(org.ini4j.Ini) File(java.io.File)

Aggregations

Ini (org.ini4j.Ini)24 File (java.io.File)9 IOException (java.io.IOException)6 StringReader (java.io.StringReader)3 URL (java.net.URL)3 Map (java.util.Map)3 Profile (org.ini4j.Profile)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 CompositeMap (org.apache.commons.collections4.map.CompositeMap)2 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)2 IOption (org.apache.hyracks.api.config.IOption)2 Config (org.ini4j.Config)2 Hypervisor (com.cloud.hypervisor.Hypervisor)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1