1    package com.instantbank.collections.collectionsActivities.web;
2    
3    import java.io.ByteArrayInputStream;
4    import java.io.PrintWriter;
5    import java.io.StringWriter;
6    import oracle.xml.parser.v2.DOMParser;
7    import oracle.xml.parser.v2.XMLDocument;
8    import org.w3c.dom.Node;
9    import com.instantbank.collections.util.InstantbankException;
10   import com.instantbank.collections.util.StringFormat;
11   
12   /**
13    * A Bean class.
14    * <P>
15    *
16    * @author Indudata
17    */
18   public class PromiseHistoryTransformer {
19     private String controller;
20     private XMLDocument data;
21   
22   
23     /**
24      * Constructor
25      */
26     public PromiseHistoryTransformer() { }
27   
28   
29     public String getHistoryArray() throws InstantbankException {
30       String Action = null;
31       String Amount = null;
32       String arrayLoad = "";
33       String Comments = null;
34       String DueDate = null;
35       String NextReviewDate = null;
36       String Operator = "";
37       String PostingDate = null;
38       int promiseNumber = 0;
39       String Result = null;
40       String Status = null;
41   
42       try {
43         StringWriter sw = new StringWriter();
44         PrintWriter pw = new PrintWriter(sw);
45         data.print(pw);
46         if(data.getDocumentElement().hasChildNodes()) {
47           promiseNumber = data.selectNodes("/PromiseHistory/Promise").getLength();
48           for(int i = 0; i < promiseNumber; i++) {
49             Node promise = data.selectNodes("/PromiseHistory/Promise").item(i);
50             for(int j = 0; j < promise.getChildNodes().getLength(); j++) {
51               String NodeName = promise.getChildNodes().item(j).getNodeName();
52               if(NodeName.equals("postingdate")) {
53                 PostingDate = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
54               }
55               else if(NodeName.equals("comments")) {
56                 if(promise.getChildNodes().item(j).hasChildNodes()) {
57                   Comments = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
58                 }
59               }
60               else if(NodeName.equals("action")) {
61                 Action = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
62               }
63               else if(NodeName.equals("result")) {
64                 Result = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
65               }
66               else if(NodeName.equals("amount")) {
67                 Amount = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
68               }
69               else if(NodeName.equals("duedate")) {
70                 DueDate = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
71               }
72               else if(NodeName.equals("nextreviewdate")) {
73                 NextReviewDate = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
74               }
75               else if(NodeName.equals("status")) {
76                 Status = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
77               }
78               else if(NodeName.equals("operator")) {
79                 Operator = promise.getChildNodes().item(j).getFirstChild().getNodeValue();
80               }
81             }
82             arrayLoad += "promises[" + i + "]=new Promise(\"" + PostingDate + "\",\"";
83             arrayLoad += Operator + "\",\"" + StringFormat.toSafeJavaString(Action) + "\",\"" + StringFormat.toSafeJavaString(Result) + "\",\"" + Amount + "\",\"";
84             arrayLoad += DueDate + "\",\"" + NextReviewDate + "\",\"" + Status + "\",\"" + StringFormat.toSafeJavaString(Comments) + "\");\n";
85             Operator = "";
86             Status = "";
87             NextReviewDate = "";
88             DueDate = "";
89             Amount = "";
90             Result = "";
91             Action = "";
92             Comments = "";
93             PostingDate = "";
94           }
95         }
96         arrayLoad += "promiseNumber = " + promiseNumber + ";";
97       }
98       catch(Exception e) {}
99       return arrayLoad;
100    }
101  
102  
103    public void setController(String controller) throws InstantbankException {
104      try {
105        this.controller = controller;
106      }
107      catch(Exception e) {}
108    }
109  
110  
111    public void setData(String data) throws InstantbankException {
112      DOMParser docParser = new DOMParser();
113      ByteArrayInputStream stream;
114      try {
115        stream = new ByteArrayInputStream(data.getBytes());
116        docParser.setValidationMode(false);
117        docParser.parse(stream);
118        this.data = docParser.getDocument();
119      }
120      catch(Exception e) {}
121    }
122  
123  }
124  
125