View Javadoc

1   /*
2    * Copyright 2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.attribute;
17  
18  import org.kuali.rice.core.api.uif.RemotableAttributeField;
19  import org.kuali.rice.core.api.uif.RemotableQuickFinder;
20  import org.kuali.rice.kns.web.ui.Field;
21  import org.w3c.dom.NamedNodeMap;
22  import org.w3c.dom.Node;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * This class provides some common shared utility methods shared by the XML-based
29   * attribute implementations. 
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public final class XMLAttributeUtils {
35  
36  	private XMLAttributeUtils() {
37  		throw new UnsupportedOperationException("do not call");
38  	}
39  
40      /**
41       * TODO - Rice 2.0 - Can remove this method once old xml attributes have been converted to RemotableAttributeField
42       */
43  	public static void establishFieldLookup(Field field, Node lookupNode) {
44  		NamedNodeMap quickfinderAttributes = lookupNode.getAttributes();
45  		String businessObjectClass = quickfinderAttributes.getNamedItem("dataObjectClass").getNodeValue();
46  		field.setQuickFinderClassNameImpl(businessObjectClass);
47  		for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) {
48  			Map<String, String> fieldConversionsMap = new HashMap<String, String>();
49  			Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex);
50  			if ("fieldConversions".equals(fieldConversionsChildNode)) {
51  				for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) {
52  					Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex);
53  					if ("fieldConversion".equals(fieldConversionChildNode)) {
54  						NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes();
55  						String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName").getNodeValue();
56  						String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName").getNodeValue();
57  						fieldConversionsMap.put(lookupFieldName, localFieldName);
58  					}
59  				}
60  			}
61  			field.setFieldConversions(fieldConversionsMap);
62  		}
63  	}
64  
65      public static void establishFieldLookup(RemotableAttributeField.Builder fieldBuilder, Node lookupNode) {
66  		NamedNodeMap quickfinderAttributes = lookupNode.getAttributes();
67  		String businessObjectClass = quickfinderAttributes.getNamedItem("dataObjectClass").getNodeValue();
68          // TODO - Rice 2.0 - Not sure if null is appropriate for baseLookupUrl, maybe we need to look this up somewhere?
69          RemotableQuickFinder.Builder quickFinderBuilder = RemotableQuickFinder.Builder.create(null, businessObjectClass);
70  		for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) {
71  			Map<String, String> fieldConversionsMap = new HashMap<String, String>();
72  			Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex);
73  			if ("fieldConversions".equals(fieldConversionsChildNode)) {
74  				for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) {
75  					Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex);
76  					if ("fieldConversion".equals(fieldConversionChildNode)) {
77  						NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes();
78  						String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName").getNodeValue();
79  						String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName").getNodeValue();
80  						fieldConversionsMap.put(lookupFieldName, localFieldName);
81  					}
82  				}
83  			}
84              quickFinderBuilder.setFieldConversions(fieldConversionsMap);
85  			fieldBuilder.getWidgets().add(quickFinderBuilder);
86  		}
87  	}
88  	
89  }