1 package com.instantbank.lettertemplate.control.web.handlers;
2
3 import java.util.HashMap;
4 import java.util.ArrayList;
5 import java.util.Enumeration;
6 import java.util.Hashtable;
7 import java.util.StringTokenizer;
8
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.ServletContext;
11 import com.instantbank.lettertemplate.control.event.CategoryEvent;
12 import com.instantbank.lettertemplate.control.util.JSPUtil;
13 import com.instantbank.lettertemplate.control.util.WebKeys;
14 import com.instantbank.common.utilcomponents.Debug;
15 import com.instantbank.common.utilcomponents.CommonUtil;
16 import com.instantbank.common.utilcomponents.LetterTemplateGlobals;
17 import com.instantbank.lettertemplate.control.LetterTemplateEventException;
18
19
20
27 public class CategoryFlowHandler
28 implements FlowHandler {
29 private Debug debug = null;
30
31
32
37 public void doStart(HttpServletRequest request) { }
38
39
40
49 public String processFlow(HttpServletRequest request, Object answer,
50 ServletContext context)
51 throws LetterTemplateEventException {
52 debug = new Debug();
53 debug.setDebugginOn(true);
54 debug.setPreMessage("** CategoryFlowHandler: ");
55 debug.println("processFlow");
56
57 String nextScreen = null;
58 CategoryEvent ce = null;
59 Hashtable categoryTable = null;
60 String companyId = (String)request.getSession()
61 .getAttribute(WebKeys.CompanyId);
62
63 if(request.getAttribute(WebKeys.CategoryEvent) != null) {
64 ce = (CategoryEvent)request.getAttribute(WebKeys.CategoryEvent);
65 }
66
67 if(request.getAttribute(WebKeys.ExceptionOcurred) != null) {
68
69
70 CommonUtil.putVariableInRequest(request, context, companyId,
71 WebKeys.CategoryTable, WebKeys.CategoryList);
72 nextScreen = "1";
73
74
75 }
76 else if(request.getAttribute(WebKeys.ExistsCategoryList) != null) {
77
78
79 CommonUtil.putVariableInRequest(request, context, companyId,
80 WebKeys.CategoryTable, WebKeys.CategoryList);
81 nextScreen = "2";
82
83
84 }
85 else if(ce.getActionType() == CategoryEvent.LIST_CATEGORIES) {
86
87
88
89 CommonUtil.putVariableInContext
90 (context, companyId, WebKeys.CategoryTable, answer);
91
92 request.setAttribute(WebKeys.CategoryList, answer);
93 nextScreen = "2";
94
95
96 }
97 else if(ce.getActionType() == CategoryEvent.UPDATE_CATEGORIES) {
98
99
100
101
102
103 CommonUtil.putVariableInContext(context, companyId,
104 WebKeys.CategoryTable, "");
105
106
107 CommonUtil.putVariableInContext(context, companyId,
108 WebKeys.TemplatesTable, "");
109
110
111 CommonUtil.putVariableInContext(context, companyId,
112 WebKeys.CategoryTable, ((ArrayList)answer).get(1));
113
114
115 request.setAttribute
116 (WebKeys.CategoryList, ((ArrayList)answer).get(1));
117
118 String problem = (String)(((ArrayList)answer).get(0));
119 if(problem.equals(LetterTemplateGlobals.STR_UNDEF)) {
120 nextScreen = "2";
121
122 }
123 else {
124
125 JSPUtil.putProblemInRequest(request, problem);
126 nextScreen = "1";
127
128 }
129 }
130 return nextScreen;
131 }
132
133
134
139 public void doEnd(HttpServletRequest request) { }
140 }
141
142