Commit 8dd8a477 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

1) Added JSP Compilation


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1458 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2eb3e8f6
...@@ -82,6 +82,9 @@ public class PluginServlet extends HttpServlet { ...@@ -82,6 +82,9 @@ 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)){
return;
}
handleJSP(pathInfo , request , response); handleJSP(pathInfo , request , response);
return; return;
} }
...@@ -350,6 +353,7 @@ public class PluginServlet extends HttpServlet { ...@@ -350,6 +353,7 @@ 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.
* @return true if this page was handled successfully.
*/ */
private boolean handleJspDocument(String pathInfo , HttpServletRequest request , private boolean handleJspDocument(String pathInfo , HttpServletRequest request ,
HttpServletResponse response) { HttpServletResponse response) {
...@@ -363,16 +367,23 @@ public class PluginServlet extends HttpServlet { ...@@ -363,16 +367,23 @@ public class PluginServlet extends HttpServlet {
Plugin plugin = pluginManager.getPlugin(pluginName); Plugin plugin = pluginManager.getPlugin(pluginName);
File pluginDirectory = pluginManager.getPluginDirectory(plugin); File pluginDirectory = pluginManager.getPluginDirectory(plugin);
File compiledServletsDirectory = new File(pluginDirectory , "classes"); File compilationDir = new File(pluginDirectory , "classes");
compiledServletsDirectory.mkdirs(); compilationDir.mkdirs();
String jsp = jspURL.substring(fileSeperator + 1); String jsp = jspURL.substring(fileSeperator + 1);
int indexOfLastSlash = jsp.lastIndexOf("/");
String relativeDir = "";
if(indexOfLastSlash != -1){
relativeDir = jsp.substring(0, indexOfLastSlash);
relativeDir = relativeDir.replaceAll("//", ".") + '.';
}
File jspFile = new File(pluginDirectory + "/web" , jsp); File jspFile = new File(pluginDirectory + "/web" , jsp);
String filename = jspFile.getName(); String filename = jspFile.getName();
int indexOfPeriod = filename.indexOf("."); int indexOfPeriod = filename.indexOf(".");
if (indexOfPeriod != -1) { if (indexOfPeriod != -1) {
filename = StringUtils.randomString(10); filename = "dev"+StringUtils.randomString(4);
} }
JspC jspc = new JspC(); JspC jspc = new JspC();
...@@ -380,7 +391,7 @@ public class PluginServlet extends HttpServlet { ...@@ -380,7 +391,7 @@ public class PluginServlet extends HttpServlet {
return false; return false;
} }
jspc.setJspFiles(jspFile.getAbsolutePath()); jspc.setJspFiles(jspFile.getAbsolutePath());
jspc.setOutputDir(compiledServletsDirectory.getAbsolutePath()); jspc.setOutputDir(compilationDir.getAbsolutePath());
jspc.setClassName(filename); jspc.setClassName(filename);
jspc.setCompile(true); jspc.setCompile(true);
...@@ -389,7 +400,7 @@ public class PluginServlet extends HttpServlet { ...@@ -389,7 +400,7 @@ public class PluginServlet extends HttpServlet {
jspc.execute(); jspc.execute();
try { try {
Object servletInstance = pluginManager.loadClass("org.apache.jsp." + 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);
...@@ -401,6 +412,8 @@ public class PluginServlet extends HttpServlet { ...@@ -401,6 +412,8 @@ public class PluginServlet extends HttpServlet {
} }
catch (JasperException e) { catch (JasperException e) {
System.out.println(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -413,7 +426,7 @@ public class PluginServlet extends HttpServlet { ...@@ -413,7 +426,7 @@ public class PluginServlet extends HttpServlet {
* @param plugin the plugin the jspc will handle. * @param plugin the plugin the jspc will handle.
* @return the classpath needed to compile a single jsp in a plugin. * @return the classpath needed to compile a single jsp in a plugin.
*/ */
private String getClasspathForPlugin(Plugin plugin) { private static String getClasspathForPlugin(Plugin plugin) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
File pluginDirectory = pluginManager.getPluginDirectory(plugin); File pluginDirectory = pluginManager.getPluginDirectory(plugin);
...@@ -423,7 +436,7 @@ public class PluginServlet extends HttpServlet { ...@@ -423,7 +436,7 @@ public class PluginServlet extends HttpServlet {
File[] libs = libDirectory.listFiles(); File[] libs = libDirectory.listFiles();
for (int i = 0;i < libs.length;i++) { for (int i = 0;i < libs.length;i++) {
File libFile = libs[i]; File libFile = libs[i];
builder.append(libFile.getAbsolutePath() + ";"); builder.append(libFile.getAbsolutePath() + ';');
} }
File messengerRoot = pluginDirectory.getParentFile().getParentFile().getParentFile(); File messengerRoot = pluginDirectory.getParentFile().getParentFile().getParentFile();
......
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