1    package com.instantbank.lettertemplate.imagesRepository.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.CodeDescription;
15   import com.instantbank.common.utilcomponents.Debug;
16   
17   /**
18    *  Letter Images usecase: helper class for ImagesRepositoryMain.jsp
19    *
20    * @author Instant-bank (Consuelo Franky, Jorge Cardenas)
21    * @created August 2002
22    */
23   public class ImageTranslator
24       implements Serializable {
25     // input data for the jsp: elements of images list
26     private String[] code;
27     private String[] name;
28     private int nlLength;
29   
30     private Debug debug = null;
31   
32   
33     /**
34      *  gets images list from request and creates input data for the jsp setting
35      *  values of code and name Strings
36      *
37      * @param request of MainServlet
38      */
39     public void setData(HttpServletRequest request) {
40   
41       debug = new Debug();
42       debug.setDebugginOn(true);
43       debug.setPreMessage("** ImageTranslator: ");
44   
45       try {
46   
47         CodeDescription[] cd = (CodeDescription[])
48           request.getAttribute(WebKeys.ImagesRepositoryList);
49         debug.println("images list obtained");
50         nlLength = cd.length;
51         code = new String[nlLength];
52         name = new String[nlLength];
53   
54         for(int i = 0; i < nlLength; i++) {
55           code[i] = String.valueOf(cd[i].getCode());
56           name[i] = cd[i].getDescription();
57         }
58       }
59       catch(Exception e) {
60         debug.println("Exception unexpected:" + e.getMessage());
61       }
62     }
63   
64   
65     /**
66      *  extends the onLoad() javaScript method initializing itemsArrays according
67      *  to input data of the jsp
68      *
69      * @return String to append to onLoad()
70      */
71     public String getImagesArray() {
72       String Head = null;
73       String Body = null;
74       char Ch = '"';
75   
76       Head = "numberOfItems = " + nlLength + "; \n" +
77         "numberOfDeleted=0;\n";
78       Body = "";
79       for(int i = 0; i < nlLength; i++) {
80         Body = Body +
81           "itemsArray[" + i + "] = new Item("
82           + Ch + code[i] + Ch + ","
83           + Ch + name[i] + Ch + ","
84           + Ch + "N" + Ch +
85         // status "N" means "not modified"
86           ");\n";
87       }
88       //debug.println ("Body="+ Body);
89       return (Head + Body);
90     }
91   }
92   
93