1    package com.instantbank.collections.collectionsActivities.web;
2    
3    import java.io.ByteArrayInputStream;
4    import java.util.Hashtable;
5    import oracle.xml.parser.v2.DOMParser;
6    import oracle.xml.parser.v2.XMLDocument;
7    import oracle.xml.parser.v2.XMLNode;
8    import org.w3c.dom.Element;
9    import org.w3c.dom.NodeList;
10   import com.instantbank.collections.collectionsActivities.ejb.ActionResultServices;
11   import com.instantbank.collections.collectionsActivities.ejb.ActionResultServicesHome;
12   import com.instantbank.collections.util.InstantbankException;
13   import com.instantbank.collections.util.ServiceLocator;
14   
15   /**
16    * A Bean class.
17    * <P>
18    *
19    * @author Indudata
20    */
21   public class ActionsResultsByUserBean {
22   
23     private String actionsResultsXmlString;
24     private XMLDocument actionsResultsXml;
25   
26   
27     /**
28      * Constructor
29      *
30      * @param userId Description of the Parameter
31      * @param companyId Description of the Parameter
32      * @throws InstantbankException Description of the Exception
33      */
34     public ActionsResultsByUserBean(Long userId, Long companyId) throws InstantbankException {
35       DOMParser docParser = new DOMParser();
36       ByteArrayInputStream stream = null;
37       try {
38         ActionResultServicesHome home = (ActionResultServicesHome)
39           ServiceLocator.instance().createEJB("ActionResultServicesHome", ActionResultServicesHome.class, false);
40         ActionResultServices actionResultServices = home.create();
41         actionsResultsXmlString = actionResultServices.getListByUser(userId, companyId);
42         stream = new ByteArrayInputStream(actionsResultsXmlString.getBytes());
43         docParser.setValidationMode(false);
44         docParser.parse(stream);
45         actionsResultsXml = docParser.getDocument();
46       }
47       catch(Exception e) {}
48     }
49   
50   
51     public String getActionOptionList() throws InstantbankException {
52       String actionsSelect = "<select class='inputForm' name='ddActions' size='1' style='width:198' onChange='changeAction(this.value)'><option value></option>";
53       XMLNode node;
54       NodeList nodeList;
55       Element root;
56       Hashtable ht = new Hashtable();
57       root = actionsResultsXml.getDocumentElement();
58       String htObject;
59       try {
60         nodeList = root.getChildNodes();
61         for(int i = 0; i < nodeList.getLength(); i++) {
62           node = (XMLNode)nodeList.item(i);
63           htObject = (String)ht.get(node.valueOf("./act_id"));
64           if(htObject == null) {
65             actionsSelect += "<option value='" + node.valueOf("./act_id") + "'>" + node.valueOf("./act_code") + " - " + node.valueOf("./act_description") + "</option>";
66             ht.put(node.valueOf("./act_id"), node.valueOf("./act_id"));
67           }
68         }
69         actionsSelect += "</select>";
70       }
71       catch(Exception e) {}
72       return actionsSelect;
73     }
74   
75   
76     public String getResultVector() throws InstantbankException {
77       String resultVectorHtml = "var actionsResultLinks = new Array();\nvar results = new Array();\n";
78       XMLNode node;
79       NodeList nodeList;
80       Element root;
81       Hashtable ht = new Hashtable();
82       Hashtable ht2 = new Hashtable();
83       root = actionsResultsXml.getDocumentElement();
84       Integer htObject;
85       String htObject2;
86       try {
87         nodeList = root.getChildNodes();
88         for(int i = 0; i < nodeList.getLength(); i++) {
89           node = (XMLNode)nodeList.item(i);
90           htObject = (Integer)ht.get(node.valueOf("./act_id"));
91           if(htObject == null) {
92             resultVectorHtml += "actionsResultLinks[" + node.valueOf("./act_id") + "]=new Array();actionsResultLinks[" + node.valueOf("./act_id") + "][1]='" + node.valueOf("./res_id") + "';\n";
93             htObject2 = (String)ht2.get(node.valueOf("./res_id"));
94             if(htObject2 == null) {
95               resultVectorHtml += "results[" + node.valueOf("./res_id") + "]=new Array();\n";  //act_code
96               resultVectorHtml += "results[" + node.valueOf("./res_id") + "][1]='" + node.valueOf("./res_code") + "';results[" + node.valueOf("./res_id") + "][2]='" + node.valueOf("./res_description") + "';\n";
97               ht2.put(node.valueOf("./res_id"), node.valueOf("./res_id"));
98             }
99             ht.put(node.valueOf("./act_id"), new Integer(1));
100          }
101          else {
102            resultVectorHtml += "actionsResultLinks[" + node.valueOf("./act_id") + "][" + new Integer(((Integer)ht.get(node.valueOf("./act_id"))).intValue() + 1) + "]='" + node.valueOf("./res_id") + "';\n";
103            htObject2 = (String)ht2.get(node.valueOf("./res_id"));
104            if(htObject2 == null) {
105              resultVectorHtml += "results[" + node.valueOf("./res_id") + "]=new Array();\n";
106              resultVectorHtml += "results[" + node.valueOf("./res_id") + "][1]='" + node.valueOf("./res_code") + "';results[" + node.valueOf("./res_id") + "][2]='" + node.valueOf("./res_description") + "';\n";
107              ht2.put(node.valueOf("./res_id"), node.valueOf("./res_id"));
108            }
109            ht.put(node.valueOf("./act_id"), new Integer(((Integer)ht.get(node.valueOf("./act_id"))).intValue() + 1));
110          }
111        }
112      }
113      catch(Exception e) {}
114      return resultVectorHtml;
115    }
116  }
117  
118