KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > jspbeans > ContactCenterUserInfoServlet


1 /*
2  * VerifyFreeLoginServlet.java
3  *
4  * Created on March 7, 2003, 1:08 AM
5  */

6
7 package com.quikj.application.web.talk.jspbeans;
8
9 import java.io.*;
10 import javax.servlet.*;
11 import javax.servlet.http.*;
12
13 /**
14  *
15  * @author amit
16  */

17 public class ContactCenterUserInfoServlet extends HttpServlet
18 {
19     /** Initializes the servlet.
20      */

21     public void init(ServletConfig config) throws ServletException
22     {
23         super.init(config);
24     }
25     
26     /** Destroys the servlet.
27      */

28     public void destroy()
29     {
30     }
31     
32     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
33      * @param request servlet request
34      * @param response servlet response
35      */

36     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
37     throws ServletException, IOException
38     {
39         String JavaDoc customer = request.getParameter("customer");
40         if (customer == null)
41         {
42             request.setAttribute("errorMessage",
43             "talk.servlet.no.customer");
44             goToPage("/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
45             return;
46         }
47                 
48         ContactCenterCustomerList customer_bean = (ContactCenterCustomerList)getServletContext().getAttribute(
49         ContactCenterServlet.CUSTOMER_BEAN);
50         if (customer_bean == null)
51         {
52             request.setAttribute("errorMessage",
53             "talk.servlet.uninitialized");
54             goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
55             return;
56         }
57                 
58         try
59         {
60             // Get the properties for this customer
61
ContactCenterCustomerProperty customer_property =
62             customer_bean.getCustomerProperty(customer);
63             
64             if (customer_property == null)
65             {
66                 // go to an error page
67
request.setAttribute("errorMessage",
68                 "talk.servlet.customer.undefined");
69                 goToPage("/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
70                 return;
71             }
72             
73             // Set the properties in the request scope
74
request.setAttribute("customerProperty", customer_property);
75                                     
76             // Create a new instance of the form bean and populate it
77
ContactCenterUnrestrictedAccessForm form_bean = new ContactCenterUnrestrictedAccessForm();
78             form_bean.populate(request);
79             request.setAttribute("formBean", form_bean);
80             
81             // If any of the required attributes are not specified
82
if(form_bean.isFormError() == true)
83             {
84                 request.setAttribute( "errorMessage", "talk.unrestricted.enter.mandatory");
85                 
86                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("userInfoPage");
87                 if (page == null)
88                 {
89                     page = "/aceapp/jsp/contactcenter/talk_unrestricted_userinfo.jsp";
90                 }
91                 goToPage(page, request, response );
92                 return;
93             }
94             
95             if (customer_property.getClientType().equals("JAVA") == true)
96             {
97                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("chatButtonPage");
98                 if (page == null)
99                 {
100                     page = "/aceapp/jsp/contactcenter/talk_display_applet.jsp";
101                 }
102                 goToPage(page, request, response );
103             }
104             else if (customer_property.getClientType().equals("HTML") == true)
105             {
106                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("chatPage");
107                 if (page == null)
108                 {
109                     page = "/aceapp/jsp/contactcenter/talk_display_chat.jsp";
110                 }
111                 goToPage(page, request, response );
112             }
113             return;
114         }
115         catch (Exception JavaDoc ex)
116         {
117             request.setAttribute ("exceptionMessage",
118             ex.getClass().getName() + ": "
119             + ex.getMessage());
120             goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
121             return;
122         }
123                 
124     }
125     
126     /** Handles the HTTP <code>GET</code> method.
127      * @param request servlet request
128      * @param response servlet response
129      */

130     protected void doGet(HttpServletRequest request, HttpServletResponse response)
131     throws ServletException, IOException
132     {
133         
134         processRequest(request, response);
135         
136     }
137     
138     /** Handles the HTTP <code>POST</code> method.
139      * @param request servlet request
140      * @param response servlet response
141      */

142     protected void doPost(HttpServletRequest request, HttpServletResponse response)
143     throws ServletException, IOException
144     {
145         
146         processRequest(request, response);
147         
148     }
149     
150     /** Returns a short description of the servlet.
151      *
152      */

153     public String JavaDoc getServletInfo()
154     {
155         return servletDescription;
156     }
157     
158     /** Handles the forwarding process
159      * @param String address - URL of the request
160      * @param request servlet request
161      * @param response servlet response
162      */

163     private void goToPage( String JavaDoc address,
164     HttpServletRequest request,
165     HttpServletResponse response )
166     throws ServletException, IOException
167     {
168         
169         RequestDispatcher dispatcher =
170         getServletContext().getRequestDispatcher( address );
171         dispatcher.forward( request, response );
172         
173     }
174     
175     /**
176      * Private members
177      *
178      */

179     private String JavaDoc servletDescription =
180     "This servlet verifies if the "
181     + "customer entered in the required input and accrodingly "
182     + "either forwards the customer to the applet/chat page or back to the JSP";
183     
184 }
185
Popular Tags