{
throw new ConfigurationException("Only one external virtualhosts configuration file allowed, multiple filenames found.");
}
// Virtualhost configuration object
Configuration vhostConfiguration = new HierarchicalConfiguration();
// Load from embedded configuration if possible
if (!vhostConfig.subset("virtualhost").isEmpty())
{
vhostConfiguration = vhostConfig;
}
else
{
// Load from the external configuration if possible
for (String fileName : vhostFiles)
{
// Open the vhosts XML file and copy values from it to our config
_vhostsFile = new File(fileName);
if (!_vhostsFile.exists())
{
throw new ConfigurationException("Virtualhosts file does not exist");
}
vhostConfiguration = parseConfig(new File(fileName));
// save the default virtualhost name
String defaultVirtualHost = vhostConfiguration.getString("default");
getConfig().setProperty("virtualhosts.default", defaultVirtualHost);
}
}
// Now extract the virtual host names from the configuration object
List hosts = vhostConfiguration.getList("virtualhost.name");
for (int j = 0; j < hosts.size(); j++)
{
String name = (String) hosts.get(j);
// Add the virtual hosts to the server configuration
VirtualHostConfiguration virtualhost = new VirtualHostConfiguration(name, vhostConfiguration.subset("virtualhost." + name));
_virtualHosts.put(virtualhost.getName(), virtualhost);
}
}