1    package com.instantbank.collections.commonQueuing.web;
2    
3    import java.io.ByteArrayInputStream;
4    import java.io.PrintWriter;
5    import java.io.StringWriter;
6    import java.util.Hashtable;
7    import oracle.xml.parser.v2.DOMParser;
8    import oracle.xml.parser.v2.XMLDocument;
9    import oracle.xml.parser.v2.XMLNode;
10   import org.w3c.dom.Element;
11   import org.w3c.dom.NodeList;
12   import com.instantbank.collections.commonQueuing.ejb.QueueServices;
13   import com.instantbank.collections.commonQueuing.ejb.QueueServicesHome;
14   import com.instantbank.collections.companyInfo.ejb.CompanyServices;
15   import com.instantbank.collections.companyInfo.ejb.CompanyServicesHome;
16   import com.instantbank.collections.util.InstantbankException;
17   import com.instantbank.collections.util.ServiceLocator;
18   import com.instantbank.collections.util.XMLUtils;
19   
20   public class DownloadTransformer {
21     long companyId;
22     XMLDocument doc;
23     FieldsTransformer ft = null;
24     String objectType = "";
25   
26   
27   
28     public DownloadTransformer(Long companyId, String objectType) throws InstantbankException {
29       this.objectType = objectType;
30       this.companyId = companyId.longValue();
31       this.ft = new FieldsTransformer(companyId, objectType);
32     }
33   
34   
35     public String getAlternateLocation() {
36       return getValueOf("Download/Distribution/Locations/secondaryid");
37     }
38   
39   
40     public String getCompanyLocation(Long companyId) {
41       String companyLocation = "var cmpLocationVector = new Array();\n";
42       DOMParser docParser = new DOMParser();
43       Hashtable ht = new Hashtable();
44       String htObject;
45       XMLDocument inxml;
46       XMLNode node;
47       NodeList nodeList;
48       Element root;
49       ByteArrayInputStream stream = null;
50       String xmlString = "";
51   
52       try {
53         CompanyServicesHome home = (CompanyServicesHome)ServiceLocator.instance().createEJB("CompanyServicesHome", CompanyServicesHome.class, false);
54         CompanyServices companycervices = home.create();
55         xmlString = companycervices.getCompanyLocations(companyId);
56         stream = new ByteArrayInputStream(xmlString.getBytes());
57         docParser.setValidationMode(false);
58         docParser.parse(stream);
59         inxml = docParser.getDocument();
60         root = inxml.getDocumentElement();
61         nodeList = root.getChildNodes();
62         for(int i = 0; i < nodeList.getLength(); i++) {
63           node = (XMLNode)nodeList.item(i);
64           htObject = (String)ht.get(node.valueOf("./id"));
65           if(htObject == null) {
66             companyLocation += "cmpLocationVector[" + i + "]= new Array();\n";
67             companyLocation += "cmpLocationVector[" + i + "][0]='" + node.valueOf("./id") + "';\n";
68             companyLocation += "cmpLocationVector[" + i + "][1]='" + node.valueOf("./name") + "';\n";
69           }
70         }
71   
72       }
73       catch(Exception e) {
74         companyLocation += "/* Error: " + e.getClass().getName() + " " + e.getMessage() + " */";
75       }
76       return companyLocation;
77     }
78   
79   
80     public String getDescription() {
81       return getValueOf("Download/DownloadFields/description");
82     }
83   
84   
85     public String getFieldsArray() {
86       return ft.getFieldsArray();
87     }
88   
89   
90     public String getFrequency() {
91       return getValueOf("Download/DownloadFields/frequency");
92     }
93   //*CR2002062600.0 - add ach drafting to collections*//
94   
95     public String getFileType() {
96       return getValueOf("Download/DownloadFields/filetype");
97     }
98   //*CR2002062600.0 - add ach drafting to collections*//
99   
100    public String getFtpType() {
101      return getValueOf("Download/DownloadFields/ftptype");
102    }
103  //*CR2002062600.0 - add ach drafting to collections*//
104  
105    public String getAchAccount() {
106      return getValueOf("Download/DownloadFields/achaccount");
107    }
108  
109  
110    public String getId() {
111      return getValueOf("Download/DownloadFields/id");
112    }
113  
114  
115    public String getLastChangedBy() {
116      return getValueOf("Download/DownloadFields/lastchangedby");
117    }
118  
119  
120    public String getLastChangedDate() {
121      return getValueOf("Download/DownloadFields/lastchangeddate");
122    }
123  
124  
125    public String getName() {
126      return getValueOf("Download/DownloadFields/name");
127    }
128  
129  
130    public String getMenusArray() {
131      return ft.getMenus();
132    }
133  
134  
135    public String getPrimaryLocation() {
136      return getValueOf("Download/Distribution/Locations/primaryid");
137    }
138  
139  
140    public String getQueueType() {
141      return getValueOf("Download/DownloadFields/queuetype");
142    }
143  
144  
145    public String getQueueTypesOptions() {
146      DOMParser docParser = new DOMParser();
147      XMLDocument inxml;
148      XMLNode node;
149      NodeList nodeList;
150      String queueSelect = "";
151      Element root;
152      ByteArrayInputStream stream = null;
153      String xmlString;
154      try {
155        QueueServicesHome home = (QueueServicesHome)ServiceLocator.instance().createEJB("QueueServicesHome", QueueServicesHome.class, false);
156        QueueServices qs = home.create();
157        xmlString = qs.getDownloadQueueTypes(new Long(companyId), objectType);
158        stream = new ByteArrayInputStream(xmlString.getBytes());
159        docParser.setValidationMode(false);
160        docParser.parse(stream);
161        inxml = docParser.getDocument();
162        root = inxml.getDocumentElement();
163        nodeList = root.getChildNodes();
164        for(int i = 0; i < nodeList.getLength(); i++) {
165          node = (XMLNode)nodeList.item(i);
166          queueSelect += node.valueOf("./id");
167        }
168      }
169      catch(Exception e) {
170        queueSelect += "<-- " + e.getClass().getName() + " " + e.getMessage() + " -->";
171      }
172      return queueSelect;
173    }
174  
175  
176    public String getRulesArray() throws InstantbankException {
177      XMLNode node;
178      NodeList nodeList;
179      PrintWriter pw;
180      Element root;
181      String rules;
182      StringWriter sw;
183      String varArrays = "";
184  
185      try {
186        root = doc.getDocumentElement();
187        nodeList = root.getChildNodes();
188        for(int i = 0; i < nodeList.getLength(); i++) {
189          node = (XMLNode)nodeList.item(i);
190          if(node.getNodeName().equals("RulesList")) {
191            sw = new StringWriter();
192            pw = new PrintWriter(sw);
193            node.print(pw);
194            rules = XMLUtils.xmlHeader();
195            rules += sw.toString();
196            varArrays += ft.getRulesArray(rules);
197          }
198        }
199      }
200      catch(Exception e) {
201        varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
202      }
203      return varArrays;
204    }
205  
206  
207    public String getSortArray() throws InstantbankException {
208      XMLNode node;
209      NodeList nodeList;
210      PrintWriter pw;
211      Element root;
212      String rules;
213      StringWriter sw;
214      String varArrays = "";
215  
216      try {
217        root = doc.getDocumentElement();
218        nodeList = root.getChildNodes();
219        for(int i = 0; i < nodeList.getLength(); i++) {
220          node = (XMLNode)nodeList.item(i);
221          if(node.getNodeName().equals("SortList")) {
222            sw = new StringWriter();
223            pw = new PrintWriter(sw);
224            node.print(pw);
225            rules = XMLUtils.xmlHeader();
226            rules += sw.toString();
227            varArrays += ft.getSortArray(rules);
228          }
229        }
230      }
231      catch(Exception e) {
232        varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
233      }
234      return varArrays;
235    }
236  
237  
238    public String getSelectedFieldsArray() throws InstantbankException {
239      XMLNode node;
240      NodeList nodeList;
241      PrintWriter pw;
242      Element root;
243      String rules;
244      StringWriter sw;
245      String varArrays = "";
246  
247      try {
248        root = doc.getDocumentElement();
249        nodeList = root.getChildNodes();
250        for(int i = 0; i < nodeList.getLength(); i++) {
251          node = (XMLNode)nodeList.item(i);
252          if(node.getNodeName().equals("FieldsList")) {
253            sw = new StringWriter();
254            pw = new PrintWriter(sw);
255            node.print(pw);
256            rules = XMLUtils.xmlHeader();
257            rules += sw.toString();
258            varArrays += ft.getSelectedFields(rules);
259          }
260        }
261      }
262      catch(Exception e) {
263        varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
264      }
265      return varArrays;
266    }
267  
268  
269    public String getStartDate() {
270      return getValueOf("Download/DownloadFields/startdate");
271    }
272  
273  
274    public String getStatus() {
275      return getValueOf("Download/DownloadFields/status");
276    }
277  
278  
279    private String getValueOf(String nodeName) {
280      try {
281        return doc.valueOf(nodeName);
282      }
283      catch(Exception e) {
284        return "";
285      }
286    }
287  
288  
289    public void setData(String xml) {
290      DOMParser docParser = new DOMParser();
291      ByteArrayInputStream stream = null;
292  
293      try {
294        stream = new ByteArrayInputStream(xml.getBytes());
295        docParser.setValidationMode(false);
296        docParser.parse(stream);
297        doc = docParser.getDocument();
298      }
299      catch(Exception e) {
300      }
301    }
302  
303  
304    private void jbInit() throws Exception { }
305  }
306  
307