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;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
/**
* Servlet is used for retrieval of plugin icons.
......@@ -44,28 +45,22 @@ public class PluginIconServlet extends HttpServlet {
@Override
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();
Plugin plugin = pluginManager.getPlugin(pluginName);
if (plugin != null) {
// Try looking for PNG file first then default to GIF.
File icon = new File(pluginManager.getPluginDirectory(plugin), "logo_small.png");
boolean isPng = true;
if (!icon.exists()) {
icon = new File(pluginManager.getPluginDirectory(plugin), "logo_small.gif");
isPng = false;
}
if (icon.exists()) {
PluginMetadata metadata = pluginManager.getMetadata( canonicalName );
if (metadata != null) {
final URL icon = metadata.getIcon();
if ( icon != null ) {
// Clear any empty lines added by the JSP declaration. This is required to show
// the image in resin!
response.reset();
if (isPng) {
if ( icon.toExternalForm().toLowerCase().endsWith( ".png" )) {
response.setContentType("image/png");
}
else {
else if (icon.toExternalForm().toLowerCase().endsWith( ".png" )) {
response.setContentType("image/gif");
}
try (InputStream in = new FileInputStream(icon)) {
try (InputStream in = icon.openStream()) {
try (OutputStream ost = response.getOutputStream()) {
byte[] buf = new byte[1024];
int len;
......
......@@ -280,7 +280,7 @@ public class PluginManager
/**
* 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
* 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
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.
*
......
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