1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import org.kuali.rice.krad.uif.component.Component;
19 import org.kuali.rice.krad.uif.container.CollectionGroup;
20 import org.kuali.rice.krad.uif.container.Container;
21 import org.kuali.rice.krad.uif.container.Group;
22 import org.kuali.rice.krad.uif.container.PageGroup;
23 import org.kuali.rice.krad.uif.field.DataField;
24 import org.kuali.rice.krad.uif.field.FieldGroup;
25 import org.kuali.rice.krad.uif.field.InputField;
26 import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
27 import org.kuali.rice.krad.uif.layout.TableLayoutManager;
28 import org.kuali.rice.krad.uif.view.View;
29 import org.kuali.rice.krad.uif.view.ViewIndex;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34
35
36
37
38
39
40
41
42
43
44
45 public class ViewCleaner {
46
47
48
49
50
51
52
53 public static void cleanView(View view) {
54 view.setApplicationHeader(null);
55 view.setApplicationFooter(null);
56 view.setBreadcrumbs(null);
57 view.setBreadcrumbOptions(null);
58 view.setBreadcrumbItem(null);
59 view.setParentLocation(null);
60 view.setPathBasedBreadcrumbs(null);
61 view.setNavigation(null);
62 view.setPage(null);
63 view.setNavigation(null);
64 view.setAdditionalCssFiles(null);
65 view.setAdditionalScriptFiles(null);
66 view.setActionFlags(null);
67 view.setEditModes(null);
68 view.setViewMenuLink(null);
69 view.setViewMenuLink(null);
70 view.setPreLoadScript(null);
71 view.setViewTemplates(new ArrayList<String>());
72 view.setSessionPolicy(null);
73 view.setViewHelperServiceClass(null);
74
75 view.getViewIndex().clearIndexesAfterRender();
76
77
78 PageGroup currentPage = view.getCurrentPage();
79 cleanComponent(currentPage, view.getViewIndex());
80
81 cleanComponent(view, view.getViewIndex());
82
83 List<Component> pages = new ArrayList<Component>();
84 pages.add(currentPage);
85
86 view.setItems(pages);
87 }
88
89
90
91
92
93
94 public static void cleanComponent(Component component, ViewIndex viewIndex) {
95 if (component == null) {
96 return;
97 }
98
99 if (component.isForceSessionPersistence()) {
100 return;
101 }
102
103 component.setTemplate(null);
104 component.setTemplateName(null);
105 component.setTitle(null);
106 component.setProgressiveRender(null);
107 component.setConditionalRefresh(null);
108 component.setRefreshWhenChangedPropertyNames(null);
109 component.setAdditionalComponentsToRefresh(null);
110 component.setAlign(null);
111 component.setValign(null);
112 component.setWidth(null);
113 component.setCellCssClasses(null);
114 component.setCellStyle(null);
115 component.setCellWidth(null);
116 component.setStyle(null);
117 component.setLibraryCssClasses(null);
118 component.setCssClasses(null);
119 component.setAdditionalCssClasses(null);
120 component.setToolTip(null);
121 component.setRenderedHtmlOutput(null);
122 component.setComponentSecurity(null);
123 component.setOnLoadScript(null);
124 component.setOnUnloadScript(null);
125 component.setOnCloseScript(null);
126 component.setOnBlurScript(null);
127 component.setOnChangeScript(null);
128 component.setOnClickScript(null);
129 component.setOnDblClickScript(null);
130 component.setOnFocusScript(null);
131 component.setOnSubmitScript(null);
132 component.setOnKeyPressScript(null);
133 component.setOnKeyUpScript(null);
134 component.setOnKeyDownScript(null);
135 component.setOnMouseOverScript(null);
136 component.setOnMouseOutScript(null);
137 component.setOnMouseUpScript(null);
138 component.setOnMouseDownScript(null);
139 component.setOnMouseMoveScript(null);
140 component.setOnDocumentReadyScript(null);
141 component.setComponentModifiers(null);
142 component.setTemplateOptions(null);
143 component.setTemplateOptionsJSString(null);
144 component.setPropertyReplacers(null);
145
146 if (!viewIndex.isIdForRefreshComponent(component.getId())) {
147 component.setDataAttributes(null);
148 }
149
150 component.setPreRenderContent(null);
151 component.setPostRenderContent(null);
152 component.setExpressionGraph(null);
153 component.setPropertyExpressions(null);
154
155
156
157 if (!viewIndex.isIdForRefreshComponent(component.getId()) && !(component instanceof PageGroup)
158 && !(component instanceof View)) {
159 component.setContext(null);
160 }
161
162 if (component instanceof Container) {
163 cleanContainer((Container) component, viewIndex);
164 }
165
166 if (component instanceof DataField) {
167 cleanDataField((DataField) component);
168 }
169
170 if (component instanceof FieldGroup) {
171 Component group = ((FieldGroup) component).getGroup();
172 cleanComponent(group, viewIndex);
173 }
174 }
175
176
177
178
179
180
181 protected static void cleanContainer(Container container, ViewIndex viewIndex) {
182 container.setHeader(null);
183 container.setFooter(null);
184 container.setHelp(null);
185 container.setInstructionalMessage(null);
186
187
188 if (!(container instanceof PageGroup)) {
189 container.setValidationMessages(null);
190 }
191
192 if (container.getItems() != null) {
193 for (Component item : container.getItems()) {
194 cleanComponent(item, viewIndex);
195 }
196 }
197
198 if (container instanceof Group) {
199 Group group = (Group) container;
200
201 group.setDisclosure(null);
202 group.setScrollpane(null);
203 }
204
205 if (container instanceof CollectionGroup) {
206 cleanCollectionGroup((CollectionGroup) container, viewIndex);
207 }
208 else {
209 container.setLayoutManager(null);
210 }
211 }
212
213
214
215
216
217
218
219 protected static void cleanCollectionGroup(CollectionGroup collectionGroup, ViewIndex viewIndex) {
220 collectionGroup.setAddLineLabel(null);
221
222 if (collectionGroup.getAddLineItems() != null) {
223 for (Component item : collectionGroup.getAddLineItems()) {
224 cleanComponent(item, viewIndex);
225 }
226 }
227
228 collectionGroup.setAddLineActions(null);
229 collectionGroup.setLineActions(null);
230 collectionGroup.setActiveCollectionFilter(null);
231 collectionGroup.setFilters(null);
232 collectionGroup.setSubCollections(null);
233 collectionGroup.setCollectionGroupBuilder(null);
234 collectionGroup.setNewItemsCssClass(null);
235 collectionGroup.setAddItemCssClass(null);
236 collectionGroup.setAddBlankLineAction(null);
237 collectionGroup.setAddViaLightBoxAction(null);
238
239 if ((collectionGroup.getLayoutManager() != null) && (collectionGroup
240 .getLayoutManager() instanceof TableLayoutManager) && !collectionGroup.isUseServerPaging()) {
241
242 cleanTableLayoutManager((TableLayoutManager) collectionGroup.getLayoutManager());
243 }
244 else if ((collectionGroup.getLayoutManager() != null) && (collectionGroup
245 .getLayoutManager() instanceof StackedLayoutManager)) {
246 collectionGroup.setLayoutManager(null);
247 }
248 }
249
250
251
252
253
254
255 protected static void cleanTableLayoutManager(TableLayoutManager tableLayoutManager) {
256 tableLayoutManager.setHeaderLabelPrototype(null);
257 tableLayoutManager.setSequenceFieldPrototype(null);
258 tableLayoutManager.setActionFieldPrototype(null);
259 tableLayoutManager.setSubCollectionFieldGroupPrototype(null);
260 tableLayoutManager.setSelectFieldPrototype(null);
261 tableLayoutManager.setAddLineGroup(null);
262 tableLayoutManager.setRowDetailsGroup(null);
263 tableLayoutManager.setToggleAllDetailsAction(null);
264 tableLayoutManager.setExpandDetailsActionPrototype(null);
265 tableLayoutManager.setGroupingPropertyNames(null);
266 tableLayoutManager.setTotalLabel(null);
267 tableLayoutManager.setPageTotalLabel(null);
268 tableLayoutManager.setGroupTotalLabelPrototype(null);
269 tableLayoutManager.setColumnCalculations(null);
270 }
271
272
273
274
275
276
277 protected static void cleanDataField(DataField dataField) {
278 dataField.setLabel(null);
279 dataField.setFieldLabel(null);
280 dataField.setDictionaryAttributeName(null);
281 dataField.setDictionaryObjectEntry(null);
282 dataField.setForcedValue(null);
283 dataField.setReadOnlyDisplayReplacementPropertyName(null);
284 dataField.setReadOnlyDisplaySuffixPropertyName(null);
285 dataField.setReadOnlyDisplayReplacement(null);
286 dataField.setReadOnlyDisplaySuffix(null);
287 dataField.setReadOnlyListDisplayType(null);
288 dataField.setReadOnlyListDelimiter(null);
289 dataField.setMaskFormatter(null);
290 dataField.setAdditionalHiddenPropertyNames(null);
291 dataField.setPropertyNamesForAdditionalDisplay(null);
292 dataField.setInquiry(null);
293 dataField.setHelp(null);
294
295 if (dataField instanceof InputField) {
296 cleanInputField((InputField) dataField);
297 }
298 }
299
300
301
302
303
304
305 protected static void cleanInputField(InputField inputField) {
306 inputField.setCustomValidatorClass(null);
307 inputField.setValidCharactersConstraint(null);
308 inputField.setCaseConstraint(null);
309 inputField.setDependencyConstraints(null);
310 inputField.setMustOccurConstraints(null);
311 inputField.setControl(null);
312 inputField.setOptionsFinder(null);
313 inputField.setValidationMessages(null);
314 inputField.setConstraintText(null);
315 inputField.setInstructionalText(null);
316 inputField.setInstructionalMessage(null);
317 inputField.setConstraintMessage(null);
318 inputField.setQuickfinder(null);
319 }
320 }