01: /*
02: * Enhydra Java Application Server Project
03: *
04:
05: *
06: * Contributor(s):
07: *
08: * $Id: Welcome.java,v 1.1 2006-09-11 12:52:43 sinisa Exp $
09: */
10:
11: package com.lutris.appserver.welcome.presentation;
12:
13: //dr2806 import com.lutris.xml.xmlc.*;
14: //dr2806 import com.lutris.xml.xmlc.html.*;
15: import com.lutris.appserver.server.httpPresentation.*;
16: import com.lutris.appserver.server.session.*;
17: import com.lutris.util.*;
18: import java.io.*;
19: import org.w3c.dom.*;
20: import org.w3c.dom.html.*;
21:
22: /**
23: * Output the welcome page.
24: */
25: public class Welcome implements HttpPresentation {
26: /*
27: * Used to keep track of the total number of times this page has been
28: * served.
29: */
30: private static int counter = 0;
31:
32: /*
33: * Set counters in the page.
34: */
35: public void setCounters(Session session, WelcomeHTML htmlObj)
36: throws KeywordValueException {
37: /*
38: * Fill the tag that holds the total number of times this page has
39: * been served, to all users. We use a static variable to hold this
40: * information.
41: */
42: counter++;
43: htmlObj.setTextTotalHits(Integer.toString(counter));
44:
45: /*
46: * Fill in the tag that holds the number of times this user
47: * has been served this page. Since this is a per-user thing,
48: * we use session data. The first time a user loads this page,
49: * the session data will not contain the counter, treat this
50: * as if the counter was zero.
51: */
52: SessionData sessionData = session.getSessionData();
53: String userCounterString = sessionData.getString("counter");
54: int userCounter = 0;
55: if (userCounterString != null) {
56: userCounter = Integer.parseInt(userCounterString);
57: }
58: userCounter++;
59: userCounterString = Integer.toString(userCounter);
60: sessionData.set("counter", userCounterString);
61:
62: htmlObj.setTextUserHits(userCounterString);
63: }
64:
65: /**
66: * Entry.
67: */
68: public void run(HttpPresentationComms comms)
69: throws HttpPresentationException {
70: try {
71: WelcomeHTML htmlObj = (WelcomeHTML) comms.xmlcFactory
72: .create(WelcomeHTML.class);
73: setCounters(comms.session, htmlObj);
74: comms.response.writeHTML(htmlObj);
75: } catch (KeywordValueException except) {
76: throw new HttpPresentationException(except);
77: }
78: }
79: }
|