String identifier = XPathHelper.valueOf(config, "@id", xpathProcessor);
if (identifier == null)
throw new IllegalStateException("Unable to create module without identifier");
// class
Module module = null;
String className = XPathHelper.valueOf(config, "m:class", xpathProcessor);
if (className != null) {
try {
Class<? extends Module> c = (Class<? extends Module>) classLoader.loadClass(className);
module = c.newInstance();
module.setIdentifier(identifier);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Implementation " + className + " for module '" + identifier + "' not found", e);
} catch (InstantiationException e) {
throw new IllegalStateException("Error instantiating impelementation " + className + " for module '" + identifier + "'", e);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Access violation instantiating implementation " + className + " for module '" + identifier + "'", e);
} catch (Throwable t) {
throw new IllegalStateException("Error loading implementation " + className + " for module '" + identifier + "'", t);
}
} else {
module = new ModuleImpl();
module.setIdentifier(identifier);
}
// Check if module is enabled
Boolean enabled = Boolean.valueOf(XPathHelper.valueOf(config, "m:enable", xpathProcessor));
module.setEnabled(enabled);
// name
String name = XPathHelper.valueOf(config, "m:name", xpathProcessor);
module.setName(name);
// pagelets
NodeList pageletNodes = XPathHelper.selectList(config, "m:pagelets/m:pagelet", xpathProcessor);
for (int i = 0; i < pageletNodes.getLength(); i++) {
PageletRenderer pagelet = PageletRendererImpl.fromXml(pageletNodes.item(i), xpathProcessor);
module.addRenderer(pagelet);
}
// actions
NodeList actionNodes = XPathHelper.selectList(config, "m:actions/m:action", xpathProcessor);
for (int i = 0; i < actionNodes.getLength(); i++) {
module.addAction(ActionSupport.fromXml(actionNodes.item(i), xpathProcessor));
}
// image styles
NodeList imagestyleNodes = XPathHelper.selectList(config, "m:imagestyles/m:imagestyle", xpathProcessor);
for (int i = 0; i < imagestyleNodes.getLength(); i++) {
module.addImageStyle(ImageStyleImpl.fromXml(imagestyleNodes.item(i), xpathProcessor));
}
// jobs
NodeList jobNodes = XPathHelper.selectList(config, "m:jobs/m:job", xpathProcessor);
for (int i = 0; i < jobNodes.getLength(); i++) {
module.addJob(QuartzJob.fromXml(jobNodes.item(i), xpathProcessor));
}
// options
Node optionsNode = XPathHelper.select(config, "m:options", xpathProcessor);
OptionsHelper.fromXml(optionsNode, module, xpathProcessor);