throw new ServletException("Could not load database configuration", e);
}
// The configuration is wrapped in a <xindice> element so we need to get
// the "root-collection" configuration.
Configuration conf = new Configuration(configuration, false);
try {
conf = conf.getChild("root-collection", false);
if (conf != null) {
// We need to ensure that the database points to a place where it makes
// sense. If the path in the system.xml file is an absolute path, then
// honor it. If it's not, we first check for the system property "xindice.db.home"
// and if the lookup is successful we use it as the database root parent. If
// the property is not set, we use /WEB-INF relative to the servlet context, unless
// the war has not been unpacked. In this case, we throw an exception and
// ask the user to specify the location of database root
String dbRoot = conf.getAttribute(Database.DBROOT, "./db/");
File dbRootDir = new File(dbRoot);
if (dbRootDir.isAbsolute()) {
db.setConfig(conf);
} else {
// OK, no absolute path. We have to perform some checks.
// Stupid hack but spec compliant. If getRealPath() returns null
// the war archive has not been unpacked.
String realPath = config.getServletContext().getRealPath("/WEB-INF");
// Let's see if the property was specified.
String home = System.getProperty("xindice.db.home");
if (home != null) {
conf.setAttribute(Database.DBROOT, home + System.getProperty("file.separator") + dbRoot);
} else if (realPath != null) {
if (log.isWarnEnabled())
log.warn("The database root directory has been set to "
+ realPath + System.getProperty("file.separator") + dbRoot
+ ". Keep in mind that if a war upgrade will take place the database"
+ " will be lost.");
conf.setAttribute(Database.DBROOT, realPath + System.getProperty("file.separator") + dbRoot);
} else {
log.fatal("The database configuration points to a relative path, "
+ "but there was no xindice.home property set. "
+ "Furthermore, the war was not unpacked by the application server "
+ "so Xindice was unable to find a database location "