1 package com.instantbank.collections.documents.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.commonQueuing.web.FieldsTransformer;
12 import com.instantbank.collections.util.InstantbankException;
13
14 public class DocumentTransformer {
15 long companyId;
16 XMLDocument doc;
17 FieldsTransformer ft = null;
18 String objectType = "";
19
20
21 public DocumentTransformer(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("RulesList/Rule/description");
30 }
31
32
33 public String getFieldsArray() {
34 return ft.getFieldsArray();
35 }
36
37
38 public String getId() {
39 return getValueOf("Document/DocumentFields/id");
40 }
41
42
43 public String getLastChangedBy() {
44 return getValueOf("Document/DocumentFields/lastchangedby");
45 }
46
47
48 public String getLastChangedDate() {
49 return getValueOf("Document/DocumentFields/lastchangeddate");
50 }
51
52
53 public String getLocationId() {
54 return getValueOf("CompanyLocationsList/CompanyLocations/id");
55 }
56
57
58 public String getName() {
59 return getValueOf("Document/DocumentFields/name");
60 }
61
62
63 public String getMenusArray() {
64 return ft.getMenus();
65 }
66
67
68 public String getPriority() {
69 return getValueOf("Document/DocumentFields/priority");
70 }
71
72
73 public String getQueueTypesOptions() {
74 return ft.getQueueTypesOptions();
75 }
76
77
78 public String getRulesArray() throws InstantbankException {
79 XMLNode node;
80 NodeList nodeList;
81 PrintWriter pw;
82 Element root;
83 String rules;
84 StringWriter sw;
85 String varArrays = "";
86
87 try {
88 root = doc.getDocumentElement();
89 sw = new StringWriter();
90 pw = new PrintWriter(sw);
91 doc.print(pw);
92 rules = sw.toString();
93 varArrays += ft.getRulesArray(rules);
94 }
95 catch(Exception e) {
96 varArrays += "/* Exception: " + e.getClass().getName() + " " + e.getMessage() + " */";
97 }
98 return varArrays;
99 }
100
101
102 private String getValueOf(String nodeName) {
103 try {
104 return doc.valueOf(nodeName);
105 }
106 catch(Exception e) {
107 return "";
108 }
109 }
110
111
112 public void setData(String xml) {
113 DOMParser docParser = new DOMParser();
114 ByteArrayInputStream stream = null;
115
116 try {
117 stream = new ByteArrayInputStream(xml.getBytes());
118 docParser.setValidationMode(false);
119 docParser.parse(stream);
120 doc = docParser.getDocument();
121 }
122 catch(Exception e) {
123 }
124 }
125 }
126
127