KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * TalkServlet.java
3  *
4  * Created on February 23, 2003, 2:28 PM
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 import com.quikj.client.raccess.*;
13 import com.quikj.server.framework.*;
14
15 /**
16  *
17  * @author Amit
18  * @version
19  */

20 public class ContactCenterServlet extends HttpServlet
21 {
22     
23     public static final String JavaDoc CUSTOMER_BEAN = "customerBean";
24     
25     /** Initializes the servlet.
26      *
27      *
28      */

29     public void init(ServletConfig config) throws ServletException
30     {
31         super.init(config);
32         
33         if (AceLicenseManager.getInstance().licenseFeature("ace-contact-center") == false)
34         {
35             throw new ServletException(AceLicenseManager.getInstance().getErrorMessage());
36         }
37         
38         String JavaDoc app_root = getServletContext().getRealPath("");
39         
40         ContactCenterCustomerList bean = new ContactCenterCustomerList();
41         bean.setPath(app_root);
42         
43         getServletContext().setAttribute(CUSTOMER_BEAN, bean);
44         
45     }
46     
47     /** Destroys the servlet.
48      *
49      *
50      */

51     public void destroy()
52     {
53     }
54     
55     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
56      * @param request servlet request
57      * @param response servlet response
58      */

59     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
60     throws ServletException, IOException
61     {
62         response.setContentType("text/html");
63         
64         String JavaDoc customer = request.getParameter("customer");
65         if (customer == null)
66         {
67             request.setAttribute("errorMessage",
68             "talk.servlet.no.customer");
69             goToPage("/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
70             return;
71         }
72         
73         ContactCenterCustomerList customer_bean = (ContactCenterCustomerList)getServletContext().getAttribute(CUSTOMER_BEAN);
74         if (customer_bean == null)
75         {
76             request.setAttribute("errorMessage",
77             "talk.servlet.uninitialized");
78             goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
79             return;
80         }
81         
82         try
83         {
84             // Get the properties for this customer
85
ContactCenterCustomerProperty customer_property =
86             customer_bean.getCustomerProperty(customer);
87             
88             if (customer_property == null)
89             {
90                 // go to an error page
91
request.setAttribute("errorMessage",
92                 "talk.servlet.customer.undefined");
93                 goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
94                 return;
95             }
96             
97             // Set the properties in the request scope
98
request.setAttribute("customerProperty", customer_property);
99             
100             // Check to see if an operator is online for this call
101
// and display operator oos.jsp if no operator not
102
if (customer_property.isActive() == false)
103             {
104                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("oosPage");
105                 if (page == null)
106                 {
107                     page = "/aceapp/jsp/contactcenter/talk_oos.jsp";
108                 }
109                 
110                 ContactCenterEmailForm form = new ContactCenterEmailForm();
111                 request.setAttribute("formBean", form);
112                 
113                 goToPage(page, request, response);
114                 return;
115             }
116             
117             if (customer_property.isCheckOperatorAvailability() == true)
118             {
119                 if (loggedIn(customer_property.getOperator()) == false)
120                 {
121                     String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("oosPage");
122                     if (page == null)
123                     {
124                         page = "/aceapp/jsp/contactcenter/talk_oos.jsp";
125                     }
126                     
127                     ContactCenterEmailForm form = new ContactCenterEmailForm();
128                     request.setAttribute("formBean", form);
129                     goToPage(page, request, response);
130                     return;
131                 }
132                 else if (allOperatorsBusy(customer_property.getOperator()) == true)
133                 {
134                     String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("aobPage");
135                     if (page == null)
136                     {
137                         page = (String JavaDoc)customer_property.getPagesParams().get("oosPage");
138                         if (page == null)
139                         {
140                             page = "/aceapp/jsp/contactcenter/talk_oos.jsp";
141                         }
142                     }
143                     
144                     ContactCenterEmailForm form = new ContactCenterEmailForm();
145                     request.setAttribute("formBean", form);
146                     goToPage(page, request, response);
147                     return;
148                 }
149             }
150             
151             // If an operator is online:
152
if( customer_property.getAccessType().equals("unrestricted") == true)
153             {
154                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("userInfoPage");
155                 if (page == null)
156                 {
157                     page = "/aceapp/jsp/contactcenter/talk_unrestricted_userinfo.jsp";
158                 }
159                 
160                 // create an empty form and save it to the request scope
161
ContactCenterUnrestrictedAccessForm form = new ContactCenterUnrestrictedAccessForm();
162                 request.setAttribute("formBean", form);
163                 
164                 goToPage(page,
165                 request, response);
166                 return;
167                 
168             }
169             else if( customer_property.getAccessType().equals("restricted") == true)
170             {
171                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("userLoginPage");
172                 if (page == null)
173                 {
174                     page = "/aceapp/jsp/contactcenter/talk_restricted_login.jsp";
175                 }
176                 
177                 // create an empty form and save it to the request scope
178
ContactCenterRestrictedAccessForm form = new ContactCenterRestrictedAccessForm();
179                 request.setAttribute("formBean", form);
180                 
181                 goToPage(page, request, response );
182                 return;
183             }
184             
185         }
186         catch (Exception JavaDoc ex)
187         {
188             request.setAttribute("exceptionMessage",
189             ex.getClass().getName() + ": "
190             + ex.getMessage());
191             goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
192             return;
193             
194         }
195         
196     }
197     
198     /** Handles the HTTP <code>GET</code> method.
199      * @param request servlet request
200      * @param response servlet response
201      */

202     protected void doGet(HttpServletRequest request, HttpServletResponse response)
203     throws ServletException, IOException
204     {
205         
206         processRequest(request, response);
207         
208     }
209     
210     /** Handles the HTTP <code>POST</code> method.
211      * @param request servlet request
212      * @param response servlet response
213      */

214     protected void doPost(HttpServletRequest request, HttpServletResponse response)
215     throws ServletException, IOException
216     {
217         processRequest(request, response);
218     }
219     
220     /** Returns a short description of the servlet.
221      */

222     public String JavaDoc getServletInfo()
223     {
224         return "This servlet determines if restricted or unrestricted access is required"
225         + " and forwards to the appropriate jsp.";
226     }
227     
228     /** Handles the forwarding process
229      * @param address URL of the request
230      * @param request servlet request
231      * @param response servlet response
232      */

233     private void goToPage( String JavaDoc address,
234     HttpServletRequest request,
235     HttpServletResponse response )
236     throws ServletException, IOException
237     {
238         RequestDispatcher dispatcher =
239         getServletContext().getRequestDispatcher(address);
240         dispatcher.forward(request, response);
241     }
242     
243     private boolean loggedIn(String JavaDoc user)
244     {
245         RemoteAccessClient cl = (RemoteAccessClient)getServletContext().getAttribute("remoteAccess");
246         if (cl == null)
247         {
248             return false;
249         }
250         
251         try
252         {
253             String JavaDoc val = cl.getRemoteAccess().getParam("com.quikj.application.web.talk.feature.operator.Operator:"
254             + user,
255             "operator-queue-size");
256             if (val == null)
257             {
258                 return false;
259             }
260             else
261             {
262                 try
263                 {
264                     int count = Integer.parseInt(val);
265                     if (count > 0)
266                     {
267                         return true;
268                     }
269                     
270                     return false;
271                 }
272                 catch (NumberFormatException JavaDoc ex)
273                 {
274                     return false;
275                 }
276             }
277         }
278         catch (Exception JavaDoc ex)
279         {
280             return false;
281         }
282     }
283     
284     private boolean allOperatorsBusy(String JavaDoc user)
285     {
286         RemoteAccessClient cl = (RemoteAccessClient)getServletContext().getAttribute("remoteAccess");
287         if (cl == null)
288         {
289             return true;
290         }
291         
292         try
293         {
294             String JavaDoc val = cl.getRemoteAccess().getParam("com.quikj.application.web.talk.feature.operator.Operator:"
295             + user,
296             "all-operators-busy");
297             if (val == null)
298             {
299                 return true;
300             }
301             else
302             {
303                 if (val.equals("false") == true)
304                 {
305                     return false;
306                 }
307                 else
308                 {
309                     return true;
310                 }
311             }
312         }
313         catch (Exception JavaDoc ex)
314         {
315             return true;
316         }
317     }
318     
319 }
320
Popular Tags