1    package com.instantbank.collections.collectionsActivities.web;
2    
3    import java.io.ByteArrayInputStream;
4    import org.w3c.dom.Element;
5    import org.w3c.dom.NodeList;
6    import oracle.xml.parser.v2.DOMParser;
7    import oracle.xml.parser.v2.XMLDocument;
8    import oracle.xml.parser.v2.XMLNode;
9    import com.instantbank.collections.basicInfo.ejb.BasicInfoServices;
10   import com.instantbank.collections.basicInfo.ejb.BasicInfoServicesHome;
11   import com.instantbank.collections.util.InstantbankException;
12   import com.instantbank.collections.util.ServiceLocator;
13   import com.instantbank.collections.util.StringFormat;
14   
15   /**
16    * A Bean class.
17    * <P>
18    *
19    * @author Indudata
20    */
21   public class SearchAccountTransformer {
22   
23     private String accountNumber = "";
24     private String businessPhone = "";
25     private String city = "";
26     private String customerRole = "";
27     private String driversLicense = "";
28     private String emailAddress = "";
29     private String firstName = "";
30     private String homePhone = "";
31     private String lastName = "";
32     private String oldAccountNumber = "";
33     private String paymentAmount = "";
34     private String socialSecurityNbr = "";
35     private String stateCode = "";
36     private String street = "";
37     private String vinNbr = "";
38     private String zipCode = "";
39   
40     private String customerRolesXmlString;
41     private XMLDocument customerRolesXml;
42   
43     private StatesTransformer statesTransformer;
44   
45   
46     /**
47      * Constructor
48      */
49     public SearchAccountTransformer() {
50       DOMParser docParser = new DOMParser();
51       ByteArrayInputStream stream = null;
52   
53       try {
54         statesTransformer = new StatesTransformer("US");
55         BasicInfoServicesHome bihome = (BasicInfoServicesHome)
56           ServiceLocator.instance().createEJB("BasicInfoServicesHome", BasicInfoServicesHome.class, false);
57         BasicInfoServices basicInfoServices = bihome.create();
58         customerRolesXmlString = basicInfoServices.getCustomerRoles();
59         stream = new ByteArrayInputStream(customerRolesXmlString.getBytes());
60         docParser.setValidationMode(false);
61         docParser.parse(stream);
62         customerRolesXml = docParser.getDocument();
63       }
64       catch(Exception e) {}
65     }
66   
67   
68     public String getCustomerRolesOptions() throws InstantbankException {
69       String customerRolesOptions = "";
70       XMLNode node;
71       NodeList nodeList;
72       Element root;
73       String selectedFlag = "";
74       try {
75         root = customerRolesXml.getDocumentElement();
76         nodeList = root.getChildNodes();
77         for(int i = 0; i < nodeList.getLength(); i++) {
78           node = (XMLNode)nodeList.item(i);
79           if((node.valueOf("./code")).equals(this.customerRole)) {
80             selectedFlag = "selected";
81           }
82           customerRolesOptions += "<option " + selectedFlag + " value='" + StringFormat.toSafeHTMLString(node.valueOf("./code")) + "'>" + StringFormat.toSafeHTMLString(node.valueOf("./description")) + "</option>";
83           selectedFlag = "";
84         }
85       }
86       catch(Exception e) {}
87       return customerRolesOptions;
88     }
89   
90   
91     public String getStatesOptions() throws InstantbankException {
92       try {
93       }
94       catch(Exception e) {}
95       return statesTransformer.getStatesOptions(this.stateCode);
96     }
97   
98   
99     public void setCriteriaData(String criteriaXmlString) throws InstantbankException {
100  
101      XMLDocument criteriaXml;
102      DOMParser docParser = new DOMParser();
103      XMLNode node;
104      Element root;
105      ByteArrayInputStream stream = null;
106  
107      try {
108        if(criteriaXmlString != null) {
109          stream = new ByteArrayInputStream(criteriaXmlString.getBytes());
110          docParser.setValidationMode(false);
111          docParser.parse(stream);
112          criteriaXml = docParser.getDocument();
113          root = criteriaXml.getDocumentElement();
114          node = (XMLNode)root;
115          this.accountNumber = node.valueOf("./AccountNo");
116  
117          this.businessPhone = node.valueOf("./BusinessPhone");
118          this.city = node.valueOf("./City");
119          this.customerRole = node.valueOf("./CustomerRole");
120          this.driversLicense = node.valueOf("./DriversLicense");
121          this.emailAddress = node.valueOf("./Email");
122  
123          this.firstName = node.valueOf("./FirstName");
124          this.homePhone = node.valueOf("./HomePhone");
125          this.lastName = node.valueOf("./LastName");
126          this.oldAccountNumber = node.valueOf("./OldAccountNo");
127          this.paymentAmount = node.valueOf("./PaymentAmount");
128          this.socialSecurityNbr = node.valueOf("./SSN");
129          this.stateCode = node.valueOf("./StateCode");
130          this.street = node.valueOf("./Street");
131          this.vinNbr = node.valueOf("./VIN");
132          this.zipCode = node.valueOf("./ZipCode");
133        }
134      }
135      catch(Exception e) {
136        e.printStackTrace();
137      }
138      return;
139    }
140  
141  
142    public String setData(String data) throws InstantbankException {
143      String ssnNumber = "";
144      String dataRows = "";
145      XMLDocument dataXml;
146      DOMParser docParser = new DOMParser();
147      String lastRow = "-1";
148      XMLNode node;
149      NodeList nodeList;
150      Element root;
151      ByteArrayInputStream stream;
152      stream = new ByteArrayInputStream(data.getBytes());
153      try {
154        docParser.setValidationMode(false);
155        docParser.parse(stream);
156        dataXml = docParser.getDocument();
157        root = dataXml.getDocumentElement();
158        nodeList = root.getChildNodes();
159        for(int i = 0; i < nodeList.getLength(); i++) {
160          node = (XMLNode)nodeList.item(i);
161          if(node.valueOf("./ssn").length() > 8) {
162            ssnNumber = node.valueOf("./ssn").substring(0, 3) + "-" +
163              node.valueOf("./ssn").substring(3, 5) + "-" +
164              node.valueOf("./ssn").substring(5, 9);
165          }
166          else {
167            ssnNumber = node.valueOf("./ssn");
168          }
169          dataRows += "<tr style=\"cursor:hand;\" onClick=\"onSelect(this)\" onDblClick=\"onDoubleClick(" + node.valueOf("./id") + ")\" id=\"row" + (new Long(i)).toString() + "\">\n" +
170            "  <td width=\"110\" align=\"left\"><font face=\"Tahoma\"><small>  " + node.valueOf("./accountnumber") + "</small></font></td>\n" +
171            "  <td width=\"110\" align=\"left\"><font face=\"Tahoma\"><small>" + node.valueOf("./customerrole") + "</small></font></td>\n" +
172            "  <td width=\"110\" align=\"left\"><font face=\"Tahoma\"><small>" + node.valueOf("./name") + "</small></font></td>\n" +
173            "  <td width=\"110\" align=\"left\"><font face=\"Tahoma\"><small>" + ssnNumber + "</small></font></td>\n" +
174            "  <td width=\"110\" align=\"left\"><font face=\"Tahoma\"><small>" + node.valueOf("./city") + ", " + node.valueOf("./state") + "</small></font></td>\n" +
175            "  <td width=\"110\" align=\"left\"><font face=\"Tahoma\"><small>" + node.valueOf("./vin") + "</small></font></td>\n" +
176            "</tr>\n";
177          if((new Integer(1)).parseInt(node.valueOf("./therow")) > (new Integer(1)).parseInt(lastRow)) {
178            lastRow = node.valueOf("./therow");
179          }
180        }
181        lastRow = "<script>lastRow = " + lastRow + ";</script>";
182      }
183      catch(Exception e) {}
184      return dataRows + lastRow;
185    }
186  
187  
188    public String setLastUsedRownum(String lastRownum) throws InstantbankException {
189      return "<script>beforeLastRow = " + lastRownum + ";</script>";
190    }
191  
192  
193    public String getAccountNumber() throws InstantbankException {
194      return this.accountNumber;
195    }
196  
197  
198    public String getBusinessPhone() throws InstantbankException {
199      return this.businessPhone;
200    }
201  
202  
203    public String getCity() throws InstantbankException {
204      return this.city;
205    }
206  
207  
208    public String getCustomerRole() throws InstantbankException {
209      return this.customerRole;
210    }
211  
212  
213    public String getDriversLicense() throws InstantbankException {
214      return this.driversLicense;
215    }
216  
217  
218    public String getEmailAddress() throws InstantbankException {
219      return this.emailAddress;
220    }
221  
222  
223    public String getFirstName() throws InstantbankException {
224      return this.firstName;
225    }
226  
227  
228    public String getHomePhone() throws InstantbankException {
229      return this.homePhone;
230    }
231  
232  
233    public String getLastName() throws InstantbankException {
234      return this.lastName;
235    }
236  
237  
238    public String getOldAccountNumber() throws InstantbankException {
239      return this.oldAccountNumber;
240    }
241  
242  
243    public String getPaymentAmount() throws InstantbankException {
244      return this.paymentAmount;
245    }
246  
247  
248    public String getSocialSecurityNbr() throws InstantbankException {
249      return this.socialSecurityNbr;
250    }
251  
252  
253    public String getStateCode() throws InstantbankException {
254      return this.stateCode;
255    }
256  
257  
258    public String getStreet() throws InstantbankException {
259      return this.street;
260    }
261  
262  
263    public String getVinNbr() throws InstantbankException {
264      return this.vinNbr;
265    }
266  
267  
268    public String getZipCode() throws InstantbankException {
269      return this.zipCode;
270    }
271  }
272  
273