private void prepareModules() {
String[] resourceModules = new String[] {
options.getUrisModule(), options.getProcessModule() };
String modulesDatabase = options.getModulesDatabase();
logger.info("checking modules, database: " + modulesDatabase);
Session session = contentSource.newSession(modulesDatabase);
InputStream is = null;
Content c = null;
ContentCreateOptions opts = ContentCreateOptions
.newTextInstance();
try {
for (int i = 0; i < resourceModules.length; i++) {
// Start by checking install flag.
if (!options.isDoInstall()) {
logger.info("Skipping module installation: "
+ resourceModules[i]);
continue;
}
// Next check: if XCC is configured for the filesystem, warn
// user
else if (options.getModulesDatabase().equals("")) {
logger
.warning("XCC configured for the filesystem: please install modules manually");
return;
}
// Finally, if it's configured for a database, install.
else {
File f = new File(resourceModules[i]);
// If not installed, are the specified files on the
// filesystem?
if (f.exists()) {
moduleUri = options.getModuleRoot() + f.getName();
c = ContentFactory.newContent(moduleUri, f, opts);
}
// finally, check package
else {
logger.warning("looking for "
+ resourceModules[i] + " as resource");
moduleUri = options.getModuleRoot()
+ resourceModules[i];
is = this.getClass().getResourceAsStream(
resourceModules[i]);
if (null == is) {
throw new NullPointerException(
resourceModules[i]
+ " could not be found on the filesystem,"
+ " or in package resources");
}
c = ContentFactory
.newContent(moduleUri, is, opts);
}
session.insertContent(c);
}
}
} catch (IOException e) {
logger.logException("fatal error", e);
throw new RuntimeException(e);
} catch (RequestException e) {
logger.logException("fatal error", e);
throw new RuntimeException(e);
} finally {
session.close();
}
}