1 package com.instantbank.collections.security.web;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.Serializable;
6 import java.util.Vector;
7 import javax.naming.Name;
8 import oracle.xml.parser.v2.DOMParser;
9 import oracle.xml.parser.v2.XMLDocument;
10 import oracle.xml.parser.v2.XMLNode;
11 import oracle.xml.parser.v2.XMLParseException;
12 import oracle.xml.parser.v2.XSLException;
13 import org.w3c.dom.Element;
14 import org.w3c.dom.NodeList;
15 import org.xml.sax.SAXException;
16 import com.instantbank.collections.util.StringFormat;
17
18 public class UserGroupTransformer
19 implements Serializable {
20
21 private Vector id;
22 private Vector changedBy;
23 private String ChangedBy;
24 private Vector changedDate;
25 private String ChangedDate;
26 private String currProfileId;
27 private String groupId;
28 private int Grpindex = 0;
29 private Vector level;
30 private Vector name;
31 private String Name;
32 private int nlLength;
33 private NodeList nlParents;
34 private String ParCode;
35 private String ParId;
36 private int Parindex = 0;
37 private String ParName;
38 private String ParprofileId;
39 private Vector Pid;
40 private String prData;
41 private String profileId;
42 private Vector Profileid;
43 private String typeSel;
44 private XMLDocument xmlGroup;
45 private XMLDocument xmlGroups;
46
47
48 public String getLastMaintainedBy() {
49 return "ChangeBy.value = GroupsArray[" + Grpindex + "].groupChgby";
50 }
51
52
53 public String getLastMaintainedDate() {
54 return "LastChanged.value = GroupsArray[" + Grpindex + "].groupChgdat";
55 }
56
57
58 public String getName(String Selection, String groupChild) {
59
60 String Asignament = null;
61 String Body = null;
62 String elementId = new String();
63 String elementLevel = new String();
64 String elementName = new String();
65 String elementPid = new String();
66 String elementPrfid = new String();
67 String elementChgBy = new String();
68 String elementChgDat = new String();
69 char Ch = '"';
70 String Head = null;
71 int j = 0;
72 int l = 0;
73
74 typeSel = Selection;
75 l = id.size() + 1;
76 Parindex = 0;
77 Grpindex = 0;
78 Head = "numberOfGroups = " + l + "; \n";
79 Body = "GroupsArray[0] = new Group(" + Ch + Ch + "," + Ch + Ch + "," + Ch + Ch + "," + Ch + Ch + "," + Ch + Ch + "," + Ch + Ch + "," + Ch + Ch + ");\n";
80 currProfileId = "0";
81 for(int i = 0; i < id.size(); i++) {
82 elementId = StringFormat.toSafeJavaString((String)id.elementAt(i));
83 elementName = StringFormat.toSafeJavaString((String)name.elementAt(i));
84 elementLevel = StringFormat.toSafeJavaString((String)level.elementAt(i));
85 elementPid = StringFormat.toSafeJavaString((String)Pid.elementAt(i));
86 elementPrfid = StringFormat.toSafeJavaString((String)Profileid.elementAt(i));
87 elementChgBy = StringFormat.toSafeJavaString((String)changedBy.elementAt(i));
88 elementChgDat = StringFormat.toSafeJavaString((String)changedDate.elementAt(i));
89 j = i + 1;
90 if((elementId.equals(groupId)) && (Parindex == 0)) {
91 if(typeSel.equals("2")) {
92 Grpindex = j;
93 Parindex = 0;
94 currProfileId = elementPrfid;
95 }
96 else {
97 Parindex = j;
98 Grpindex = 0;
99 }
100 }
101 if((elementId.equals(groupChild)) && (Grpindex == 0)) {
102 if(typeSel.equals("3")) {
103 Grpindex = j;
104 }
105 }
106 Body = Body +
107 "GroupsArray[" + j + "] = new Group(" + Ch + elementId + Ch +
108 "," + Ch + elementName + Ch + "," + Ch + elementPid + Ch + "," + Ch + elementPrfid + Ch +
109 "," + Ch + TrasData(elementChgBy) + Ch + "," + Ch + TrasData(elementChgDat) + Ch + "," + Ch + elementLevel + Ch + ");\n";
110 }
111 return (Head + Body);
112 }
113
114
115 public String getRoleProfile() {
116 return currProfileId;
117 }
118
119
120 public String getSelected() {
121 String Foot = null;
122
123 Foot = "listParentGroup[" + Parindex + "].selected=true \n" +
124 "listGroupName[" + Grpindex + "].selected=true\n" +
125 "GroupSelected=" + Grpindex;
126 return Foot;
127 }
128
129
130 public XMLDocument parseInfo(String data) throws XMLParseException, XSLException, SAXException, IOException {
131 DOMParser docParser = new DOMParser();
132 ByteArrayInputStream stream;
133 XMLDocument xmlDoc;
134
135 xmlDoc = null;
136 prData = prData + data;
137 stream = new ByteArrayInputStream(data.getBytes());
138 docParser.setValidationMode(false);
139 docParser.parse(stream);
140 xmlDoc = docParser.getDocument();
141 return xmlDoc;
142 }
143
144
145 public void setChildren(XMLNode Parent, String ParentId, int hierarchy) throws XSLException {
146 NodeList nlChild;
147 NodeList nlChildren;
148 int nlChildLen;
149 XMLNode ChildNode;
150 String ParId;
151
152 nlChildren = Parent.selectNodes("./ChildGroups/Group");
153 nlChildLen = nlChildren.getLength();
154 ParId = new String();
155 hierarchy = hierarchy + 1;
156 for(int j = 0; j < nlChildLen; j++) {
157 ChildNode = (XMLNode)nlChildren.item(j);
158 ParId = ChildNode.valueOf("./id");
159 id.addElement(ParId);
160 name.addElement(ChildNode.valueOf("./name"));
161 level.addElement((new Integer(hierarchy)).toString());
162 Pid.addElement(ParentId);
163 Profileid.addElement(ChildNode.valueOf("./profileid"));
164 changedBy.addElement(ChildNode.valueOf("./changedby"));
165 changedDate.addElement(ChildNode.valueOf("./changeddate"));
166 nlChild = ChildNode.selectNodes("./ChildGroups");
167 if(nlChild.getLength() > 0) {
168 setChildren(ChildNode, ParId, hierarchy);
169 }
170 }
171 }
172
173
174 public void setData(String data) throws XMLParseException, XSLException, SAXException, IOException {
175 xmlGroup = parseInfo(data);
176 groupId = xmlGroup.valueOf("/GroupList/Group/id");
177 Name = xmlGroup.valueOf("/GroupList/Group/name");
178 profileId = xmlGroup.valueOf("/GroupList/Group/profileid");
179 ChangedBy = xmlGroup.valueOf("/GroupList/Group/changedby");
180 ChangedDate = xmlGroup.valueOf("/GroupList/Group/changeddate");
181 }
182
183
184 public void setGroups(String data) throws XMLParseException, XSLException, SAXException, IOException {
185 NodeList nlChild;
186 XMLNode node;
187 XMLNode nodeChild;
188 Element ParElement;
189
190 xmlGroups = parseInfo(data);
191 ParElement = xmlGroups.getDocumentElement();
192 nlParents = ParElement.getChildNodes();
193 nlLength = nlParents.getLength();
194 ParId = new String();
195 id = new Vector();
196 name = new Vector();
197 level = new Vector();
198 Pid = new Vector();
199 Profileid = new Vector();
200 changedBy = new Vector();
201 changedDate = new Vector();
202 for(int i = 0; i < nlLength; i++) {
203 node = (XMLNode)nlParents.item(i);
204 ParId = node.valueOf("./id");
205 id.addElement(ParId);
206 name.addElement(node.valueOf("./name"));
207 level.addElement((new Integer(0)).toString());
208 Pid.addElement("");
209 Profileid.addElement(node.valueOf("./profileid"));
210 changedBy.addElement(node.valueOf("./changedby"));
211 changedDate.addElement(node.valueOf("./changeddate"));
212 nlChild = node.selectNodes("./ChildGroups");
213 if(nlChild.getLength() > 0) {
214 setChildren(node, ParId, 0);
215 }
216 }
217 }
218
219
220 public String TrasData(String in) {
221 String out = new String();
222
223 if(in.equals("_")) {
224 out = "";
225 }
226 else {
227 out = in;
228 }
229 return out;
230 }
231 }
232