Java Code Examples for org.ini4j.Ini#add()

The following examples show how to use org.ini4j.Ini#add() . 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: SvnConfigFiles.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Merges only sections/keys/values into target which are not already present in source
 * 
 * @param source the source ini file
 * @param target the target ini file in which the values from the source file are going to be merged
 */
private void merge(Ini source, Ini target) {
    for (Iterator<String> itSections = source.keySet().iterator(); itSections.hasNext();) {
        String sectionName = itSections.next();
        Ini.Section sourceSection = source.get( sectionName );
        Ini.Section targetSection = target.get( sectionName );

        if(targetSection == null) {
            targetSection = target.add(sectionName);
        }

        for (Iterator<String> itVariables = sourceSection.keySet().iterator(); itVariables.hasNext();) {
            String key = itVariables.next();

            if(!targetSection.containsKey(key)) {
                targetSection.put(key, sourceSection.get(key));
            }
        }            
    }
}
 
Example 2
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Merges only sections/keys/values into target which are not already present in source
 * 
 * @param source the source ini file
 * @param target the target ini file in which the values from the source file are going to be merged
 */
private void merge(Ini source, Ini target) {
    for (Iterator<String> itSections = source.keySet().iterator(); itSections.hasNext();) {
        String sectionName = itSections.next();
        Ini.Section sourceSection = source.get( sectionName );
        Ini.Section targetSection = target.get( sectionName );

        if(targetSection == null) {
            targetSection = target.add(sectionName);
        }

        for (Iterator<String> itVariables = sourceSection.keySet().iterator(); itVariables.hasNext();) {
            String key = itVariables.next();

            if(!targetSection.containsKey(key)) {
                targetSection.put(key, sourceSection.get(key));
            }
        }            
    }
}
 
Example 3
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void patch(Ini file) {
    // patch store-auth-creds to "no"
    Ini.Section auth = (Ini.Section) file.get("auth");                  // NOI18N
    if(auth == null) {
        auth = file.add("auth");                                        // NOI18N
    }
    auth.put("store-auth-creds", "yes");                                // NOI18N
    auth.put("store-passwords", "no");                                  // NOI18N
    auth.put("password-stores", "");                                    // NOI18N
}
 
Example 4
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Ini.Section getSection(Ini ini, String key, boolean create) {
    Ini.Section section = ini.get(key);
    if(section == null) {
        return ini.add(key);
    }
    return section;
}
 
Example 5
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Ini.Section getSection(Ini ini, String key, boolean create) {
    Ini.Section section = ini.get(key);
    if(section == null && create) {
        return ini.add(key);
    }
    return section;
}