Java Code Examples for org.ini4j.Ini#Section

The following examples show how to use org.ini4j.Ini#Section . 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
/**
 * Returns the section from the <b>servers</b> config file used by the Subversion module which 
 * is holding the proxy settings for the given host
 *
 * @param host the host
 * @return the section holding the proxy settings for the given host
 */ 
private Ini.Section getServerGroup(String host) {
    if(host == null || host.equals("")) {                                   // NOI18N
        return null;
    }
    Ini.Section groups = svnServers.get(GROUPS_SECTION);
    if(groups != null) {
        for (Iterator<String> it = groups.keySet().iterator(); it.hasNext();) {
            String key = it.next();
            String value = groups.get(key);
            if(value != null) {     
                value = value.trim();                    
                if(value != null && match(value, host)) {
                    return svnServers.get(key);
                }      
            }
        }
    }
    return null;
}
 
Example 2
Source File: FromHereCredentialsIniStream.java    From here-aaa-java-sdk with Apache License 2.0 6 votes vote down vote up
static Properties getPropertiesFromIni(InputStream inputStream, String sectionName) throws IOException {
    Ini ini = new Ini();
    try (Reader reader = new InputStreamReader(inputStream, OAuthConstants.UTF_8_CHARSET)) {
        ini.load(reader);
        Ini.Section section = ini.get(sectionName);
        Properties properties = new Properties();
        properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY,
                section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY));
        properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY,
                section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY));
        properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY,
                section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY));
        // scope is optional
        String scope = section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY);
        if (null != scope)
            properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY, scope);

        return properties;
    }
}
 
Example 3
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 4
Source File: AutoHelper.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static String getLocationFromIni( String iniLocation )
	throws IOException {
	// Format: "/Section/Key:URL_to_ini"
	String[] ss = iniLocation.split( ":", 2 );
	assertIOException( ss.length < 2, "invalid ini location; the format is /Section/Key:URL_to_ini" );

	String[] iniPath = ss[ 0 ].split( "/", 3 );
	assertIOException( iniPath.length < 3, "path to ini content is not well-formed; the format is /Section/Key" );

	URL iniURL = new URL( ss[ 1 ] );

	try( Reader reader = new InputStreamReader( iniURL.openStream() ) ) {
		Ini ini = new Ini( reader );

		Ini.Section section = ini.get( iniPath[ 1 ] );
		assertIOException( section == null, "could not find section " + iniPath[ 1 ] + " in ini" );

		String retLocation = section.get( iniPath[ 2 ] );
		assertIOException( retLocation == null,
			"could not find key " + iniPath[ 2 ] + " in section " + iniPath[ 1 ] + " in ini" );

		return retLocation;
	}
}
 
Example 5
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 6
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean setSSLCert(RepositoryConnection rc, Ini.Section nbGlobalSection) {
    if(rc == null) {
        return false;
    }
    String certFile = rc.getCertFile();
    if(certFile == null || certFile.equals("")) {
        return false;
    }
    char[] certPasswordChars = rc.getCertPassword();
    String certPassword = certPasswordChars == null ? "" : new String(certPasswordChars); //NOI18N
    if(certPassword.equals("")) { // NOI18N
        return false;
    }
    nbGlobalSection.put("ssl-client-cert-file", certFile);
    if (!DO_NOT_SAVE_PASSPHRASE) {
        nbGlobalSection.put("ssl-client-cert-password", certPassword);
        return true;
    }
    return false;
}
 
Example 7
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setExternalCommand(String tunnelName, String command) {
    if (command == null) {
        return;
    }
    if (Utilities.isWindows()) {
        // tunnel command should contain forward slashes even on windows
        command = command.replace("\\", "/");                       //NOI18N
    }
    Ini.Section tunnels = getSection(config, "tunnels", true);
    tunnels.put(tunnelName, command);
    storeIni(config, "config");                                                     // NOI18N
}
 
Example 8
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 9
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the miscellany/global-ignores setting from the config file.
 *
 * @return a list with the inore patterns
 *
 */
