1    package com.instantbank.lettertemplate.previewPrint.web;
2    
3    import java.io.*;
4    import java.net.*;
5    import java.util.*;
6    import javax.naming.*;
7    import javax.rmi.*;
8    import javax.servlet.http.HttpServletRequest;
9    
10   import oracle.xml.parser.v2.*;
11   import org.w3c.dom.*;
12   import org.xml.sax.*;
13   import com.instantbank.lettertemplate.control.util.WebKeys;
14   import com.instantbank.common.utilcomponents.Debug;
15   
16   /**
17    *  Preview/Print Letter usecase: helper class for previewPrintMain.jsp
18    *
19    * @author Instant-bank (Jorge Cardenas)
20    * @created August 2002
21    */
22   public class PreviewPrintTranslator
23       implements Serializable {
24     // input data for the jsp: elements of images list
25   
26     private String[] codetemplate;
27     private String[] category;
28     private String[] printtype;
29     private String[] nametempl;
30     private int nlLengthT;
31   
32     private Debug debug = null;
33   
34   
35     /**
36      *  gets templates list from request and creates input data for the jsp
37      *  setting values of code and name Strings
38      *
39      * @param request of MainServlet
40      */
41     public void setData(HttpServletRequest request) {
42   
43       debug = new Debug();
44       debug.setDebugginOn(true);
45       debug.setPreMessage("** PreviewPrintTranslator: ");
46   
47       try {
48         ArrayList listTempl = new ArrayList();
49         ArrayList item = new ArrayList();
50   
51         listTempl = (ArrayList)request.getAttribute(WebKeys.TemplatesList);
52         nlLengthT = listTempl.size();
53         codetemplate = new String[nlLengthT];
54         category = new String[nlLengthT];
55         printtype = new String[nlLengthT];
56         nametempl = new String[nlLengthT];
57   
58         for(int i = 0; i < nlLengthT; i++) {
59           item = (ArrayList)(listTempl.get(i));
60           codetemplate[i] = String.valueOf(((Long)item.get(0)).longValue());
61           category[i] = (String)item.get(1);
62           printtype[i] = (String)item.get(2);
63           nametempl[i] = (String)item.get(3);
64         }
65       }
66   
67       catch(Exception e) {
68         debug.println("Exception unexpected:" + e.getMessage());
69       }
70     }
71   
72   
73     /**
74      *  extends the onLoad() javaScript method initializing itemsArrays according
75      *  to input data of the jsp
76      *
77      * @return String to append to onLoad()
78      */
79     public String getTemplatesArray() {
80       String Head = null;
81       String Body = null;
82       char Ch = '"';
83   
84       Head = "numberOfItems = " + nlLengthT + "; \n" +
85         "numberOfDeleted=0;\n";
86       Body = "";
87       for(int i = 0; i < nlLengthT; i++) {
88         Body = Body +
89           "itemsArray[" + i + "] = new Item("
90           + Ch + codetemplate[i] + Ch + ","
91           + Ch + category[i] + Ch + ","
92           + Ch + printtype[i] + Ch + ","
93           + Ch + nametempl[i] + Ch + ","
94           + Ch + "N" + Ch +   // status "N" means "not modified"
95         ");\n";
96       }
97       //debug.println ("Body="+ Body);
98       return (Head + Body);
99     }
100  }
101  
102