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

1) PluginServlet would re-initialize with multiple plugins.

2) HSQLDB should not be merged.
3) SetupManager 
4) remove migration script.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1115 b35dd754-fafc-0310-a699-88a17e54d16e
parent 059595ae
......@@ -11,22 +11,27 @@
package org.jivesoftware.messenger.container;
import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.util.Log;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.util.Log;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletOutputStream;
import java.io.*;
import java.util.Map;
import java.util.List;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -34,12 +39,12 @@ import java.util.concurrent.ConcurrentHashMap;
* to plugins. Since plugins can be dynamically loaded and live in a different place
* than normal Jive Messenger admin console files, it's not possible to have them
* added to the normal Jive Messenger admin console web app directory.<p>
*
* <p/>
* The servlet listens for requests in the form <tt>/plugins/[pluginName]/[JSP File]</tt>
* (e.g. <tt>/plugins/foo/example.jsp</tt>). It also listens for image requests in the
* the form <tt>/plugins/[pluginName]/images/*.png|gif</tt> (e.g.
* <tt>/plugins/foo/images/example.gif</tt>).<p>
*
* <p/>
* JSP files must be compiled and available via the plugin's class loader. The mapping
* between JSP name and servlet class files is defined in [pluginName]/web/web.xml.
* Typically, this file is auto-generated by the JSP compiler when packaging the plugin.
......@@ -48,20 +53,22 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class PluginServlet extends HttpServlet {
private static Map<String,HttpServlet> servlets;
private static Map<String, HttpServlet> servlets;
private static File pluginDirectory;
private static ServletConfig servletConfig;
static {
servlets = new ConcurrentHashMap<String, HttpServlet>();
pluginDirectory = new File(JiveGlobals.getMessengerHome(), "plugins");
}
public void init(ServletConfig config) throws ServletException {
super.init(config);
servletConfig = config;
servlets = new ConcurrentHashMap<String,HttpServlet>();
pluginDirectory = new File(JiveGlobals.getMessengerHome(), "plugins");
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
throws ServletException, IOException {
String pathInfo = request.getPathInfo();
if (pathInfo == null) {
......@@ -98,9 +105,9 @@ public class PluginServlet extends HttpServlet {
* Registers all JSP page servlets for a plugin.
*
* @param manager the plugin manager.
* @param plugin the plugin.
* @param webXML the web.xml file containing JSP page names to servlet class file
* mappings.
* @param plugin the plugin.
* @param webXML the web.xml file containing JSP page names to servlet class file
* mappings.
*/
public static void registerServlets(PluginManager manager, Plugin plugin, File webXML) {
if (!webXML.exists()) {
......@@ -120,8 +127,8 @@ public class PluginServlet extends HttpServlet {
Document doc = saxReader.read(webXML);
// Find all <servlet> entries to discover name to class mapping.
List classes = doc.selectNodes("//servlet");
Map<String,Class> classMap = new HashMap<String,Class>();
for (int i=0; i<classes.size(); i++) {
Map<String, Class> classMap = new HashMap<String, Class>();
for (int i = 0; i < classes.size(); i++) {
Element servletElement = (Element)classes.get(i);
String name = servletElement.element("servlet-name").getTextTrim();
String className = servletElement.element("servlet-class").getTextTrim();
......@@ -129,7 +136,7 @@ public class PluginServlet extends HttpServlet {
}
// Find all <servelt-mapping> entries to discover name to URL mapping.
List names = doc.selectNodes("//servlet-mapping");
for (int i=0; i<names.size(); i++) {
for (int i = 0; i < names.size(); i++) {
Element nameElement = (Element)names.get(i);
String name = nameElement.element("servlet-name").getTextTrim();
String url = nameElement.element("url-pattern").getTextTrim();
......@@ -155,7 +162,7 @@ public class PluginServlet extends HttpServlet {
* Unregisters all JSP page servlets for a plugin.
*
* @param webXML the web.xml file containing JSP page names to servlet class file
* mappings.
* mappings.
*/
public static void unregisterServlets(File webXML) {
if (!webXML.exists()) {
......@@ -173,7 +180,7 @@ public class PluginServlet extends HttpServlet {
Document doc = saxReader.read(webXML);
// Find all <servelt-mapping> entries to discover name to URL mapping.
List names = doc.selectNodes("//servlet-mapping");
for (int i=0; i<names.size(); i++) {
for (int i = 0; i < names.size(); i++) {
Element nameElement = (Element)names.get(i);
String url = nameElement.element("url-pattern").getTextTrim();
// Destroy the servlet than remove from servlets map.
......@@ -194,15 +201,14 @@ public class PluginServlet extends HttpServlet {
* servlet is found, a 404 error is returned.
*
* @param pathInfo the extra path info.
* @param request the request object.
* @param request the request object.
* @param response the response object.
* @throws ServletException if a servlet exception occurs while handling the
* request.
* @throws IOException if an IOException occurs while handling the request.
* request.
* @throws IOException if an IOException occurs while handling the request.
*/
private void handleJSP(String pathInfo, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
HttpServletResponse response) throws ServletException, IOException {
// Strip the starting "/" from the path to find the JSP URL.
String jspURL = pathInfo.substring(1);
HttpServlet servlet = servlets.get(jspURL);
......@@ -223,9 +229,8 @@ public class PluginServlet extends HttpServlet {
* @param response the response object.
* @throws IOException if an IOException occurs while handling the request.
*/
private void handleImage(String pathInfo, HttpServletResponse response) throws IOException
{
String [] parts = pathInfo.split("/");
private void handleImage(String pathInfo, HttpServletResponse response) throws IOException {
String[] parts = pathInfo.split("/");
// Image request must be in correct format.
if (parts.length != 4) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
......@@ -258,13 +263,21 @@ public class PluginServlet extends HttpServlet {
// Use a 1K buffer.
byte[] buf = new byte[1024];
int len;
while ((len=in.read(buf)) != -1) {
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
}
}
finally {
try { in.close(); } catch (Exception ignored) {}
try { out.close(); } catch (Exception ignored) {}
try {
in.close();
}
catch (Exception ignored) {
}
try {
out.close();
}
catch (Exception ignored) {
}
}
}
}
......
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