Commit 715026bb authored by Matt Tucker's avatar Matt Tucker Committed by matt

Fixed normal (non dev mode) plugins. Comments and cleanup.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1482 b35dd754-fafc-0310-a699-88a17e54d16e
parent 78e7796d
......@@ -99,6 +99,7 @@ public class PluginManager {
plugins.clear();
pluginDirs.clear();
classloaders.clear();
pluginDevelopment.clear();
}
/**
......@@ -176,11 +177,16 @@ public class PluginManager {
}
}
PluginClassLoader pluginLoader = new PluginClassLoader(pluginDir);
// Check to see if development mode is turned on for the plugin. If it is,
// configure dev mode.
Element developmentNode = (Element)pluginXML.selectSingleNode("/plugin/development");
PluginDevEnvironment dev = null;
if (developmentNode != null) {
Element webRoot = (Element)developmentNode.selectSingleNode("/plugin/development/webRoot");
Element classesDir = (Element)developmentNode.selectSingleNode("/plugin/development/classesDir");
Element webRoot = (Element)developmentNode.selectSingleNode(
"/plugin/development/webRoot");
Element classesDir = (Element)developmentNode.selectSingleNode(
"/plugin/development/classesDir");
dev = new PluginDevEnvironment();
......@@ -197,6 +203,7 @@ public class PluginManager {
pluginLoader.addURL(classes.getAbsoluteFile().toURL());
}
}
pluginLoader.initialize();
String className = pluginXML.selectSingleNode("/plugin/class").getText();
......@@ -222,7 +229,6 @@ public class PluginManager {
pluginDevelopment.put(plugin, dev);
}
// If there a <adminconsole> section defined, register it.
Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole");
if (adminElement != null) {
......
......@@ -42,15 +42,17 @@ 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.
* Alternatively, if development mode is enabled for the plugin then the the JSP file
* will be dynamically compiled using JSPC.
*
* @author Matt Tucker
*/
......@@ -72,7 +74,8 @@ public class PluginServlet extends HttpServlet {
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws ServletException, IOException
{
String pathInfo = request.getPathInfo();
if (pathInfo == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
......@@ -82,7 +85,7 @@ public class PluginServlet extends HttpServlet {
try {
// Handle JSP requests.
if (pathInfo.endsWith(".jsp")) {
if (handleJspDocument(pathInfo, request, response)) {
if (handleDevJSP(pathInfo, request, response)) {
return;
}
handleJSP(pathInfo, request, response);
......@@ -212,14 +215,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.
* @throws ServletException if a servlet exception occurs while handling the 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);
......@@ -346,18 +349,19 @@ public class PluginServlet extends HttpServlet {
}
/**
* Handles a request for a JSP page. It checks to see if the jsp page exists in
* the current plugin. If one is found, request handling is passed to it. If no
* jsp page is found, we return false to allow for other handlers.
* Handles a request for a JSP page in development mode. If development mode is
* not enabled, this method returns false so that normal JSP handling can be performed.
* If development mode is enabled, this method tries to locate the JSP, compile
* it using JSPC, and then return the output.
*
* @param pathInfo the extra path info.
* @param request the request object.
* @param response the response object.
* @return true if this page was handled successfully.
* @return true if this page request was handled; false if the request was not handled.
*/
private boolean handleJspDocument(String pathInfo, HttpServletRequest request,
HttpServletResponse response) {
private boolean handleDevJSP(String pathInfo, HttpServletRequest request,
HttpServletResponse response)
{
String jspURL = pathInfo.substring(1);
// Handle pre-existing pages and fail over to pre-compiled pages.
......@@ -367,6 +371,10 @@ public class PluginServlet extends HttpServlet {
Plugin plugin = pluginManager.getPlugin(pluginName);
PluginDevEnvironment environment = pluginManager.getDevEnvironment(plugin);
// If development mode not turned on for plugin, return false.
if (environment == null) {
return false;
}
File webDir = environment.getWebRoot();
if (webDir == null || !webDir.exists()) {
return false;
......@@ -401,7 +409,7 @@ public class PluginServlet extends HttpServlet {
jspc.setJspFiles(jspFile.getCanonicalPath());
}
catch (IOException e) {
e.printStackTrace();
Log.error(e);
}
jspc.setOutputDir(compilationDir.getAbsolutePath());
jspc.setClassName(filename);
......@@ -412,21 +420,20 @@ public class PluginServlet extends HttpServlet {
jspc.execute();
try {
Object servletInstance = pluginManager.loadClass("org.apache.jsp." + relativeDir + filename, plugin).newInstance();
Object servletInstance = pluginManager.loadClass("org.apache.jsp." +
relativeDir + filename, plugin).newInstance();
HttpServlet servlet = (HttpServlet)servletInstance;
servlet.init(servletConfig);
servlet.service(request, response);
return true;
}
catch (Exception e) {
e.printStackTrace();
Log.error(e);
}
}
catch (JasperException e) {
System.out.println(e.getLocalizedMessage());
e.printStackTrace();
Log.error(e);
}
}
return false;
......
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