KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > examples > ex4 > SampleViewHandler


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: SampleViewHandler.java,v 1.11 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.examples.ex4;
21
22 import java.io.*;
23 import java.util.*;
24 import java.net.*;
25 import javax.servlet.*;
26 import javax.servlet.http.*;
27
28 import org.enhydra.barracuda.core.event.*;
29 import org.enhydra.barracuda.examples.ex4.events.*;
30
31
32 /**
33  * A sample view event handler
34  */

35 public class SampleViewHandler extends DefaultListenerFactory {
36
37     public static final String JavaDoc HANDLED_BY = "HandledBy";
38
39     //define the necessary factory methods
40
public BaseEventListener getInstance() {
41         return new RenderHandler();
42     }
43     public String JavaDoc getListenerID() {
44         return getID(RenderHandler.class);
45     }
46
47     //------------------------------------------------------------
48
// Model 2 - View Event Handlers
49
//------------------------------------------------------------
50
/**
51      * RenderHandler - handle the request to render the test
52      * screen
53      */

54     class RenderHandler extends DefaultBaseEventListener {
55         public void handleViewEvent(ViewEventContext context) throws EventException, ServletException, IOException {
56             //unpack the necessary entities from the context
57
BaseEvent event = context.getEvent();
58             HttpServletResponse resp = context.getResponse();
59
60             //csc_061202.1 - added
61
//set the caching hdrs (allow this page to be cached by browser)
62
resp.setHeader("Cache-Control","max-age=0");
63             resp.setDateHeader("Last-Modified", System.currentTimeMillis());
64
65             //build the response
66
resp.setContentType("text/html");
67             PrintWriter out = resp.getWriter();
68             
69             //header
70
String JavaDoc title = "Simple Deployment Descriptor Test Screen";
71             out.println ("<html>");
72             out.println (" <head>");
73             out.println (" <title>"+title+"</title>");
74             out.println (" </head>");
75             out.println (" <body>");
76             out.println (" <font face=\"Arial\">");
77
78             //body
79
out.println (" <p>"+title);
80             out.println (" <p>Handled by:"+context.getState(HANDLED_BY));
81             
82             //footer
83
out.println (" </font>");
84             out.println (" </body>");
85             out.println ("</html>");
86         }
87     }
88 }
89
90
Popular Tags