Commit 82911ecd authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Moved over to using PluginIconServlet.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4187 b35dd754-fafc-0310-a699-88a17e54d16e
parent 866d8c58
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.wildfire.container;
import org.jivesoftware.util.ParamUtils;
import org.jivesoftware.wildfire.XMPPServer;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Servlet is used for retrieval of plugin icons.
*
* @author Derek DeMoro
*/
public class PluginIconServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
String pluginName = 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()) {
// Clear any empty lines added by the JSP declaration. This is required to show
// the image in resin!
response.reset();
if (isPng) {
response.setContentType("image/png");
}
else {
response.setContentType("image/gif");
}
InputStream in = null;
OutputStream ost = null;
try {
in = new FileInputStream(icon);
ost = response.getOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) >= 0) {
ost.write(buf, 0, len);
}
ost.flush();
}
catch (IOException ioe) {
}
finally {
if (in != null) {
try {
in.close();
}
catch (Exception e) {
}
}
if (ost != null) {
try {
ost.close();
}
catch (Exception e) {
}
}
}
}
}
}
}
...@@ -108,6 +108,11 @@ ...@@ -108,6 +108,11 @@
</init-param> </init-param>
</servlet> </servlet>
<servlet>
<servlet-name>PluginIconServlet</servlet-name>
<servlet-class>org.jivesoftware.wildfire.container.PluginIconServlet</servlet-class>
</servlet>
<!--@@JSPC-SERVLETS@@--> <!--@@JSPC-SERVLETS@@-->
...@@ -121,6 +126,11 @@ ...@@ -121,6 +126,11 @@
<url-pattern>/getFavicon</url-pattern> <url-pattern>/getFavicon</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping>
<servlet-name>PluginIconServlet</servlet-name>
<url-pattern>/geticon</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>dwr-invoker</servlet-name> <servlet-name>dwr-invoker</servlet-name>
......
...@@ -466,7 +466,7 @@ ...@@ -466,7 +466,7 @@
<tr> <tr>
<td class="line-bottom-border" width="1%"> <td class="line-bottom-border" width="1%">
<% if (icon.exists()) { %> <% if (icon.exists()) { %>
<img src="plugin-icon.jsp?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showIcon=true&decorator=none" width="16" height="16" alt="Plugin"> <img src="/geticon?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showIcon=true&decorator=none" width="16" height="16" alt="Plugin">
<% } <% }
else { %> else { %>
<img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin"> <img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin">
......
...@@ -461,7 +461,7 @@ else if ("false".equals(request.getParameter("deletesuccess"))) { %> ...@@ -461,7 +461,7 @@ else if ("false".equals(request.getParameter("deletesuccess"))) { %>
<tr valign="top"> <tr valign="top">
<td width="1%" class="<%= update != null ? "update-top-left" : "line-bottom-border"%>"> <td width="1%" class="<%= update != null ? "update-top-left" : "line-bottom-border"%>">
<% if (icon.exists()) { %> <% if (icon.exists()) { %>
<img src="plugin-icon.jsp?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showIcon=true&decorator=none" width="16" height="16" alt="Plugin"> <img src="geticon?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showIcon=true&decorator=none" width="16" height="16" alt="Plugin">
<% } <% }
else { %> else { %>
<img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin"> <img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin">
......
<%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.wildfire.container.Plugin"%>
<%@ page import="java.io.*"%>
<%@ page import="org.jivesoftware.wildfire.container.PluginManager"%>
<%@ page import="org.jivesoftware.wildfire.XMPPServer"%>
<%
String pluginName = 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()) {
// Clear any empty lines added by the JSP declaration. This is required to show
// the image in resin!
response.reset();
if (isPng) {
response.setContentType("image/png");
}
else {
response.setContentType("image/gif");
}
InputStream in = null;
OutputStream ost = null;
try {
in = new FileInputStream(icon);
ost = response.getOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) >= 0) {
ost.write(buf,0,len);
}
ost.flush();
}
catch (IOException ioe) {
}
finally {
if (in != null) {
try { in.close(); } catch (Exception e) { }
}
if (ost != null) {
try { ost.close(); } catch (Exception e) { }
}
}
}
}
%>
\ 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