1    package com.instantbank.collections.basicInfo.web;
2    
3    import java.io.ByteArrayInputStream;
4    import java.io.IOException;
5    import java.io.Serializable;
6    import oracle.xml.parser.v2.DOMParser;
7    import oracle.xml.parser.v2.XMLDocument;
8    import oracle.xml.parser.v2.XMLParseException;
9    import oracle.xml.parser.v2.XSLException;
10   import org.w3c.dom.NodeList;
11   import org.xml.sax.SAXException;
12   import com.instantbank.collections.util.StringFormat;
13   
14   public class StateTranslator
15       implements Serializable {
16     private String[] id;
17     private String[] code;
18     private String[] name;
19     private String[] sttCoun;
20     private String[] message;
21     private NodeList nlId;
22     private NodeList nlCode;
23     private NodeList nlName;
24     private NodeList nlsttCoun;
25     private String States;
26     private int nlLength;
27     private String prData;
28   
29   
30     public void setData(String data) throws XMLParseException, XSLException, SAXException, IOException {
31       DOMParser docParser = new DOMParser();
32       ByteArrayInputStream stream;
33       XMLDocument xmlDoc = null;
34   
35       try {
36         prData = data;
37         stream = new ByteArrayInputStream(data.getBytes());
38         docParser.setValidationMode(false);
39         docParser.parse(stream);
40         xmlDoc = docParser.getDocument();
41         nlId = xmlDoc.selectNodes("/StatesList/State/id/text()");
42         nlCode = xmlDoc.selectNodes("/StatesList/State/code/text()");
43         nlName = xmlDoc.selectNodes("/StatesList/State/name/text()");
44         nlsttCoun = xmlDoc.selectNodes("/StatesList/State/country/text()");
45         nlLength = nlId.getLength();
46         id = new String[nlLength];
47         code = new String[nlLength];
48         name = new String[nlLength];
49         sttCoun = new String[nlLength];
50         for(int i = 0; i < nlLength; i++) {
51           id[i] = nlId.item(i).getNodeValue();
52           code[i] = nlCode.item(i).getNodeValue();
53           name[i] = nlName.item(i).getNodeValue();
54           sttCoun[i] = nlsttCoun.item(i).getNodeValue();
55         }
56       }
57       catch(Exception e) {}
58     }
59   
60   
61     public String getStatesArray(String CounId) {
62       String Head = null;
63       String Body = null;
64       String CounCode = null;
65       String iniCoun = null;
66       char Ch = '"';
67   
68       try {
69         Head = "numberOfItems = " + nlLength + "; \n" +
70           "numberOfDeleted=0;\n";
71         Body = "";
72         CounCode = CounId;
73         for(int i = 0; i < nlLength; i++) {
74           id[i] = StringFormat.toSafeJavaString(id[i]);
75           code[i] = StringFormat.toSafeJavaString(code[i]);
76           name[i] = StringFormat.toSafeJavaString(name[i]);
77           sttCoun[i] = StringFormat.toSafeJavaString(sttCoun[i]);
78           Body = Body +
79             "itemsArray[" + i + "] = new Item(" + Ch + id[i] + Ch +
80             "," + Ch + code[i] + Ch + "," + Ch + name[i] + Ch + "," + Ch + sttCoun[i] + Ch + "," + Ch + "N" + Ch + ");\n";
81         }
82         Head = Head;
83         iniCoun = "currCounCode = " + Ch + StringFormat.toSafeJavaString(CounCode) + Ch + "\n";
84       }
85       catch(Exception e) {}
86       return (Head + Body + iniCoun);
87     }
88   }
89