KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > welcome > presentation > Welcome


1 /*
2  * Enhydra Java Application Server Project
3  *
4  
5  *
6  * Contributor(s):
7  *
8  * $Id: Welcome.java,v 1.1 2004/08/16 10:50:22 slobodan Exp $
9  */

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,
36                             WelcomeHTML htmlObj)
37         throws KeywordValueException {
38         /*
39          * Fill the tag that holds the total number of times this page has
40          * been served, to all users. We use a static variable to hold this
41          * information.
42          */

43         counter++;
44         htmlObj.setTextTotalHits(Integer.toString(counter));
45
46         /*
47          * Fill in the tag that holds the number of times this user
48          * has been served this page. Since this is a per-user thing,
49          * we use session data. The first time a user loads this page,
50          * the session data will not contain the counter, treat this
51          * as if the counter was zero.
52          */

53         SessionData sessionData = session.getSessionData();
54         String JavaDoc userCounterString = sessionData.getString("counter");
55         int userCounter = 0;
56         if (userCounterString != null) {
57             userCounter = Integer.parseInt(userCounterString);
58         }
59         userCounter++;
60         userCounterString = Integer.toString(userCounter);
61         sessionData.set("counter", userCounterString);
62
63         htmlObj.setTextUserHits(userCounterString);
64     }
65
66     /**
67      * Entry.
68      */

69     public void run(HttpPresentationComms comms)
70         throws HttpPresentationException {
71         try {
72             WelcomeHTML htmlObj
73                 = (WelcomeHTML)comms.xmlcFactory.create(WelcomeHTML.class);
74             setCounters(comms.session, htmlObj);
75             comms.response.writeHTML(htmlObj);
76         } catch (KeywordValueException except) {
77             throw new HttpPresentationException(except);
78         }
79     }
80 }
81
Popular Tags