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.PreviewPrintEvent;
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.lettertemplate.control.LetterTemplateEventException;
21   
22   /**
23    *  Preview/Print Letter usecase: flow handler for deciding output screen after
24    *  processing an action
25    *
26    * @author Instant-bank (Jorge Cardenas)
27    * @created August 2002
28    */
29   public class PreviewPrintFlowHandler
30       implements FlowHandler {
31     private Debug debug = null;
32   
33   
34     /**
35      *  optional execution before processFlow method
36      *
37      * @param request HTTP request
38      */
39     public void doStart(HttpServletRequest request) { }
40   
41   
42     /**
43      *  principal method for deciding output screen after processing an action
44      *
45      * @param request of MainServlet
46      * @param answer of the action
47      * @param context web context
48      * @return String with the number of the output screen
49      * @exception LetterTemplateEventException
50      */
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("** PreviewPrintFlowHandler: ");
57       debug.println("processFlow");
58   
59       String nextScreen = null;
60       PreviewPrintEvent ce = null;
61       Hashtable templateTable = null;
62   
63       HttpSession session = request.getSession();
64       String companyId = (String)request.getSession()
65         .getAttribute(WebKeys.CompanyId);
66   
67       if(request.getAttribute(WebKeys.PreviewPrintEvent) != null) {
68         ce = (PreviewPrintEvent)request.getAttribute(WebKeys.PreviewPrintEvent);
69       }
70   
71       if(request.getAttribute(WebKeys.ExceptionOcurred) != null) {
72   
73         // puts in request the current templates list,
74         // obtained from the web context:
75         CommonUtil.putVariableInRequest(request, context, companyId,
76           WebKeys.TemplatesTable, WebKeys.TemplatesList);
77   
78         Object pendingProblem = session.getAttribute(WebKeys.PendingProblem);
79   
80         if(pendingProblem != null && pendingProblem.equals("true")) {
81           session.setAttribute(WebKeys.PendingProblem, "false");
82           nextScreen = "1";
83           // PREVIEWPRINT_PROBLEM
84         }
85         nextScreen = "1";
86   
87       }
88       else if(request.getAttribute(WebKeys.ExistsTemplatesList) != null) {
89         // puts in request the current templates list,
90         // obtained from the web context:
91         CommonUtil.putVariableInRequest(request, context, companyId,
92           WebKeys.TemplatesTable, WebKeys.TemplatesList);
93   
94         nextScreen = "2";
95         // PREVIEWPRINT_MAIN
96   
97       }
98       else if(ce.getActionType() == PreviewPrintEvent.LIST_TEMPLATES_PREVIEW) {
99         // answer is an ArrayList with 1 elements:
100        // 0: current templates list: ArrayList
101  
102        // puts current templates list in the web context :
103        CommonUtil.putVariableInContext(context, companyId,
104          WebKeys.TemplatesTable, answer);
105  
106        // puts current templates list in the web request :
107        request.setAttribute
108          (WebKeys.TemplatesList, answer);
109  
110        nextScreen = "2";
111        // PREVIEWPRINT_MAIN
112  
113      }
114  
115      return nextScreen;
116    }
117  
118  
119    /**
120     *  optional execution after processFlow method
121     *
122     * @param request HTTP request
123     */
124    public void doEnd(HttpServletRequest request) { }
125  }
126  
127