1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.attribute;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.core.api.config.ConfigurationException;
21 import org.kuali.rice.core.api.uif.RemotableAttributeField;
22 import org.kuali.rice.core.api.uif.RemotableQuickFinder;
23 import org.kuali.rice.kns.lookup.LookupUtils;
24 import org.kuali.rice.kns.web.ui.Field;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26 import org.w3c.dom.NamedNodeMap;
27 import org.w3c.dom.Node;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32
33
34
35
36
37
38
39 public final class XMLAttributeUtils {
40
41 private static final Logger LOG = Logger.getLogger(XMLAttributeUtils.class);
42
43 private XMLAttributeUtils() {
44 throw new UnsupportedOperationException("do not call");
45 }
46
47
48
49
50 public static void establishFieldLookup(Field field, Node lookupNode) {
51 NamedNodeMap quickfinderAttributes = lookupNode.getAttributes();
52 String businessObjectClass = quickfinderAttributes.getNamedItem("dataObjectClass").getNodeValue();
53 field.setQuickFinderClassNameImpl(businessObjectClass);
54 for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) {
55 Map<String, String> fieldConversionsMap = new HashMap<String, String>();
56 Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex);
57 if ("fieldConversions".equals(fieldConversionsChildNode)) {
58 for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) {
59 Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex);
60 if ("fieldConversion".equals(fieldConversionChildNode)) {
61 NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes();
62 String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName").getNodeValue();
63 String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName").getNodeValue();
64 fieldConversionsMap.put(lookupFieldName, localFieldName);
65 }
66 }
67 }
68 field.setFieldConversions(fieldConversionsMap);
69 }
70 }
71
72 public static void establishFieldLookup(RemotableAttributeField.Builder fieldBuilder, Node lookupNode) {
73 NamedNodeMap quickfinderAttributes = lookupNode.getAttributes();
74 Node dataObjectNode = quickfinderAttributes.getNamedItem("dataObjectClass");
75 if (dataObjectNode == null) {
76
77 dataObjectNode = quickfinderAttributes.getNamedItem("businessObjectClass");
78 if (dataObjectNode != null) {
79 LOG.warn("Field is using deprecated 'businessObjectClass' instead of 'dataObjectClass' for lookup definition, field name is: " + fieldBuilder.getName());
80 } else {
81 throw new ConfigurationException("Failed to locate 'dataObjectClass' for lookup definition.");
82 }
83 }
84 String dataObjectClass = dataObjectNode.getNodeValue();
85 String baseLookupUrl = KRADServiceLocatorWeb.getRiceApplicationConfigurationMediationService().getBaseLookupUrl(dataObjectClass);
86 if (StringUtils.isBlank(baseLookupUrl)) {
87
88 baseLookupUrl = LookupUtils.getBaseLookupUrl(false);
89 }
90 RemotableQuickFinder.Builder quickFinderBuilder = RemotableQuickFinder.Builder.create(baseLookupUrl, dataObjectClass);
91 for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) {
92 Map<String, String> fieldConversionsMap = new HashMap<String, String>();
93 Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex);
94 if ("fieldConversions".equals(fieldConversionsChildNode)) {
95 for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) {
96 Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex);
97 if ("fieldConversion".equals(fieldConversionChildNode)) {
98 NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes();
99 String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName").getNodeValue();
100 String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName").getNodeValue();
101 fieldConversionsMap.put(lookupFieldName, localFieldName);
102 }
103 }
104 }
105 quickFinderBuilder.setFieldConversions(fieldConversionsMap);
106 fieldBuilder.getWidgets().add(quickFinderBuilder);
107 }
108 }
109
110 }