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 CountryTranslator
15 implements Serializable {
16 private String[] code;
17 private String[] comments;
18 private String[] message;
19 private String[] name;
20 private NodeList nlCode;
21 private NodeList nlName;
22 private NodeList nlComment;
23 private String Countries;
24 private int nlLength;
25 private String prData;
26
27
28 public void setData(String data) throws XMLParseException, XSLException, SAXException, IOException {
29 DOMParser docParser = new DOMParser();
30 ByteArrayInputStream stream;
31 XMLDocument xmlDoc = null;
32 try {
33 prData = data;
34 stream = new ByteArrayInputStream(data.getBytes());
35 docParser.setValidationMode(false);
36 docParser.parse(stream);
37 xmlDoc = docParser.getDocument();
38 nlCode = xmlDoc.selectNodes("/CountriesList/Country/code/text()");
39 nlName = xmlDoc.selectNodes("/CountriesList/Country/name/text()");
40 nlComment = xmlDoc.selectNodes("/CountriesList/Country/comments/text()");
41 nlLength = nlCode.getLength();
42 code = new String[nlLength];
43 name = new String[nlLength];
44 comments = new String[nlLength];
45 for(int i = 0; i < nlLength; i++) {
46 code[i] = nlCode.item(i).getNodeValue();
47 name[i] = nlName.item(i).getNodeValue();
48 if(nlComment.item(i).getNodeValue().equals("_")) {
49 comments[i] = "";
50 }
51 else {
52 comments[i] = nlComment.item(i).getNodeValue();
53 }
54 }
55 }
56 catch(Exception e) {}
57 }
58
59
60 public String getCountriesArray() {
61 String Head = null;
62 String Body = null;
63 char Ch = '"';
64
65 try {
66 Head = "numberOfItems = " + nlLength + "; \n" +
67 "numberOfDeleted=0;\n";
68 Body = "";
69 for(int i = 0; i < nlLength; i++) {
70 code[i] = StringFormat.toSafeJavaString(code[i]);
71 name[i] = StringFormat.toSafeJavaString(name[i]);
72 comments[i] = StringFormat.toSafeJavaString(comments[i]);
73 Body = Body +
74 "itemsArray[" + i + "] = new Item(" + Ch + code[i] + Ch +
75 "," + Ch + code[i] + Ch + "," + Ch + name[i] + Ch + "," + Ch + comments[i] + Ch +
76 "," + Ch + "N" + Ch + ");\n";
77 }
78 Head = Head;
79 }
80 catch(Exception e) {}
81 return (Head + Body);
82 }
83 }
84
85