1 package org.jfox.ioc.management.http; 2 3 import java.io.FileNotFoundException ; 4 import java.io.IOException ; 5 import java.util.Properties ; 6 import javax.servlet.ServletConfig ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 10 import org.apache.velocity.Template; 11 import org.apache.velocity.app.Velocity; 12 import org.apache.velocity.context.Context; 13 import org.apache.velocity.servlet.VelocityServlet; 14 import org.jfox.ioc.Registry; 15 16 19 20 public abstract class SuperServlet extends VelocityServlet { 21 22 31 protected Properties loadConfiguration(ServletConfig config) 32 throws IOException , FileNotFoundException { 33 Properties p = new Properties (); 34 35 42 43 String path = config.getServletContext().getRealPath("/"); 44 45 if(path == null) { 46 path = ""; 47 } 48 49 path += "/WEB-INF/template"; 51 p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path); 52 53 56 57 p.setProperty("runtime.log", path + "velocity.log"); 58 59 return p; 60 } 61 62 63 75 public Template handleRequest(HttpServletRequest request, 76 HttpServletResponse response, 77 Context ctx) throws Exception { 78 79 String template = getTemplate(); 80 81 Template outty = getTemplate(template); 82 buildContext(request,ctx); 83 84 return outty; 85 } 86 87 public abstract String getTemplate(); 88 89 public abstract void buildContext(HttpServletRequest request, Context ctx) throws Exception ; 90 91 protected Registry getRegistry(){ 92 return Registry.getInstance(); 93 } 94 } 95 96 | Popular Tags |