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 oracle.xml.parser.v2.DOMParser;
7 import oracle.xml.parser.v2.XMLDocument;
8 import oracle.xml.parser.v2.XMLNode;
9 import org.w3c.dom.Element;
10 import org.w3c.dom.NodeList;
11 import com.instantbank.collections.util.InstantbankException;
12 import com.instantbank.collections.util.XMLUtils;
13
14 public class QueueTransformer {
15 long companyId;
16 XMLDocument doc;
17 FieldsTransformer ft = null;
18 String objectType = "";
19
20
21 public QueueTransformer(Long companyId, String objectType) throws InstantbankException {
22 this.ft = new FieldsTransformer(companyId, objectType);
23 this.objectType = objectType;
24 this.companyId = companyId.longValue();
25 }
26
27
28 public String getDescription() {
29 return getValueOf("Queue/QueueFields/description");
30 }
31
32
33 public String getFieldsArray() {
34 return ft.getFieldsArray();
35 }
36
37
38 public String getGroupsUserArray() {
39 return ft.getGroupsUserArray();
40 }
41
42
43 public String getId() {
44 return getValueOf("Queue/QueueFields/id");
45 }
46
47
48 public String getLastChangedBy() {
49 return getValueOf("Queue/QueueFields/lastchangedby");
50 }
51
52
53 public String getLastChangedDate() {
54 return getValueOf("Queue/QueueFields/lastchangeddate");
55 }
56
57
58 public String getName() {
59 return getValueOf("Queue/QueueFields/name");
60 }
61
62
63 public String getMenusArray() {
64 return ft.getMenus();
65 }
66
67
68 public String getQueueType() {
69 return getValueOf("Queue/QueueFields/type");
70 }
71
72
73 public String getPriority() {
74 return getValueOf("Queue/QueueFields/priority");
75 }
76
77
78 public String getQueueTypesOptions() {
79 return ft.getQueueTypesOptions();
80 }
81
82
83 public String getRulesArray() throws InstantbankException {
84 XMLNode node;
85 NodeList nodeList;
86 PrintWriter pw;
87 Element root;
88 String rules;
89 StringWriter sw;
90 String varArrays = "";
91
92 try {
93 root = doc.getDocumentElement();
94 nodeList = root.getChildNodes();
95 for(int i = 0; i < nodeList.getLength(); i++) {
96 node = (XMLNode)nodeList.item(i);
97 if(node.getNodeName().equals("RulesList")) {
98 sw = new StringWriter();
99 pw = new PrintWriter(sw);
100 node.print(pw);
101 rules = XMLUtils.xmlHeader();
102 rules += sw.toString();
103 varArrays += ft.getRulesArray(rules);
104 }
105 }
106 }
107 catch(Exception e) {
108 varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
109 }
110 return varArrays;
111 }
112
113
114 public String getSortArray() throws InstantbankException {
115 XMLNode node;
116 NodeList nodeList;
117 PrintWriter pw;
118 Element root;
119 String rules;
120 StringWriter sw;
121 String varArrays = "";
122
123 try {
124 root = doc.getDocumentElement();
125 nodeList = root.getChildNodes();
126 for(int i = 0; i < nodeList.getLength(); i++) {
127 node = (XMLNode)nodeList.item(i);
128 if(node.getNodeName().equals("SortList")) {
129 sw = new StringWriter();
130 pw = new PrintWriter(sw);
131 node.print(pw);
132 rules = XMLUtils.xmlHeader();
133 rules += sw.toString();
134 varArrays += ft.getSortArray(rules);
135 }
136 }
137 }
138 catch(Exception e) {
139 varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
140 }
141 return varArrays;
142 }
143
144
145 public String getSelectedUsersArray() throws InstantbankException {
146 XMLNode node;
147 NodeList nodeList;
148 PrintWriter pw;
149 Element root;
150 String rules;
151 StringWriter sw;
152 String varArrays = "";
153
154 try {
155 root = doc.getDocumentElement();
156 nodeList = root.getChildNodes();
157 for(int i = 0; i < nodeList.getLength(); i++) {
158 node = (XMLNode)nodeList.item(i);
159 if(node.getNodeName().equals("DistributionList")) {
160 sw = new StringWriter();
161 pw = new PrintWriter(sw);
162 node.print(pw);
163 rules = XMLUtils.xmlHeader();
164 rules += sw.toString();
165 varArrays += ft.getSelectedUsersArray(rules);
166 }
167 }
168 }
169 catch(Exception e) {
170 varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
171 }
172 return varArrays;
173 }
174
175
176 public String getStartDate() {
177 return getValueOf("Queue/QueueFields/startdate");
178 }
179
180
181 public String getStatus() {
182 return getValueOf("Queue/QueueFields/status");
183 }
184
185
186 private String getValueOf(String nodeName) {
187 try {
188 return doc.valueOf(nodeName);
189 }
190 catch(Exception e) {
191 return "";
192 }
193 }
194
195
196 public void setData(String xml) {
197 DOMParser docParser = new DOMParser();
198 ByteArrayInputStream stream = null;
199
200 try {
201 stream = new ByteArrayInputStream(xml.getBytes());
202 docParser.setValidationMode(false);
203 docParser.parse(stream);
204 doc = docParser.getDocument();
205 }
206 catch(Exception e) {
207 }
208 }
209 }
210
211