1 package com.instantbank.collections.collectionsActivities.web; 2 3 import javax.servlet.http.HttpSession; 4 import java.io.ByteArrayInputStream; 5 import java.io.Serializable; 6 import oracle.xml.parser.v2.DOMParser; 7 import oracle.xml.parser.v2.XMLDocument; 8 import org.w3c.dom.NodeList; 9 import com.instantbank.collections.collectionsActivities.ejb.ActionResultServices; 10 import com.instantbank.collections.collectionsActivities.ejb.ActionResultServicesHome; 11 import com.instantbank.collections.commonQueuing.ejb.QueueServices; 12 import com.instantbank.collections.commonQueuing.ejb.QueueServicesHome; 13 import com.instantbank.collections.letters.ejb.LetterServices; 14 import com.instantbank.collections.letters.ejb.LetterServicesHome; 15 import com.instantbank.collections.util.InstantbankException; 16 import com.instantbank.collections.util.ServiceLocator; 17 import com.instantbank.collections.util.StringFormat; 18 import com.instantbank.collections.util.XMLUtils; 19 20 public class ResultMaintenanceTransformer 21 implements Serializable { 22 private HttpSession gblSession; 23 private XMLDocument resultList; 24 private XMLDocument dataDoc; 25 26 27 public String getAttribute(String name) throws InstantbankException { 28 String strAtt = new String(""); 29 try { 30 strAtt = dataDoc.valueOf("Result/" + name); 31 } 32 catch(Exception e) {} 33 return strAtt; 34 } 35 36 37 public void setSession(HttpSession session) { 38 gblSession = session; 39 } 40 41 42 public void setData(String data) throws InstantbankException { 43 ActionResultServicesHome home; 44 ActionResultServices services; 45 ByteArrayInputStream stream; 46 DOMParser docParser = new DOMParser(); 47 String xml; 48 String strResultsList; 49 Long companyId; 50 51 try { 52 xml = XMLUtils.xmlHeader() + data; 53 dataDoc = null; 54 stream = new ByteArrayInputStream(xml.getBytes()); 55 docParser.setValidationMode(false); 56 docParser.parse(stream); 57 dataDoc = docParser.getDocument(); 58 59 home = (ActionResultServicesHome)ServiceLocator.instance().createEJB("ActionResultServicesHome", ActionResultServicesHome.class, false); 60 services = home.create(); 61 companyId = (Long)gblSession.getAttribute("companyId"); 62 strResultsList = services.getResultsList(companyId); 63 resultList = null; 64 stream = new ByteArrayInputStream(strResultsList.getBytes()); 65 docParser.setValidationMode(false); 66 docParser.parse(stream); 67 resultList = docParser.getDocument(); 68 } 69 catch(Exception e) { 70 } 71 } 72 73 74 public String getLettersOptions() throws InstantbankException { 75 LetterServicesHome home; 76 LetterServices services; 77 ByteArrayInputStream stream; 78 DOMParser docParser = new DOMParser(); 79 String xml; 80 String s = new String(""); 81 ; 82 Long companyId; 83 XMLDocument LetterDoc; 84 NodeList nlName; 85 NodeList nlId; 86 87 try { 88 companyId = (Long)gblSession.getAttribute("companyId"); 89 home = (LetterServicesHome)ServiceLocator.instance().createEJB("LetterServicesHome", LetterServicesHome.class, false); 90 services = home.create(); 91 xml = services.getLetters(companyId); 92 93 LetterDoc = null; 94 stream = new ByteArrayInputStream(xml.getBytes()); 95 docParser.setValidationMode(false); 96 docParser.parse(stream); 97 LetterDoc = docParser.getDocument(); 98 99 s = ""; 100 nlName = LetterDoc.selectNodes("/Letters/Letter/name/text()"); 101 nlId = LetterDoc.selectNodes("/Letters/Letter/id/text()"); 102 for(int i = 0; i < nlName.getLength(); i++) { 103 s += "<Option value=\"" + nlId.item(i).getNodeValue() + "\">" + StringFormat.toSafeHTMLString(nlName.item(i).getNodeValue()) + "</Option>"; 104 } 105 } 106 catch(Exception e) {} 107 return s; 108 } 109 110 111 public String getQueuesOptions() throws InstantbankException { 112 QueueServicesHome home; 113 QueueServices services; 114 ByteArrayInputStream stream; 115 DOMParser docParser = new DOMParser(); 116 String xml; 117 String s = new String(""); 118 ; 119 Long companyId; 120 XMLDocument queueDoc; 121 NodeList nlName; 122 NodeList nlId; 123 NodeList nlCategory; 124 125 try { 126 companyId = (Long)gblSession.getAttribute("companyId"); 127 home = (QueueServicesHome)ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, false); 128 services = home.create(); 129 xml = services.getQueues(companyId); 130 131 queueDoc = null; 132 stream = new ByteArrayInputStream(xml.getBytes()); 133 docParser.setValidationMode(false); 134 docParser.parse(stream); 135 queueDoc = docParser.getDocument(); 136 137 s = ""; 138 nlName = queueDoc.selectNodes("/Queues/Queue/name/text()"); 139 nlId = queueDoc.selectNodes("/Queues/Queue/id/text()"); 140 nlCategory = queueDoc.selectNodes("/Queues/Queue/category/text()"); 141 s = "numberOfQueues = " + (nlName.getLength() + 1) + "; \n"; 142 s += "queuesArray[0] = new Queue('', 'NO DEFAULT QUEUE', ''); \n"; 143 for(int i = 0; i < nlName.getLength(); i++) { 144 s += "queuesArray[" + (i + 1) + "] = new Queue(" + nlId.item(i).getNodeValue() + ", '" + 145 nlName.item(i).getNodeValue() + "', '" + nlCategory.item(i).getNodeValue() + "');\n"; 146 } 147 } 148 catch(Exception e) {} 149 return s; 150 } 151 152 153 public String getResultCodeOptions() throws InstantbankException { 154 NodeList nlCode; 155 NodeList nlId; 156 String Code = new String(""); 157 String Id = new String(""); 158 String s = new String(""); 159 String ArrOpt[][]; 160 try { 161 s = ""; 162 nlCode = resultList.selectNodes("/Results/Result/code/text()"); 163 nlId = resultList.selectNodes("/Results/Result/id/text()"); 164 ArrOpt = new String[2][nlCode.getLength()]; 165 166 for(int i = 0; i < nlCode.getLength(); i++) { 167 ArrOpt[0][i] = nlId.item(i).getNodeValue(); 168 ArrOpt[1][i] = nlCode.item(i).getNodeValue(); 169 } 170 171 for(int j = 0; j < nlCode.getLength(); j++) { 172 for(int i = j + 1; i < nlCode.getLength(); i++) { 173 if(ArrOpt[1][i].compareTo(ArrOpt[1][j]) < 0) { 174 String t = ArrOpt[1][j]; 175 ArrOpt[1][j] = ArrOpt[1][i]; 176 ArrOpt[1][i] = t; 177 String t1 = ArrOpt[0][j]; 178 ArrOpt[0][j] = ArrOpt[0][i]; 179 ArrOpt[0][i] = t1; 180 } 181 } 182 } 183 184 for(int i = 0; i < nlCode.getLength(); i++) { 185 Id = ArrOpt[0][i]; 186 Code = ArrOpt[1][i]; 187 s += "<option value=\"" + Id + "\">" + StringFormat.toSafeHTMLString(Code) + "</option>"; 188 } 189 190 } 191 catch(Exception e) {} 192 return s; 193 } 194 195 196 public String getResultDescriptionOptions() throws InstantbankException { 197 NodeList nlDescription; 198 NodeList nlId; 199 String Description = new String(""); 200 String Id = new String(""); 201 String s = new String(""); 202 String ArrOpt[][]; 203 try { 204 s = ""; 205 nlDescription = resultList.selectNodes("/Results/Result/description/text()"); 206 nlId = resultList.selectNodes("/Results/Result/id/text()"); 207 ArrOpt = new String[2][nlDescription.getLength()]; 208 209 for(int i = 0; i < nlDescription.getLength(); i++) { 210 ArrOpt[0][i] = nlId.item(i).getNodeValue(); 211 ArrOpt[1][i] = nlDescription.item(i).getNodeValue(); 212 } 213 214 for(int j = 0; j < nlDescription.getLength(); j++) { 215 for(int i = j + 1; i < nlDescription.getLength(); i++) { 216 if(ArrOpt[1][i].compareTo(ArrOpt[1][j]) < 0) { 217 String t = ArrOpt[1][j]; 218 ArrOpt[1][j] = ArrOpt[1][i]; 219 ArrOpt[1][i] = t; 220 String t1 = ArrOpt[0][j]; 221 ArrOpt[0][j] = ArrOpt[0][i]; 222 ArrOpt[0][i] = t1; 223 } 224 } 225 } 226 227 for(int i = 0; i < nlDescription.getLength(); i++) { 228 Id = ArrOpt[0][i]; 229 Description = ArrOpt[1][i]; 230 s += "<option value=\"" + Id + "\">" + StringFormat.toSafeHTMLString(Description) + "</option>"; 231 } 232 233 } 234 catch(Exception e) {} 235 return s; 236 } 237 } 238 239