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.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.companyInfo.ejb.CompanyServices;
13   import com.instantbank.collections.companyInfo.ejb.CompanyServicesHome;
14   import com.instantbank.collections.util.ServiceLocator;
15   import com.instantbank.collections.util.StringFormat;
16   
17   /**
18    * A Bean class.
19    * <P>
20    *
21    * @author Indudata Ltda.
22    */
23   public class SelectCompanyTransformer
24       implements Serializable {
25   
26     private String controller;
27     private XMLDocument data;
28   
29   
30     /**
31      * Constructor
32      */
33     public SelectCompanyTransformer() { }
34   
35   
36     public String getController() {
37       return controller;
38     }
39   
40   
41     public String getCompaniesOptions() {
42       DOMParser docParser = new DOMParser();
43       CompanyServicesHome home;
44       String Id;
45       String name;
46       NodeList nlId;
47       NodeList nlName;
48       String s = "";
49       CompanyServices services;
50       ByteArrayInputStream stream;
51       String xml;
52       XMLDocument xmlDoc = null;
53   
54       try {
55         home = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
56         services = home.create();
57         xml = services.getCompanies();
58         stream = new ByteArrayInputStream(xml.getBytes());
59         docParser.setValidationMode(false);
60         docParser.parse(stream);
61         xmlDoc = docParser.getDocument();
62         nlId = xmlDoc.selectNodes("/CompaniesList/Company/id/text()");
63         nlName = xmlDoc.selectNodes("/CompaniesList/Company/name/text()");
64         nlId.item(0).getNodeName();
65   
66         for(int i = 0; i < nlId.getLength(); i++) {
67           Id = StringFormat.toSafeJavaString(nlId.item(i).getNodeValue());
68           if(Id == null) {
69             Id = "";
70           }
71           name = StringFormat.toSafeHTMLString(nlName.item(i).getNodeValue());
72           if(name == null) {
73             name = "";
74           }
75           s += "<option value=\"" + Id + "\">" + name + "</option>";
76         }
77       }
78       catch(Exception e) {}
79       return s;
80     }
81   
82   
83     public void setController(String controller) {
84       this.controller = controller;
85     }
86   
87   
88     public void setData(String data) throws XMLParseException, XSLException, SAXException, IOException {
89       DOMParser docParser = new DOMParser();
90       ByteArrayInputStream stream;
91   
92       stream = new ByteArrayInputStream(data.getBytes());
93       docParser.setValidationMode(false);
94       docParser.parse(stream);
95       this.data = docParser.getDocument();
96     }
97   }
98   
99