org.zanata.client.config
Class ConfigUtil

java.lang.Object
  extended by org.zanata.client.config.ConfigUtil

public class ConfigUtil
extends Object


Constructor Summary
ConfigUtil()
           
 
Method Summary
static String findPrefix(org.apache.commons.configuration.SubnodeConfiguration config, URL url)
          Finds the key prefix, within an ini subnode (eg [servers]) with the specified url.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigUtil

public ConfigUtil()
Method Detail

findPrefix

public static String findPrefix(org.apache.commons.configuration.SubnodeConfiguration config,
                                URL url)
Finds the key prefix, within an ini subnode (eg [servers]) with the specified url.

If the ini contains:

 [servers]
 a.username=alice
 a.url=http://a.example.com
 b.username=bob
 b.url=http://b.example.com
 
then the code
 servers = config.getSection("servers"); 
 String prefix = findPrefix(servers, new URL("http://b.example.com"))
 String username = servers.getString(prefix+".username");
 
will return "bob";

Due to an anomaly/bug in the current version of Apache Commons Configuration's iterator, the returned prefix is actually "b." (with a dot), and the runtime key for "b.url" is actually "b..url". Fortunately the config.get* commands are consistent with this, so if you reference servers.getString(prefix+".username") the value "bob" will be returned anyway.

Parameters:
config -
url -
Returns:


Copyright © 2013 Zanata Project. All Rights Reserved.