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 { ...@@ -99,6 +99,7 @@ public class PluginManager {
plugins.clear(); plugins.clear();
pluginDirs.clear(); pluginDirs.clear();
classloaders.clear(); classloaders.clear();
pluginDevelopment.clear();
} }
/** /**
...@@ -176,11 +177,16 @@ public class PluginManager { ...@@ -176,11 +177,16 @@ public class PluginManager {
} }
} }
PluginClassLoader pluginLoader = new PluginClassLoader(pluginDir); 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"); Element developmentNode = (Element)pluginXML.selectSingleNode("/plugin/development");
PluginDevEnvironment dev = null; PluginDevEnvironment dev = null;
if (developmentNode != null) { if (developmentNode != null) {
Element webRoot = (Element)developmentNode.selectSingleNode("/plugin/development/webRoot"); Element webRoot = (Element)developmentNode.selectSingleNode(
Element classesDir = (Element)developmentNode.selectSingleNode("/plugin/development/classesDir"); "/plugin/development/webRoot");
Element classesDir = (Element)developmentNode.selectSingleNode(
"/plugin/development/classesDir");
dev = new PluginDevEnvironment(); dev = new PluginDevEnvironment();
...@@ -197,6 +203,7 @@ public class PluginManager { ...@@ -197,6 +203,7 @@ public class PluginManager {
pluginLoader.addURL(classes.getAbsoluteFile().toURL()); pluginLoader.addURL(classes.getAbsoluteFile().toURL());
} }
} }
pluginLoader.initialize(); pluginLoader.initialize();
String className = pluginXML.selectSingleNode("/plugin/class").getText(); String className = pluginXML.selectSingleNode("/plugin/class").getText();
...@@ -222,7 +229,6 @@ public class PluginManager { ...@@ -222,7 +229,6 @@ public class PluginManager {
pluginDevelopment.put(plugin, dev); pluginDevelopment.put(plugin, dev);
} }
// If there a <adminconsole> section defined, register it. // If there a <adminconsole> section defined, register it.
Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole"); Element adminElement = (Element)pluginXML.selectSingleNode("/plugin/adminconsole");
if (adminElement != null) { if (adminElement != null) {
......
...@@ -42,15 +42,17 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -42,15 +42,17 @@ import java.util.concurrent.ConcurrentHashMap;
* to plugins. Since plugins can be dynamically loaded and live in a different place * 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 * 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> * 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> * 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 * (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. * the form <tt>/plugins/[pluginName]/images/*.png|gif</tt> (e.g.
* <tt>/plugins/foo/images/example.gif</tt>).<p> * <tt>/plugins/foo/images/example.gif</tt>).<p>
* <p/> *
* JSP files must be compiled and available via the plugin's class loader. The mapping * 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. * 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. * 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 * @author Matt Tucker
*/ */
...@@ -72,7 +74,8 @@ public class PluginServlet extends HttpServlet { ...@@ -72,7 +74,8 @@ public class PluginServlet extends HttpServlet {
} }
public void service(HttpServletRequest request, HttpServletResponse response) public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException
{
String pathInfo = request.getPathInfo(); String pathInfo = request.getPathInfo();
if (pathInfo == null) { if (pathInfo == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_NOT_FOUND);
...@@ -82,7 +85,7 @@ public class PluginServlet extends HttpServlet { ...@@ -82,7 +85,7 @@ public class PluginServlet extends HttpServlet {
try { try {
// Handle JSP requests. // Handle JSP requests.
if (pathInfo.endsWith(".jsp")) { if (pathInfo.endsWith(".jsp")) {
if (handleJspDocument(pathInfo, request, response)) { if (handleDevJSP(pathInfo, request, response)) {
return; return;
} }
handleJSP(pathInfo, request, response); handleJSP(pathInfo, request, response);
...@@ -214,12 +217,12 @@ public class PluginServlet extends HttpServlet { ...@@ -214,12 +217,12 @@ public class PluginServlet extends HttpServlet {
* @param pathInfo the extra path info. * @param pathInfo the extra path info.
* @param request the request object. * @param request the request object.
* @param response the response object. * @param response the response object.
* @throws ServletException if a servlet exception occurs while handling the * @throws ServletException if a servlet exception occurs while handling the request.
* request.
* @throws IOException if an IOException occurs while handling the request. * @throws IOException if an IOException occurs while handling the request.
*/ */
private void handleJSP(String pathInfo, HttpServletRequest 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. // Strip the starting "/" from the path to find the JSP URL.
String jspURL = pathInfo.substring(1); String jspURL = pathInfo.substring(1);
...@@ -346,18 +349,19 @@ public class PluginServlet extends HttpServlet { ...@@ -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 * Handles a request for a JSP page in development mode. If development mode is
* the current plugin. If one is found, request handling is passed to it. If no * not enabled, this method returns false so that normal JSP handling can be performed.
* jsp page is found, we return false to allow for other handlers. * 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 pathInfo the extra path info.
* @param request the request object. * @param request the request object.
* @param response the response 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, private boolean handleDevJSP(String pathInfo, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response)
{
String jspURL = pathInfo.substring(1); String jspURL = pathInfo.substring(1);
// Handle pre-existing pages and fail over to pre-compiled pages. // Handle pre-existing pages and fail over to pre-compiled pages.
...@@ -367,6 +371,10 @@ public class PluginServlet extends HttpServlet { ...@@ -367,6 +371,10 @@ public class PluginServlet extends HttpServlet {
Plugin plugin = pluginManager.getPlugin(pluginName); Plugin plugin = pluginManager.getPlugin(pluginName);
PluginDevEnvironment environment = pluginManager.getDevEnvironment(plugin); PluginDevEnvironment environment = pluginManager.getDevEnvironment(plugin);
// If development mode not turned on for plugin, return false.
if (environment == null) {
return false;
}
File webDir = environment.getWebRoot(); File webDir = environment.getWebRoot();
if (webDir == null || !webDir.exists()) { if (webDir == null || !webDir.exists()) {
return false; return false;
...@@ -401,7 +409,7 @@ public class PluginServlet extends HttpServlet { ...@@ -401,7 +409,7 @@ public class PluginServlet extends HttpServlet {
jspc.setJspFiles(jspFile.getCanonicalPath()); jspc.setJspFiles(jspFile.getCanonicalPath());
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); Log.error(e);
} }
jspc.setOutputDir(compilationDir.getAbsolutePath()); jspc.setOutputDir(compilationDir.getAbsolutePath());
jspc.setClassName(filename); jspc.setClassName(filename);
...@@ -412,21 +420,20 @@ public class PluginServlet extends HttpServlet { ...@@ -412,21 +420,20 @@ public class PluginServlet extends HttpServlet {
jspc.execute(); jspc.execute();
try { 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; HttpServlet servlet = (HttpServlet)servletInstance;
servlet.init(servletConfig); servlet.init(servletConfig);
servlet.service(request, response); servlet.service(request, response);
return true; return true;
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); Log.error(e);
} }
} }
catch (JasperException e) { catch (JasperException e) {
System.out.println(e.getLocalizedMessage()); Log.error(e);
e.printStackTrace();
} }
} }
return false; 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