1 package com.instantbank.collections.creditInfo.web; 2 3 import java.io.ByteArrayInputStream; 4 import java.io.IOException; 5 import java.io.PrintWriter; 6 import java.io.StringWriter; 7 import oracle.xml.parser.v2.DOMParser; 8 import oracle.xml.parser.v2.XMLDocument; 9 import oracle.xml.parser.v2.XMLParseException; 10 import oracle.xml.parser.v2.XSLException; 11 import org.w3c.dom.Node; 12 import org.xml.sax.SAXException; 13 14 public class TransactionHistoryTransformer { 15 private String controller; 16 private XMLDocument data; 17 18 19 public TransactionHistoryTransformer() { } 20 21 22 public String getHistoryArray() throws Exception { 23 String arrayLoad = ""; 24 String Description = null; 25 String EffectiveDate = null; 26 String EndingBalance = null; 27 String FeesAmount = null; 28 String Id = null; 29 String InterestAmount = null; 30 String OnlineOperator = null; 31 String PrincipalAmount = null; 32 String ProcessingDate = null; 33 String Reversed = null; 34 String Source = null; 35 String TraceNumber = null; 36 int transactionNumber = 0; 37 String Type = null; 38 39 StringWriter sw = new StringWriter(); 40 PrintWriter pw = new PrintWriter(sw); 41 data.print(pw); 42 43 if(data.getDocumentElement().hasChildNodes()) { 44 transactionNumber = data.selectNodes("/TransactionHistory/Transaction").getLength(); 45 try { 46 for(int i = 0; i < transactionNumber; i++) { 47 Node transaction = data.selectNodes("/TransactionHistory/Transaction").item(i); 48 for(int j = 0; j < transaction.getChildNodes().getLength(); j++) { 49 String NodeName = transaction.getChildNodes().item(j).getNodeName(); 50 if(NodeName.equals("id")) { 51 Id = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 52 } 53 else if(NodeName.equals("onlineoperator")) { 54 if(transaction.getChildNodes().item(j).getFirstChild() != null) { 55 OnlineOperator = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 56 } 57 } 58 else if(NodeName.equals("processingdate")) { 59 ProcessingDate = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 60 } 61 else if(NodeName.equals("effectivedate")) { 62 EffectiveDate = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 63 } 64 else if(NodeName.equals("type")) { 65 Type = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 66 } 67 else if(NodeName.equals("reversed")) { 68 Reversed = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 69 } 70 else if(NodeName.equals("principalamount")) { 71 PrincipalAmount = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 72 } 73 else if(NodeName.equals("interestamount")) { 74 InterestAmount = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 75 } 76 else if(NodeName.equals("feesamount")) { 77 FeesAmount = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 78 } 79 else if(NodeName.equals("endingbalance")) { 80 EndingBalance = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 81 } 82 else if(NodeName.equals("source")) { 83 Source = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 84 } 85 else if(NodeName.equals("tracenumber")) { 86 TraceNumber = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 87 } 88 else if(NodeName.equals("description")) { 89 Description = transaction.getChildNodes().item(j).getFirstChild().getNodeValue(); 90 } 91 else { 92 System.out.println("Error determining node name: " + NodeName); 93 } 94 } 95 arrayLoad += "transactions[" + i + "]=new Transaction(\'" + Id + "\',\'" + ProcessingDate + "\',\'"; 96 arrayLoad += EffectiveDate + "\',\'" + Type + "\',\'" + Reversed + "\',\'" + PrincipalAmount + "\',\'"; 97 arrayLoad += InterestAmount + "\',\'" + FeesAmount + "\',\'" + EndingBalance + "\',\'" + Source + "\',\'"; 98 arrayLoad += TraceNumber + "\',\'" + OnlineOperator + "\',\'" + Description + "\');\n"; 99 } 100 } 101 catch(Exception e) { 102 e.printStackTrace(); 103 } 104 } 105 arrayLoad += "transactionNumber = " + transactionNumber + ";"; 106 return arrayLoad; 107 } 108 109 110 public void setController(String controller) { 111 this.controller = controller; 112 } 113 114 115 public void setData(String data) throws XMLParseException, XSLException, SAXException, IOException { 116 DOMParser docParser = new DOMParser(); 117 ByteArrayInputStream stream; 118 119 try { 120 stream = new ByteArrayInputStream(data.getBytes()); 121 docParser.setValidationMode(false); 122 docParser.parse(stream); 123 this.data = docParser.getDocument(); 124 } 125 catch(Exception e) { 126 } 127 } 128 129 } 130 131