1 package com.instantbank.collections.companyInfo.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.XMLNode;
9 import oracle.xml.parser.v2.XMLParseException;
10 import oracle.xml.parser.v2.XSLException;
11 import org.w3c.dom.NodeList;
12 import org.xml.sax.SAXException;
13 import com.instantbank.collections.basicInfo.ejb.BasicInfoServices;
14 import com.instantbank.collections.basicInfo.ejb.BasicInfoServicesHome;
15 import com.instantbank.collections.util.ServiceLocator;
16 import com.instantbank.collections.util.StringFormat;
17
18
24 public class CompanyTransformer
25 implements Serializable {
26 private String controller;
27 private XMLDocument data;
28 private XMLNode root;
29
30
31 public CompanyTransformer() { }
32
33
34 public String getAddressesArray() throws Exception {
35 NodeList addresses;
36 XMLNode address;
37 String city = " ";
38 String country = " ";
39 String id;
40 String idLoc;
41 String ipAddress = " ";
42 String line1 = " ";
43 String line2 = " ";
44 NodeList locations;
45 XMLNode location;
46 String name;
47 int numLocations;
48 String password;
49 String path = " ";
50 String phone = "2";
51 String result;
52 String s;
53 String state = " ";
54 String user = " ";
55 String zipCode = " ";
56
57 result = "";
58 try {
59 addresses = root.selectNodes("./Addresses/Address");
60 int addressNumber = addresses.getLength();
61 for(int i = 0; i < addressNumber; i++) {
62 address = (XMLNode)addresses.item(i);
63 id = address.valueOf("./id");
64 line1 = StringFormat.toSafeJavaString(address.valueOf("./line1"));
65 line2 = StringFormat.toSafeJavaString(address.valueOf("./line2"));
66 country = StringFormat.toSafeJavaString(address.valueOf("./country"));
67 city = StringFormat.toSafeJavaString(address.valueOf("./city"));
68 state = StringFormat.toSafeJavaString(address.valueOf("./state"));
69 zipCode = StringFormat.toSafeJavaString(address.valueOf("./zipcode"));
70 phone = StringFormat.toSafeJavaString(address.valueOf("./phone"));
71 locations = address.selectNodes("./Locations/Location");
72 result += "locations = new Object();\n";
73 numLocations = locations.getLength();
74 for(int j = 0; j < numLocations; j++) {
75 location = (XMLNode)locations.item(j);
76 idLoc = location.valueOf("./id");
77 path = StringFormat.toSafeJavaString(location.valueOf("./path"));
78 name = StringFormat.toSafeJavaString(location.valueOf("./name"));
79 ipAddress = StringFormat.toSafeJavaString(location.valueOf("./ipaddress"));
80 user = StringFormat.toSafeJavaString(location.valueOf("./theuser"));
81 password = StringFormat.toSafeJavaString(location.valueOf("./password"));
82 result += "locations[" + j + "] = new Location(";
83 result += idLoc + ",\"" + path + "\",\"" + name + "\",\"" + ipAddress + "\",\"" + user + "\",\"" + password + "\");\n";
84 }
85 result += "addresses[" + i + "] = new Address(";
86 result += id + ",\"" + phone + "\",\"" + line1 + "\",\"" + line2 + "\",\"" + city + "\",\"" + country + "\",\"" + state + "\",\"" + zipCode + "\"," + numLocations + ",locations);\n";
87 }
88 }
89 catch(Exception e) {
90 }
91 return result;
92 }
93
94
95 public String getController() {
96 return controller;
97 }
98
99
100 public String getCountriesOptions() {
101 String code;
102 DOMParser docParser = new DOMParser();
103 BasicInfoServicesHome home;
104 String name;
105 NodeList nlCode;
106 NodeList nlName;
107 String s = "";
108 BasicInfoServices services;
109 ByteArrayInputStream stream;
110 String xml;
111 XMLDocument xmlDoc = null;
112
113 try {
114 home = (BasicInfoServicesHome)ServiceLocator.instance().createEJB("BasicInfoServicesHome", BasicInfoServicesHome.class, false);
115 services = home.create();
116 xml = services.getCountries();
117 stream = new ByteArrayInputStream(xml.getBytes());
118 docParser.setValidationMode(false);
119 docParser.parse(stream);
120 xmlDoc = docParser.getDocument();
121 nlCode = xmlDoc.selectNodes("/CountriesList/Country/code/text()");
122 nlName = xmlDoc.selectNodes("/CountriesList/Country/name/text()");
123
124 for(int i = 0; i < nlCode.getLength(); i++) {
125 code = StringFormat.toSafeJavaString(nlCode.item(i).getNodeValue());
126 if(code == null) {
127 code = "";
128 }
129 name = StringFormat.toSafeHTMLString(nlName.item(i).getNodeValue());
130 if(name == null) {
131 name = "";
132 }
133 s += "<option value=\"" + code + "\">" + name + "</option>";
134 }
135 }
136 catch(Exception e) {
137 }
138 return s;
139 }
140
141
142 public String getId() throws Exception {
143 return data.valueOf("/Company/Id");
144 }
145
146
147 public String getCountry() throws Exception {
148 return data.valueOf("/Company/Country");
149 }
150
151
152 public String getDateMaintained() throws Exception {
153 return data.valueOf("/Company/DateMaintained");
154 }
155
156
157 public String getLastMaintainedBy() throws Exception {
158 return data.valueOf("/Company/LastMaintainedBy");
159 }
160
161
162 public String getName() throws Exception {
163 return data.valueOf("/Company/Name");
164 }
165
166
167 public String getNumber() throws Exception {
168 return data.valueOf("/Company/Number");
169 }
170
171
172 public String getNumberOfAddresses() {
173
174 int addressNum = 0;
175 String s = "";
176 try {
177 addressNum = root.selectNodes("./Addresses/Address").getLength();
178 Integer addressNumber = new Integer(addressNum);
179 s = addressNumber.toString();
180 }
181 catch(Exception e) {}
182 return s;
183 }
184
185
186 public String getSEDaysBeforePasswordReuse() throws Exception {
187 return data.valueOf("/Company/Security/dbpr");
188 }
189
190
191 public String getSEInvalidSignonAttempts() throws Exception {
192 return data.valueOf("/Company/Security/isaa");
193 }
194
195
196 public String getSEMinimumPasswordLength() throws Exception {
197 return data.valueOf("/Company/Security/mpl");
198 }
199
200
201 public String getSEMinutesInactiveBeforeRevoked() throws Exception {
202 return data.valueOf("/Company/Security/mibr");
203 }
204
205
206 public String getSENumberOfUniquePasswords() throws Exception {
207 return data.valueOf("/Company/Security/nup");
208 }
209
210
211 public String getSEPasswordExpirationDays() throws Exception {
212 return data.valueOf("/Company/Security/ped");
213 }
214
215
216 public String getSEPasswordExpirationWarningDays() throws Exception {
217 return data.valueOf("/Company/Security/pewd");
218 }
219
220
221 public String getTemporaryPath() throws Exception {
222 return StringFormat.toSafeJavaString(data.valueOf("/Company/TemporaryPath"));
223 }
224
225
226 public void setController(String controller) {
227 this.controller = controller;
228 }
229
230
231 public void setData(String data) throws XMLParseException, XSLException, SAXException, IOException {
232 DOMParser docParser = new DOMParser();
233 ByteArrayInputStream stream;
234 stream = new ByteArrayInputStream(data.getBytes());
235 docParser.setValidationMode(false);
236 docParser.parse(stream);
237 this.data = docParser.getDocument();
238 root = (XMLNode)this.data.getDocumentElement();
239 }
240 }
241
242