1 64 65 package com.jcorporate.expresso.core.servlet; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.jsdkapi.GenericSession; 69 import com.jcorporate.expresso.core.logging.LogException; 70 import com.jcorporate.expresso.core.misc.ConfigManager; 71 import com.jcorporate.expresso.core.misc.StringUtil; 72 import com.jcorporate.expresso.services.html.HtmlException; 73 import org.apache.log4j.Logger; 74 75 import javax.servlet.ServletConfig ; 76 import javax.servlet.ServletException ; 77 import javax.servlet.http.HttpServletRequest ; 78 import javax.servlet.http.HttpServletResponse ; 79 import java.io.IOException ; 80 81 82 89 public abstract class DBServlet 90 extends StdServlet { 91 protected static final String thisClass = DBServlet.class.getName(); 92 private boolean skipLogin = false; 93 private static Logger log = null; 94 95 100 public void init(ServletConfig sc) 101 throws ServletException { 102 super.init(sc); 103 setupLog(); 104 } 105 106 107 110 public void destroy() { 111 super.destroy(); 112 } 113 114 117 private static void setupLog() { 118 if (log == null) { 119 log = Logger.getLogger(DBServlet.class); 120 } 121 } 122 123 133 public void doGet(HttpServletRequest request, HttpServletResponse response) 134 throws ServletException , IOException { 135 setupChannels(request); 136 137 try { 138 super.doGet(request, response); 139 140 if (!skipLogin) { 141 CheckLogin.getInstance().checkLogin(request); 142 } 143 } catch (Exception se) { 144 showError(se, request, response); 145 } 146 } 147 148 149 157 public void doPost(HttpServletRequest req, HttpServletResponse res) 158 throws ServletException , IOException { 159 ConfigManager.getInstance(); 160 setupChannels(req); 161 162 try { 163 super.doPost(req, res); 164 165 if (!skipLogin) { 166 CheckLogin.getInstance().checkLogin(req); 167 } 168 } catch (Exception de) { 169 showError(de, req, res); 170 } 171 } 172 173 174 180 protected String getDBName(HttpServletRequest request) { 181 String dbName = null; 182 183 try { 184 dbName = GenericSession.getAttributeString(request, "db"); 185 } catch (ServletException se) { 186 log.error(se); 187 dbName = ""; 188 } 189 if (dbName.equals("")) { 190 return "default"; 191 } 192 193 return dbName; 194 } 195 196 211 public boolean requireLogin(HttpServletRequest req, 212 HttpServletResponse res, String nextURL) 213 throws IOException , ServletException , DBException, 214 LogException, HtmlException { 215 return false; 216 } 217 218 219 225 protected void setDBName(String newDBName, HttpServletRequest req) 226 throws ServletException { 227 if (StringUtil.notNull(newDBName).equals("")) { 228 newDBName = "default"; 229 } 230 231 GenericSession.setAttribute(req, "db", newDBName); 232 } 233 234 235 238 public void setSkipLogin(boolean newSkip) { 239 skipLogin = newSkip; 240 } 241 242 247 public void setupChannels(HttpServletRequest req) 248 throws ServletException { 249 log = Logger.getLogger("expresso.core.servlet"); 250 } 251 252 253 } 254 255 | Popular Tags |