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