1    package com.instantbank.lettertemplate.components.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    *  Letter Components usecase: helper class for ComponentsMain.jsp
18    *
19    * @author Instant-bank (Jorge Cardenas)
20    * @created August 2002
21    */
22   public class ComponentsTranslator
23       implements Serializable {
24   
25     // input data for the jsp: elements of components list
26     private String[] codeComponent;
27     private String[] nameComponentType;
28     private String[] printType;
29     private String[] nameComponent;
30     private int nlLength;
31   
32     private Debug debug = null;
33   
34   
35     /**
36      *  gets components 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("** ComponentsTranslator: ");
46   
47       try {
48         ArrayList listComponents = new ArrayList();
49         ArrayList item = new ArrayList();
50   
51         listComponents = (ArrayList)request.getAttribute(WebKeys.ComponentsList);
52         debug.println("components list obtained");
53   
54         nlLength = listComponents.size();
55   
56         codeComponent = new String[nlLength];
57         nameComponentType = new String[nlLength];
58         printType = new String[nlLength];
59         nameComponent = new String[nlLength];
60   
61         for(int i = 0; i < nlLength; i++) {
62           item = (ArrayList)(listComponents.get(i));
63           codeComponent[i] = String.valueOf(((Long)item.get(0)).longValue());
64           nameComponentType[i] = (String)item.get(1);
65           printType[i] = (String)item.get(2);
66           nameComponent[i] = (String)item.get(3);
67         }
68       }
69       catch(Exception e) {
70         debug.println("Exception unexpected:" + e.getMessage());
71       }
72     }
73   
74   
75     /**
76      *  extends the onLoad() javaScript method initializing itemsArrays according
77      *  to input data of the jsp
78      *
79      * @return String to append to onLoad()
80      */
81     public String getComponentsArray() {
82       String Head = null;
83       String Body = null;
84       char Ch = '"';
85   
86       Head = "numberOfItems = " + nlLength + "; \n" +
87         "numberOfDeleted=0;\n";
88       Body = "";
89       for(int i = 0; i < nlLength; i++) {
90         Body = Body +
91           "itemsArray[" + i + "] = new Item("
92           + Ch + codeComponent[i] + Ch + ","
93           + Ch + nameComponentType[i] + Ch + ","
94           + Ch + printType[i] + Ch + ","
95           + Ch + nameComponent[i] + Ch + ","
96           + Ch + "N" + Ch +
97         // status "N" means "not modified"
98           ");\n";
99       }
100      //debug.println ("Body="+ Body);
101      return (Head + Body);
102    }
103  }
104  
105