1 13 14 package com.espada.bugtracker.servlets; 15 16 import org.webmacro.*; 18 import org.webmacro.broker.*; 19 import org.webmacro.resource.*; 20 import org.webmacro.servlet.WebContext; 21 22 import javax.servlet.http.*; 24 import javax.servlet.*; 25 26 import com.espada.bugtracker.app.*; 28 29 31 import org.apache.log4j.Category; 32 33 34 public abstract class BTServlet extends HttpServlet 35 { 36 37 static Category logger = Category.getInstance(BTServlet.class.getName()); 39 40 String defaultTemplate = "errorMesg.wm"; 41 protected String getInitialTemplate(){ 42 return("errorMesg.wm"); 43 } 44 45 49 50 protected static WebMacro _wm = null; 51 52 public void init() 53 { 54 defaultTemplate=getInitialTemplate(); 55 try 57 { 58 if (_wm == null) 59 { 60 _wm = new WM(getServletContext().getRealPath(getServletContext().getInitParameter("btpropfile"))); 61 } 62 } 63 catch (InitException e) 64 { 65 logger.fatal("Problem creating the static webmacro instance."); 66 } 67 68 } 70 76 public void destroy() 77 { 78 79 if (_wm != null) 80 { 81 _wm.destroy(); 82 _wm = null; 83 } 84 } 86 88 public void doPost(HttpServletRequest req, HttpServletResponse resp){ 89 doGet(req, resp); 90 } 92 94 public void doGet(HttpServletRequest req, HttpServletResponse resp) 95 { 96 97 try 98 { 99 try 100 { 101 102 WebContext c = _wm.getWebContext(req,resp); 104 105 106 107 108 String s = "http://" + req.getServerName(); 109 c.put("serverName", s); 110 HttpSession session = req.getSession(); 111 doAction(req,resp,c); 112 c.put("loggedIn",(String )session.getAttribute("loggedIn")); 113 if (logger.isDebugEnabled()) 114 logger.debug("isLoggedIn = " + session.getAttribute("loggedIn")); 115 116 117 118 119 120 Template t = _wm.getTemplate(defaultTemplate); 122 if (logger.isDebugEnabled()) 123 logger.debug("Created template object from " + defaultTemplate + " and got " + t + " in return."); 124 125 126 127 FastWriter fw = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 129 130 t.write(fw, c); 132 fw.close(); 133 134 } 135 catch (org.webmacro.NotFoundException e) 136 { 137 138 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 139 140 out.write("ERROR! Could not locate template " + defaultTemplate + ", check that your template path is set properly in WebMacro.properties"); 141 logger.error("Could not locate template " + defaultTemplate + ", check that your template path is set properly in WebMacro.properties", e); 142 143 144 out.close(); 145 146 } 147 148 catch (org.webmacro.ContextException e) 149 { 150 151 FastWriter out = new FastWriter(resp.getOutputStream(),resp.getCharacterEncoding()); 152 153 out.write("ERROR! Could not locate required data in the Context."); 154 logger.error("Could not locate required data in the Context.", e); 155 156 out.close(); 157 158 } 159 160 } 161 catch (java.io.IOException e) 162 { 163 164 System.out.println("ERROR: IOException while writing to servlet output stream."); 166 logger.fatal("IOException while writing to servlet output stream.", e); 167 168 169 } 170 171 172 } 174 protected void doAction(HttpServletRequest request, HttpServletResponse response, WebContext c){ 175 }; 176 } | Popular Tags |