void readConfiguration(ExtensionDescriptor descriptor, Element element) throws ExtensionException {
// Plugin name
String name = element.getAttributeValue("name");
if (name == null || name.equals("")) {
throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR,
"The name attribute must be supplied for <plugin> elements (" + descriptor.getApplicationBundle().getFile().getPath() + ").");
}
// Plugin classname
String className = element.getAttributeValue("class");
if (className == null || className.equals("")) {
throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR,
"The class attribute must be supplied for <plugin> elements (" + descriptor.getApplicationBundle().getFile().getPath() + ").");
}
// Order
String orderText = element.getAttributeValue("order");
int order = 999;
if (orderText != null && !orderText.equals("")) {
order = Integer.parseInt(orderText);
}
isolate = "true".equals(element.getAttributeValue("isolate"));
// Optional
String dependencies = element.getAttributeValue("dependencies");
if (dependencies != null) {
log.warn("DEPRECATED. dependencies attribute in plugin definition in "
+ descriptor.getApplicationBundle().getFile().getAbsolutePath() + " should now use 'depends'.");
} else {
dependencies = element.getAttributeValue("depends");
}
def = new PluginDefinition(descriptor);
// Required
def.setName(name);
def.setClassName(className);
// Optional
def.setOrder(order);
/* If this is a dev extension, we generate the paths to add */
if(!descriptor.getApplicationBundle().isDevExtension()) {
for (Iterator i = element.getChildren().iterator(); i.hasNext();) {
Element el = (Element) i.next();
if (el.getName().equals("classpath")) {
String path = Util.trimmedBothOrBlank(el.getText());
if (!path.equals("")) {
File f = new File(descriptor.getApplicationBundle().getBaseDir(), path);
if (f.exists()) {
try {
// NOTE - Do not fix this deprecation warning (Java 6+). It will break plugin JSP compiling. See brett
URL u = f.getCanonicalFile().toURL();
if (log.isInfoEnabled())
log.info("Adding " + u + " to classpath");
def.addClassPath(u);
} catch (IOException murle) {
throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR,
murle, "Invalid classpath.");
}
} else {
if (!"true".equals(SystemProperties.get("adito.useDevConfig"))) {
log.warn("Plugin classpath element " + f.getAbsolutePath() + " does not exist.");
}
}
}
} else if (el.getName().equals("resources")) {
File f = new File(descriptor.getApplicationBundle().getBaseDir(), el.getText());
if (f.exists() && f.isDirectory()) {
try {
// NOTE - Do not fix this deprecation warning (Java 6+). It will break plugin JSP compiling. See brett
def.addResourceBase(f.getCanonicalFile().toURL());
} catch (Exception ex) {
throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, ex, "Invalid resource base.");
}
} else {
if (log.isInfoEnabled())
log.info("<resources> element does not point to a valid directory.");
}
} else if (el.getName().equals("native")) {
File f = new File(descriptor.getApplicationBundle().getBaseDir(), el.getText());
if (f.exists() && f.isDirectory()) {
try {
def.addNativeDirectory(f.getCanonicalFile());
} catch (Exception ex) {
throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR,
ex, "Invalid native directory.");
}
} else {
if (log.isInfoEnabled())
log.info("<native> element does not point to a valid directory.");
}
} else {
throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR,
"The <plugin> element only supports the nested <classpath>, <resources> or <native> elements");
}
}
}