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