Commit 92450df2 authored by Guus der Kinderen's avatar Guus der Kinderen

Allow icons to be served for extracted but not loaded plugins.

parent fee25623
...@@ -29,6 +29,7 @@ import java.io.FileInputStream; ...@@ -29,6 +29,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL;
/** /**
* Servlet is used for retrieval of plugin icons. * Servlet is used for retrieval of plugin icons.
...@@ -44,28 +45,22 @@ public class PluginIconServlet extends HttpServlet { ...@@ -44,28 +45,22 @@ public class PluginIconServlet extends HttpServlet {
@Override @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
String pluginName = ParamUtils.getParameter(request, "plugin"); String canonicalName = ParamUtils.getParameter(request, "plugin");
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager(); PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
Plugin plugin = pluginManager.getPlugin(pluginName); PluginMetadata metadata = pluginManager.getMetadata( canonicalName );
if (plugin != null) { if (metadata != null) {
// Try looking for PNG file first then default to GIF. final URL icon = metadata.getIcon();
File icon = new File(pluginManager.getPluginDirectory(plugin), "logo_small.png"); if ( icon != null ) {
boolean isPng = true;
if (!icon.exists()) {
icon = new File(pluginManager.getPluginDirectory(plugin), "logo_small.gif");
isPng = false;
}
if (icon.exists()) {
// Clear any empty lines added by the JSP declaration. This is required to show // Clear any empty lines added by the JSP declaration. This is required to show
// the image in resin! // the image in resin!
response.reset(); response.reset();
if (isPng) { if ( icon.toExternalForm().toLowerCase().endsWith( ".png" )) {
response.setContentType("image/png"); response.setContentType("image/png");
} }
else { else if (icon.toExternalForm().toLowerCase().endsWith( ".png" )) {
response.setContentType("image/gif"); response.setContentType("image/gif");
} }
try (InputStream in = new FileInputStream(icon)) { try (InputStream in = icon.openStream()) {
try (OutputStream ost = response.getOutputStream()) { try (OutputStream ost = response.getOutputStream()) {
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int len; int len;
......
...@@ -280,7 +280,7 @@ public class PluginManager ...@@ -280,7 +280,7 @@ public class PluginManager
/** /**
* Returns metadata for all extracted plugins, mapped by their canonical name. * Returns metadata for all extracted plugins, mapped by their canonical name.
* *
* The collection is alphabeticially sorted, by plugin name. * The collection is alphabetically sorted, by plugin name.
* *
* Note that an <em>installed</em> plugin is not per definition an <em>extracted</em> plugin, and an extracted * Note that an <em>installed</em> plugin is not per definition an <em>extracted</em> plugin, and an extracted
* plugin is not per definition a <em>loaded</em> plugin. A plugin that's extracted might, for instance, fail to * plugin is not per definition a <em>loaded</em> plugin. A plugin that's extracted might, for instance, fail to
...@@ -293,6 +293,20 @@ public class PluginManager ...@@ -293,6 +293,20 @@ public class PluginManager
return Collections.unmodifiableMap( this.pluginMetadata ); return Collections.unmodifiableMap( this.pluginMetadata );
} }
/**
* Returns metadata for an extracted plugin, or null when the plugin is extracted nor loaded.
*
* Note that an <em>installed</em> plugin is not per definition an <em>extracted</em> plugin, and an extracted
* plugin is not per definition a <em>loaded</em> plugin. A plugin that's extracted might, for instance, fail to
* load, due to restrictions imposed by its <tt>minServerVersion</tt> definition.
*
* @return A collection of metadata (possibly empty, never null).
*/
public PluginMetadata getMetadata( String canonicalName )
{
return this.pluginMetadata.get( canonicalName );
}
/** /**
* Returns a Collection of all loaded plugins. * Returns a Collection of all loaded plugins.
* *
......
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