001: /*
002: ====================================================================
003: Project Name: bugtracker
004: File Name: /src/com/espada/bugtracker/servlets/StartPage.java
005: Author: Kishan Peiris <kishan@espadanet.com>
006: Description: The Initial page for bugtracker
007: CVS Repository: goliath:/projects/repository/cvsroot/
008: CVS Module: bugtracker
009: Version: CVS $Id: $
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 class StartPage extends BTServlet {
036:
037: /**
038: * This is the core WebMacro interface which we use to create Contexts,
039: * load Templates, and begin other WebMacro operations.
040: */
041:
042: /** the default template to use **/
043: private static final String defaultTemplate = "index.wm";
044:
045: private void initConfiguration() {
046:
047: //******************************************************************************/
048: //********** INITIALIZATION *************************/
049: //
050: // Let us initialize the configuration.
051: // This would only have to be done *once* every time the server is started!!
052: // -----------------------------------------------------------------------------
053:
054: if (ConfigFactory.isInitialized()) {
055: // the config is already initialized. What me worry?
056: // out.println("Initialized to " + ConfigFactory.getFile() );
057: } else {
058: // let us initialize it.
059: try {
060:
061: String cFile = getServletContext().getRealPath(
062: getServletContext()
063: .getInitParameter("propfile"));
064:
065: ConfigFactory.setFile(cFile);
066:
067: } catch (ConfigFileMissingException e) {
068:
069: System.out.println("Ouch!");
070:
071: }
072:
073: }
074:
075: } //end of method
076:
077: /**
078: */
079: public void doGet(HttpServletRequest req, HttpServletResponse resp) {
080: // initialize WebMacro.
081: initConfiguration();
082:
083: try {
084: try {
085:
086: // create a context for the current request
087: WebContext c = _wm.getWebContext(req, resp);
088:
089: /******************************************************************/
090:
091: HttpSession session = req.getSession();
092: session.invalidate(); //discard the old values..
093:
094: session = req.getSession(true); //create a new session..
095: boolean loggedIn = false;
096: String s = "http://" + req.getServerName();
097:
098: session.setAttribute("loggedIn", String
099: .valueOf(loggedIn));
100: c.put("serverName", s);
101: c.put("loggedIn", String.valueOf(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: } catch (org.webmacro.ContextException e) {
129:
130: FastWriter out = new FastWriter(resp.getOutputStream(),
131: resp.getCharacterEncoding());
132:
133: out
134: .write("ERROR! Could not locate required data in the Context.");
135:
136: out.close();
137: }
138: } catch (java.io.IOException e) {
139:
140: // what else can we do?
141: System.out
142: .println("ERROR: IOException while writing to servlet output stream.");
143:
144: }
145:
146: } //end of method
147:
148: } //end of class
|