1 43 package net.jforum; 44 45 import java.io.BufferedWriter ; 46 import java.io.IOException ; 47 import java.io.OutputStreamWriter ; 48 49 import javax.servlet.ServletConfig ; 50 import javax.servlet.ServletException ; 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 54 import net.jforum.exceptions.ExceptionWriter; 55 import net.jforum.repository.ModulesRepository; 56 import net.jforum.util.I18n; 57 import net.jforum.util.preferences.ConfigKeys; 58 import net.jforum.util.preferences.SystemGlobals; 59 import freemarker.template.SimpleHash; 60 import freemarker.template.Template; 61 62 66 public class InstallServlet extends JForumBaseServlet 67 { 68 71 public void init(ServletConfig config) throws ServletException 72 { 73 super.init(config); 74 } 75 76 79 public void service(HttpServletRequest req, HttpServletResponse response) throws ServletException , IOException 80 { 81 try { 82 String encoding = SystemGlobals.getValue(ConfigKeys.ENCODING); 83 req.setCharacterEncoding(encoding); 84 85 ActionServletRequest request = new ActionServletRequest(req); 87 88 request.setCharacterEncoding(encoding); 89 request.setJForumContext(new JForumContext(request.getContextPath(), 90 SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION), 91 request, 92 response, 93 false)); 94 95 JForumExecutionContext ex = JForumExecutionContext.get(); 96 ex.setResponse(response); 97 ex.setRequest(request); 98 99 JForumExecutionContext.set(ex); 101 102 SimpleHash context = JForumExecutionContext.getTemplateContext(); 104 context.put("contextPath", req.getContextPath()); 105 context.put("serverName", req.getServerName()); 106 context.put("templateName", "default"); 107 context.put("serverPort", Integer.toString(req.getServerPort())); 108 context.put("I18n", I18n.getInstance()); 109 context.put("encoding", encoding); 110 context.put("extension", SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION)); 111 112 113 if (SystemGlobals.getBoolValue(ConfigKeys.INSTALLED)) { 114 JForumExecutionContext.setRedirect(request.getContextPath() 115 + "/forums/list.page"); 116 } 117 else { 118 String moduleClass = ModulesRepository.getModuleClass(request.getModule()); 120 121 context.put("moduleName", request.getModule()); 122 context.put("action", request.getAction()); 123 124 BufferedWriter out = new BufferedWriter (new OutputStreamWriter (response.getOutputStream(), encoding)); 125 126 try { 127 if (moduleClass != null) { 128 Command c = (Command)Class.forName(moduleClass).newInstance(); 130 Template template = c.process(request, response, context); 131 132 if (JForumExecutionContext.getRedirectTo() == null) { 133 response.setContentType("text/html; charset=" + encoding); 134 135 template.process(context, out); 136 out.flush(); 137 } 138 } 139 } 140 catch (Exception e) { 141 response.setContentType("text/html; charset=" + encoding); 142 if (out != null) { 143 new ExceptionWriter().handleExceptionData(e, out); 144 } 145 else { 146 new ExceptionWriter().handleExceptionData(e, 147 new BufferedWriter (new OutputStreamWriter (response.getOutputStream()))); 148 } 149 } 150 } 151 152 String redirectTo = JForumExecutionContext.getRedirectTo(); 153 154 if (redirectTo != null) { 155 response.sendRedirect(response.encodeRedirectURL(redirectTo)); 156 } 157 } 158 finally { 159 JForumExecutionContext.finish(); 160 } 161 } 162 } 163 | Popular Tags |