public List<String> getGlobalIgnores() {
    Ini.Section miscellany = config.get("miscellany");                      // NOI18N
    if (miscellany != null) {
        String ignores = miscellany.get("global-ignores");                  // NOI18N
        if (ignores != null && ignores.trim().length() > 0) {
            return parseGlobalIgnores(ignores);
        }
    }
    return DEFAULT_GLOBAL_IGNORES;
}
 
Example 10
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String getMergeValue(String key, String host) {
    Ini.Section group = getServerGroup(host);
    if(group != null) {
        return group.get(key);
    }
    group = svnServers.get(GLOBAL_SECTION);
    if(group != null) {
        return group.get(key);
    }
    return null;
}
 
Example 11
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 12
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void mergeNonProxyKeys(Ini.Section source, Ini.Section target) {
    for (String key : source.keySet()) {
        if(!isProxyConfigurationKey(key)) {
            target.put(key, source.get(key));                                                
        }                    
    }
}
 
Example 13
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Properties getProperties(String section) {
    Ini.Section inisection = getSection(hgrc, section, false);
    Properties props = new Properties();
    if (inisection != null) {
        Set<String> keys = inisection.keySet();
        for (String key : keys) {
            props.setProperty(key, inisection.get(key));
        }
    }
    return props;
}
 
Example 14
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void mergeNonProxyKeys(String host, Ini.Section svnGlobalSection, Ini.Section nbGlobalSection) {                             
    if(svnGlobalSection != null) {
        // if there is a global section, than get the no proxy settings                                                                 
        mergeNonProxyKeys(svnGlobalSection, nbGlobalSection);
    }
    Ini.Section svnHostGroup = getServerGroup(host);
    if(svnHostGroup != null) {
        // if there is a section for the given host, than get the no proxy settings                                                                 
        mergeNonProxyKeys(svnHostGroup, nbGlobalSection);                
    }                                
}
 
Example 15
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void removeProperty(String section, String name) {
    Ini.Section inisection = getSection(hgrc, section, false);
    if (inisection != null) {
         inisection.remove(name);
        if (!bIsProjectConfig && Utilities.isWindows()) {
            storeIni(hgrc, configFileName);
        } else {
            storeIni(hgrc, configFileName);
        }
     }
}
 
Example 16
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;
}
 
Example 17
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean setProxy(SVNUrl url, Ini.Section nbGlobalSection) {
    String host =  SvnUtils.ripUserFromHost(url.getHost());        
    Ini.Section svnGlobalSection = svnServers.get(GLOBAL_SECTION);
    URI uri = null;
    boolean passwordAdded = false;
    try {
        uri = new URI(url.toString());
    } catch (URISyntaxException ex) {
        Subversion.LOG.log(Level.INFO, null, ex);
        return passwordAdded;
    }
    String proxyHost = NetworkSettings.getProxyHost(uri);
    // check DIRECT connection
    if(proxyHost != null && proxyHost.length() > 0) {
        String proxyPort = NetworkSettings.getProxyPort(uri);
        assert proxyPort != null;
        nbGlobalSection.put("http-proxy-host", proxyHost);                     // NOI18N
        nbGlobalSection.put("http-proxy-port", proxyPort);                     // NOI18N

        // and the authentication
        String username = NetworkSettings.getAuthenticationUsername(uri);
        if(username != null) {
            String password = getProxyPassword(NetworkSettings.getKeyForAuthenticationPassword(uri));

            nbGlobalSection.put("http-proxy-username", username);                               // NOI18N
            nbGlobalSection.put("http-proxy-password", password);                               // NOI18N
            passwordAdded = true;
        }
    }
    // check if there are also some no proxy settings
    // we should get from the original svn servers file
    mergeNonProxyKeys(host, svnGlobalSection, nbGlobalSection);
    return passwordAdded;
}
 
Example 18
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public String getExternalCommand(String tunnelName) {
    Ini.Section tunnels = getSection(config, "tunnels", true);
    String cmd = tunnels.get(tunnelName);
    return cmd != null ? cmd : "";        
}
 
Example 19
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public String getProperty(String section, String name) {
    Ini.Section inisection = getSection(hgrc, section, true);
    String value = inisection.get(name);
    return value != null ? value : "";        // NOI18N 
}
 
Example 20
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean containsProperty(String section, String name) {
    Ini.Section inisection = getSection(hgrc, section, true);
    return inisection.containsKey(name);
}