1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.spring; |
17 | |
|
18 | |
import java.beans.PropertyEditor; |
19 | |
import java.util.HashSet; |
20 | |
import java.util.Set; |
21 | |
|
22 | |
import org.kuali.rice.core.web.format.Formatter; |
23 | |
import org.kuali.rice.kns.uif.field.AttributeField; |
24 | |
import org.kuali.rice.kns.web.spring.form.UifFormBase; |
25 | |
import org.springframework.beans.BeanWrapperImpl; |
26 | |
import org.springframework.beans.BeansException; |
27 | |
import org.springframework.beans.PropertyValue; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class UifViewBeanWrapper extends BeanWrapperImpl { |
37 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifViewBeanWrapper.class); |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
private UifFormBase form; |
43 | |
|
44 | |
|
45 | |
|
46 | |
private Set<String> processedProperties; |
47 | |
|
48 | |
|
49 | |
public UifViewBeanWrapper(Object object) { |
50 | 0 | super(object); |
51 | |
|
52 | 0 | form = (UifFormBase)object; |
53 | 0 | processedProperties = new HashSet<String>(); |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
protected void callViewService(String propertyName) { |
58 | 0 | if (LOG.isDebugEnabled()) { |
59 | 0 | LOG.debug("Attempting view service call for property '" + propertyName + "'"); |
60 | |
} |
61 | 0 | Class<? extends Formatter> formatterClass = null; |
62 | |
|
63 | |
|
64 | |
|
65 | 0 | if(form.getView() == null) { |
66 | 0 | return; |
67 | |
} |
68 | |
|
69 | |
|
70 | 0 | if(processedProperties.contains(propertyName)) { |
71 | 0 | return; |
72 | |
} |
73 | |
|
74 | 0 | AttributeField af = form.getView().getViewIndex().getAttributeFieldByPath(propertyName); |
75 | 0 | boolean requiresEncryption = false; |
76 | 0 | if(af != null) { |
77 | 0 | if (af.getAttributeSecurity() != null) { |
78 | 0 | if (af.getAttributeSecurity().hasRestrictionThatRemovesValueFromUI()) { |
79 | 0 | requiresEncryption = true; |
80 | |
} |
81 | |
} |
82 | |
|
83 | 0 | Formatter formatter = af.getFormatter(); |
84 | 0 | if(formatter != null) { |
85 | 0 | formatterClass = formatter.getClass(); |
86 | |
} |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | 0 | if(formatterClass != null) { |
92 | 0 | if (LOG.isDebugEnabled()) { |
93 | 0 | LOG.debug("Registering custom editor for property path '" + propertyName + "' and formatter class '" + formatterClass.getName() + "'"); |
94 | |
} |
95 | 0 | PropertyEditor customEditor = new UifKnsFormatterPropertyEditor(formatterClass); |
96 | 0 | if (requiresEncryption) { |
97 | 0 | if (LOG.isDebugEnabled()) { |
98 | 0 | LOG.debug("Enabling encryption for custom editor '" + propertyName + "' and formatter class '" + formatterClass.getName() + "'"); |
99 | |
} |
100 | 0 | this.registerCustomEditor(null, propertyName, new UifEncryptionPropertyEditorWrapper(customEditor)); |
101 | |
} else { |
102 | 0 | this.registerCustomEditor(null, propertyName, customEditor); |
103 | |
} |
104 | 0 | } else if (requiresEncryption) { |
105 | 0 | if (LOG.isDebugEnabled()) { |
106 | 0 | LOG.debug("No custom formatter for property path '" + propertyName + "' but property does require encryption"); |
107 | |
} |
108 | 0 | this.registerCustomEditor(null, propertyName, new UifEncryptionPropertyEditorWrapper(findEditorForPropertyName(propertyName))); |
109 | |
} |
110 | |
|
111 | 0 | processedProperties.add(propertyName); |
112 | |
|
113 | 0 | } |
114 | |
|
115 | |
protected PropertyEditor findEditorForPropertyName(String propertyName) { |
116 | 0 | Class<?> clazz = getPropertyType(propertyName); |
117 | 0 | if (LOG.isDebugEnabled()) { |
118 | 0 | LOG.debug("Attempting retrieval of property editor using class '" + clazz + "' and property path '" + propertyName + "'"); |
119 | |
} |
120 | 0 | PropertyEditor editor = findCustomEditor(clazz, propertyName); |
121 | 0 | if (editor == null) { |
122 | 0 | if (LOG.isDebugEnabled()) { |
123 | 0 | LOG.debug("No custom property editor found using class '" + clazz + "' and property path '" + propertyName + "'. Attempting to find default property editor class."); |
124 | |
} |
125 | 0 | editor = getDefaultEditor(clazz); |
126 | |
} |
127 | 0 | return editor; |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public Object getPropertyValue(String propertyName) throws BeansException { |
132 | 0 | callViewService(propertyName); |
133 | 0 | return super.getPropertyValue(propertyName); |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public void setPropertyValue(PropertyValue pv) throws BeansException { |
138 | 0 | callViewService(pv.getName()); |
139 | 0 | super.setPropertyValue(pv); |
140 | 0 | } |
141 | |
|
142 | |
@Override |
143 | |
public void setPropertyValue(String propertyName, Object value) throws BeansException { |
144 | 0 | callViewService(propertyName); |
145 | 0 | super.setPropertyValue(propertyName, value); |
146 | 0 | } |
147 | |
|
148 | |
@Override |
149 | |
public void setWrappedInstance(Object object, String nestedPath, Object rootObject) { |
150 | |
|
151 | 0 | form = (UifFormBase)object; |
152 | 0 | super.setWrappedInstance(object, nestedPath, rootObject); |
153 | 0 | } |
154 | |
|
155 | |
@Override |
156 | |
public void setWrappedInstance(Object object) { |
157 | |
|
158 | 0 | form = (UifFormBase)object; |
159 | 0 | super.setWrappedInstance(object); |
160 | 0 | } |
161 | |
|
162 | |
} |