Commit ff609f6d authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

1) "JM-432" Jive Messenger does not handle different web types (flash, applets, etc.)

2) Added Sound support in Live Assistant.

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@2993 b35dd754-fafc-0310-a699-88a17e54d16e
parent c6a1fdca
......@@ -21,6 +21,7 @@ import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
/**
* ClassLoader for plugins. It searches the plugin directory for classes
......@@ -43,8 +44,8 @@ class PluginClassLoader {
* Constructs a plugin loader for the given plugin directory.
*
* @param pluginDir the plugin directory.
* @throws java.lang.SecurityException if the created class loader violates
* existing security constraints.
* @throws SecurityException if the created class loader violates
* existing security constraints.
*/
public PluginClassLoader(File pluginDir) throws SecurityException {
addDirectory(pluginDir);
......@@ -58,29 +59,33 @@ class PluginClassLoader {
*/
public void addDirectory(File directory) {
try {
File classesDir = new File(directory, "classes");
if (classesDir.exists()) {
list.add(classesDir.toURL());
}
File libDir = new File(directory, "lib");
File[] jars = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar") || name.endsWith(".zip");
File classesDir = new File(directory, "classes");
if (classesDir.exists()) {
list.add(classesDir.toURL());
}
});
if (jars != null) {
for (int i = 0; i < jars.length; i++) {
if (jars[i] != null && jars[i].isFile()) {
list.add(jars[i].toURL());
File libDir = new File(directory, "lib");
File[] jars = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar") || name.endsWith(".zip");
}
});
if (jars != null) {
for (int i = 0; i < jars.length; i++) {
if (jars[i] != null && jars[i].isFile()) {
list.add(jars[i].toURL());
}
}
}
}
}
catch (MalformedURLException mue) {
Log.error(mue);
}
}
public Collection<URL> getURLS(){
return list;
}
/**
* Adds a URL to the class loader. The {@link #initialize()} method should be called
* after adding the URL to make the change take effect.
......@@ -95,13 +100,21 @@ class PluginClassLoader {
* Initializes the class loader with all configured classpath URLs. This method
* can be called multiple times if the list of URLs changes.
*/
public void initialize(){
public void initialize() {
Iterator urls = list.iterator();
URL[] urlArray = new URL[list.size()];
for (int i = 0; urls.hasNext(); i++) {
urlArray[i] = (URL)urls.next();
}
classLoader = new URLClassLoader(urlArray, findParentClassLoader());
// If the classloader is to be used by a child plugin, we should
// never use the ContextClassLoader, but only reuse the plugin classloader itself.
if (classLoader != null) {
classLoader = new URLClassLoader(urlArray, classLoader);
}
else {
classLoader = new URLClassLoader(urlArray, findParentClassLoader());
}
}
/**
......@@ -115,7 +128,7 @@ class PluginClassLoader {
* @throws SecurityException if the custom class loader not allowed.
*/
public Class loadClass(String name) throws ClassNotFoundException, IllegalAccessException,
InstantiationException, SecurityException {
InstantiationException, SecurityException {
return classLoader.loadClass(name);
}
......@@ -141,4 +154,4 @@ class PluginClassLoader {
}
return parent;
}
}
\ No newline at end of file
}
......@@ -187,6 +187,7 @@ public class PluginManager {
if (plugins.containsKey(parentPlugin)) {
pluginLoader = classloaders.get(getPlugin(parentPlugin));
pluginLoader.addDirectory(pluginDir);
}
else {
// See if the parent plugin exists but just hasn't been loaded yet.
......@@ -212,7 +213,7 @@ public class PluginManager {
parentPlugin + " not present.";
Log.warn(msg);
System.out.println(msg);
return;
return;
}
}
}
......@@ -270,6 +271,15 @@ public class PluginManager {
String className = pluginXML.selectSingleNode("/plugin/class").getText();
plugin = (Plugin)pluginLoader.loadClass(className).newInstance();
if(parentPluginNode != null){
String parentPlugin = parentPluginNode.getTextTrim();
// See if the parent is already loaded.
if (plugins.containsKey(parentPlugin)) {
pluginLoader = classloaders.get(getPlugin(parentPlugin));
classloaders.put(plugin, pluginLoader);
}
}
plugin.initializePlugin(this, pluginDir);
plugins.put(pluginDir.getName(), plugin);
pluginDirs.put(plugin, pluginDir);
......@@ -312,25 +322,30 @@ public class PluginManager {
// If there a <adminconsole> section defined, register it.
Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole");
if (adminElement != null) {
String pluginName = pluginDir.getName();
if(parentPluginNode != null){
pluginName = parentPluginNode.getTextTrim();
}
// If global images are specified, override their URL.
Element imageEl = (Element)adminElement.selectSingleNode(
"/plugin/adminconsole/global/logo-image");
if (imageEl != null) {
imageEl.setText("plugins/" + pluginDir.getName() + "/" + imageEl.getText());
imageEl.setText("plugins/" + pluginName + "/" + imageEl.getText());
}
imageEl = (Element)adminElement.selectSingleNode(
"/plugin/adminconsole/global/login-image");
imageEl = (Element)adminElement.selectSingleNode("/plugin/adminconsole/global/login-image");
if (imageEl != null) {
imageEl.setText("plugins/" + pluginDir.getName() + "/" + imageEl.getText());
imageEl.setText("plugins/" + pluginName + "/" + imageEl.getText());
}
// Modify all the URL's in the XML so that they are passed through
// the plugin servlet correctly.
List urls = adminElement.selectNodes("//@url");
for (int i = 0; i < urls.size(); i++) {
Attribute attr = (Attribute)urls.get(i);
attr.setValue("plugins/" + pluginDir.getName() + "/" + attr.getValue());
attr.setValue("plugins/" + pluginName + "/" + attr.getValue());
}
AdminConsole.addModel(pluginDir.getName(), adminElement);
AdminConsole.addModel(pluginName, adminElement);
}
}
else {
......@@ -481,6 +496,15 @@ public class PluginManager {
return getElementValue(plugin, "/plugin/version");
}
/**
* Returns the classloader of a plugin.
* @param plugin the plugin.
* @return the classloader of the plugin.
*/
public PluginClassLoader getPluginClassloader(Plugin plugin){
return classloaders.get(plugin);
}
/**
* Returns the value of an element selected via an xpath expression from
* a Plugin's plugin.xml file.
......@@ -543,7 +567,7 @@ public class PluginManager {
if (jars == null) {
return;
}
for (int i = 0; i < jars.length; i++) {
File jarFile = jars[i];
String pluginName = jarFile.getName().substring(0,
......@@ -704,4 +728,4 @@ public class PluginManager {
return dir.delete();
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment