001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/BTServlet.java
005: Author: Manik Surtani <manik@espadanet.com>
006: Description: The parent servlet class
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: BTServlet.java,v 1.3 2001/04/16 06:45:47 manik Exp $
010: ====================================================================
011:
012: ====================================================================
013: Copyright (C) 2001, Silk Road (Pvt.) Ltd.
014: ====================================================================
015: */
016:
017: package com.espada.bugtracker.servlets;
018:
019: import com.sr.espada.se.util.config.*;
020: import com.sr.espada.se.util.logwriter.*;
021:
022: // webmacro resources
023: import org.webmacro.*;
024: import org.webmacro.broker.*;
025: import org.webmacro.resource.*;
026: import org.webmacro.servlet.WebContext;
027:
028: // servlet libraries
029: import javax.servlet.http.*;
030: import javax.servlet.*;
031:
032: // bugtracker java apps
033: import com.espada.bugtracker.app.*;
034:
035: public abstract class BTServlet extends HttpServlet {
036: String defaultTemplate = "errorMesg.wm";
037:
038: protected String getInitialTemplate() {
039: return ("errorMesg.wm");
040: }
041:
042: /**
043: * This is the core WebMacro interface which we use to create Contexts,
044: * load Templates, and begin other WebMacro operations.
045: */
046: /** the WebMacro Object **/
047: protected static WebMacro _wm = null;
048:
049: public void init() {
050: defaultTemplate = getInitialTemplate();
051: // prepares a webmacro instance, which stays persistent.
052: try {
053: if (_wm == null) {
054: _wm = new WM(getServletContext().getRealPath(
055: getServletContext().getInitParameter(
056: "wmpropfile")));
057: }
058: } catch (InitException e) {
059: LogWriter.write("ERR>> Problem creating wm object");
060: }
061:
062: } //end of method
063:
064: /**
065: * It's not strictly necessary to destroy the WebMacro object when
066: * you're done with it--garbage collection will eventually get it--but
067: * it makes sure the resources get freed. You really ought to do this,
068: * since it might be a lot of resources.
069: */
070: public void destroy() {
071:
072: if (_wm != null) {
073: _wm.destroy();
074: _wm = null;
075: }
076: } //end of method
077:
078: /**
079: */
080: public void doPost(HttpServletRequest req, HttpServletResponse resp) {
081: doGet(req, resp);
082: } //end of method
083:
084: /**
085: */
086: public void doGet(HttpServletRequest req, HttpServletResponse resp) {
087:
088: try {
089: try {
090:
091: // create a context for the current request
092: WebContext c = _wm.getWebContext(req, resp);
093:
094: /******************************************************************/
095:
096: String s = "http://" + req.getServerName();
097: c.put("serverName", s);
098: HttpSession session = req.getSession();
099: doAction(req, resp, c);
100: c.put("loggedIn", (String) session
101: .getAttribute("loggedIn"));
102:
103: /*****************************************************************/
104:
105: // get the template we intend to execute
106: Template t = _wm.getTemplate(defaultTemplate);
107:
108: // Create FastWriter for fast output encoding
109: FastWriter fw = new FastWriter(resp.getOutputStream(),
110: resp.getCharacterEncoding());
111:
112: // write the template to the output, using our context
113: t.write(fw, c);
114: fw.close();
115:
116: } catch (org.webmacro.NotFoundException e) {
117:
118: FastWriter out = new FastWriter(resp.getOutputStream(),
119: resp.getCharacterEncoding());
120:
121: out
122: .write("ERROR! Could not locate template "
123: + defaultTemplate
124: + ", check that your template path is set properly in WebMacro.properties");
125:
126: out.close();
127:
128: }
129:
130: catch (org.webmacro.ContextException e) {
131:
132: FastWriter out = new FastWriter(resp.getOutputStream(),
133: resp.getCharacterEncoding());
134:
135: out
136: .write("ERROR! Could not locate required data in the Context.");
137:
138: out.close();
139:
140: }
141:
142: } catch (java.io.IOException e) {
143:
144: // what else can we do?
145: System.out
146: .println("ERROR: IOException while writing to servlet output stream.");
147:
148: }
149:
150: } //end of method
151:
152: protected void doAction(HttpServletRequest request,
153: HttpServletResponse response, WebContext c) {
154: };
155: } //end of class
|