1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.edl.impl.components;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.edl.impl.EDLContext;
23 import org.kuali.rice.edl.impl.EDLModelComponent;
24 import org.kuali.rice.edl.impl.RequestParser;
25 import org.kuali.rice.edl.impl.UserAction;
26 import org.w3c.dom.Document;
27 import org.w3c.dom.Element;
28 import org.w3c.dom.NodeList;
29
30 public class RefreshFromLookupComponent implements EDLModelComponent {
31
32 public void updateDOM(Document dom, Element configElement, EDLContext edlContext) {
33 String command = edlContext.getUserAction().getAction();
34 if (UserAction.ACTION_REFRESH_FROM_LOOKUP.equals(command)) {
35 RequestParser requestParser = edlContext.getRequestParser();
36
37 Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
38
39 List<Element> fieldsToDelete = new ArrayList<Element>();
40 NodeList fieldNodes = currentVersion.getElementsByTagName("field");
41
42
43 List<String> requestParameterNames = requestParser.getParameterNames();
44
45 for (int i = 0; i < fieldNodes.getLength(); i++) {
46 Element fieldNode = (Element) fieldNodes.item(i);
47 String fieldName = fieldNode.getAttribute("name");
48 if (requestParameterNames.contains(fieldName)) {
49 fieldsToDelete.add(fieldNode);
50 }
51 }
52
53
54
55 for (Element fieldToDelete : fieldsToDelete) {
56 currentVersion.removeChild(fieldToDelete);
57 }
58 }
59 }
60 }