1    package com.instantbank.collections.collectionsActivities.web;
2    
3    import java.io.ByteArrayInputStream;
4    import oracle.xml.parser.v2.DOMParser;
5    import oracle.xml.parser.v2.XMLDocument;
6    import oracle.xml.parser.v2.XMLNode;
7    import org.w3c.dom.Element;
8    import org.w3c.dom.NodeList;
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   
14   /**
15    * A Bean class.
16    * <P>
17    *
18    * @author Indudata
19    */
20   public class StatesTransformer {
21   
22     private String statesXmlString;
23     private XMLDocument statesXml;
24   
25   
26     /**
27      * Constructor
28      *
29      * @param countryId Description of the Parameter
30      * @throws InstantbankException Description of the Exception
31      */
32     public StatesTransformer(String countryId) throws InstantbankException {
33       DOMParser docParser = new DOMParser();
34       ByteArrayInputStream stream = null;
35   
36       try {
37         BasicInfoServicesHome bihome = (BasicInfoServicesHome)
38           ServiceLocator.instance().createEJB("BasicInfoServicesHome", BasicInfoServicesHome.class, false);
39         BasicInfoServices basicInfoServices = bihome.create();
40         statesXmlString = basicInfoServices.getStates(countryId);
41         stream = new ByteArrayInputStream(statesXmlString.getBytes());
42         docParser.setValidationMode(false);
43         docParser.parse(stream);
44         statesXml = docParser.getDocument();
45       }
46       catch(Exception e) {}
47     }
48   
49   
50     public String getStatesOptions(String selectedStateCode) throws InstantbankException {
51       String statesOptions = "";
52       XMLNode node;
53       NodeList nodeList;
54       Element root;
55       String selectedFlag = "";
56       try {
57         root = statesXml.getDocumentElement();
58         nodeList = root.getChildNodes();
59         for(int i = 0; i < nodeList.getLength(); i++) {
60           node = (XMLNode)nodeList.item(i);
61           if(node.valueOf("./id").equals(selectedStateCode)) {
62             selectedFlag = "selected";
63           }
64           statesOptions += "<option " + selectedFlag + " value='" + node.valueOf("./id") + "'>" + node.valueOf("./code") + " - " + node.valueOf("./name") + "</option>";
65           selectedFlag = "";
66         }
67       }
68       catch(Exception e) {}
69       return statesOptions;
70     }
71   }
72   
73