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
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.ServletContext;
14 import javax.servlet.http.HttpSession;
15 import com.instantbank.lettertemplate.control.event.TemplatesEvent;
16 import com.instantbank.lettertemplate.control.util.JSPUtil;
17 import com.instantbank.lettertemplate.control.util.WebKeys;
18 import com.instantbank.common.utilcomponents.Debug;
19 import com.instantbank.common.utilcomponents.CommonUtil;
20 import com.instantbank.common.utilcomponents.LetterTemplateGlobals;
21 import com.instantbank.lettertemplate.control.LetterTemplateEventException;
22
23
30 public class TemplatesFlowHandler
31 implements FlowHandler {
32 private Debug debug = null;
33
34
35
40 public void doStart(HttpServletRequest request) { }
41
42
43
52 public String processFlow(HttpServletRequest request, Object answer,
53 ServletContext context)
54 throws LetterTemplateEventException {
55 debug = new Debug();
56 debug.setDebugginOn(true);
57 debug.setPreMessage("** TemplatesFlowHandler: ");
58 debug.println("processFlow");
59
60 String nextScreen = null;
61 TemplatesEvent ce = null;
62 Hashtable templateTable = null;
63 Hashtable categoryTable = null;
64 HttpSession session = request.getSession();
65 String companyId = (String)request.getSession()
66 .getAttribute(WebKeys.CompanyId);
67
68 if(request.getAttribute(WebKeys.TemplatesEvent) != null) {
69 ce = (TemplatesEvent)request.getAttribute(WebKeys.TemplatesEvent);
70 }
71
72 if(request.getAttribute(WebKeys.ExceptionOcurred) != null) {
73
74
75
76 CommonUtil.putVariableInRequest(request, context, companyId,
77 WebKeys.TemplatesTable, WebKeys.TemplatesList);
78
79 CommonUtil.putVariableInRequest(request, context, companyId,
80 WebKeys.CategoryTable, WebKeys.CategoryList);
81
82 Object pendingProblem = session.getAttribute(WebKeys.PendingProblem);
83
84 if(pendingProblem != null && pendingProblem.equals("true")) {
85 session.setAttribute(WebKeys.PendingProblem, "false");
86 nextScreen = "1";
87
88 }
89 nextScreen = "1";
90
91 }
92 else if(request.getAttribute(WebKeys.ExistsTemplatesList) != null) {
93
94
95 CommonUtil.putVariableInRequest(request, context, companyId,
96 WebKeys.TemplatesTable, WebKeys.TemplatesList);
97
98
99
100 CommonUtil.putVariableInRequest(request, context, companyId,
101 WebKeys.CategoryTable, WebKeys.CategoryList);
102
103 nextScreen = "2";
104
105
106 }
107 else if(ce.getActionType() == TemplatesEvent.LIST_TEMPLATES_NAMES) {
108
109
110
111
112
113 CommonUtil.putVariableInContext(context, companyId,
114 WebKeys.TemplatesTable, ((ArrayList)answer).get(1));
115
116
117 request.setAttribute
118 (WebKeys.TemplatesList, ((ArrayList)answer).get(1));
119
120
121 CommonUtil.putVariableInContext(context, companyId,
122 WebKeys.CategoryTable, ((ArrayList)answer).get(0));
123
124
125 request.setAttribute
126 (WebKeys.CategoryList, ((ArrayList)answer).get(0));
127
128 nextScreen = "2";
129
130
131 }
132 else if(ce.getActionType() == TemplatesEvent.UPDATE_TEMPLATES_NAMES) {
133
134
135
136
137
138 CommonUtil.putVariableInContext(context, companyId,
139 WebKeys.ComponentsTable, "");
140
141
142 CommonUtil.putVariableInContext(context, companyId,
143 WebKeys.TemplatesTable, ((ArrayList)answer).get(1));
144
145
146 request.setAttribute
147 (WebKeys.TemplatesList, ((ArrayList)answer).get(1));
148
149
150
151 CommonUtil.putVariableInRequest(request, context, companyId,
152 WebKeys.CategoryTable, WebKeys.CategoryList);
153
154 String problem = (String)(((ArrayList)answer).get(0));
155
156 if(problem.equals(LetterTemplateGlobals.STR_UNDEF)) {
157 nextScreen = "2";
158
159 }
160 else {
161
162 JSPUtil.putProblemInRequest(request, problem);
163 nextScreen = "1";
164
165
166 }
167 }
168
169 return nextScreen;
170 }
171
172
173
178 public void doEnd(HttpServletRequest request) { }
179 }
180
181