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.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
23 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
24 import org.kuali.rice.krad.uif.UifConstants;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.container.PageGroup;
27 import org.kuali.rice.krad.uif.element.BreadcrumbItem;
28 import org.kuali.rice.krad.uif.element.Header;
29 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
30 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
31 import org.kuali.rice.krad.uif.view.View;
32
33 import java.io.Serializable;
34 import java.util.ArrayList;
35 import java.util.List;
36 import java.util.Map;
37
38
39
40
41
42
43 @BeanTag(name = "parentLocation", parent = "Uif-ParentLocation")
44 public class ParentLocation extends UifDictionaryBeanBase implements Serializable {
45
46 private static final long serialVersionUID = -6242148809697931126L;
47
48
49 private UrlInfo parentViewUrl;
50 private UrlInfo parentPageUrl;
51 private String parentViewLabel;
52 private String parentPageLabel;
53
54 private BreadcrumbItem viewBreadcrumbItem;
55 private BreadcrumbItem pageBreadcrumbItem;
56 protected List<BreadcrumbItem> resolvedBreadcrumbItems = new ArrayList<BreadcrumbItem>();
57
58
59
60
61
62
63
64
65
66
67
68
69 public List<BreadcrumbItem> constructParentLocationBreadcrumbItems(View view, Object currentModel,
70 Map<String, Object> currentContext) {
71
72 if (viewBreadcrumbItem == null) {
73 return resolvedBreadcrumbItems;
74 }
75
76
77 this.handleExpressions(view, currentModel, currentContext, ViewLifecycle.getExpressionEvaluator());
78
79
80 if (StringUtils.isNotBlank(parentViewUrl.getOriginalHref()) || (StringUtils.isNotBlank(
81 parentViewUrl.getViewId()) && StringUtils.isNotBlank(parentViewUrl.getControllerMapping()))) {
82 viewBreadcrumbItem.setUrl(parentViewUrl);
83 viewBreadcrumbItem.setLabel(parentViewLabel);
84 }
85
86 if (StringUtils.isNotBlank(parentPageUrl.getOriginalHref()) || (StringUtils.isNotBlank(
87 parentPageUrl.getViewId()) && StringUtils.isNotBlank(parentPageUrl.getControllerMapping()))) {
88 pageBreadcrumbItem.setUrl(parentPageUrl);
89 pageBreadcrumbItem.setLabel(parentPageLabel);
90 }
91
92
93 if (viewBreadcrumbItem.getUrl() == null || StringUtils.isBlank(viewBreadcrumbItem.getUrl().getOriginalHref())
94 && StringUtils.isBlank(viewBreadcrumbItem.getUrl().getViewId())) {
95 return resolvedBreadcrumbItems;
96 }
97
98 String parentViewId = viewBreadcrumbItem.getUrl().getViewId();
99 String controllerMapping = viewBreadcrumbItem.getUrl().getControllerMapping();
100
101 View parentView = null;
102
103 if (viewBreadcrumbItem.getUrl() != null && StringUtils.isNotBlank(controllerMapping) && StringUtils.isNotBlank(
104 parentViewId) && StringUtils.isBlank(viewBreadcrumbItem.getUrl().getOriginalHref())) {
105 parentView = KRADServiceLocatorWeb.getDataDictionaryService().getViewById(parentViewId);
106 }
107
108
109 if (parentView != null) {
110 processParentViewDerivedContent(parentView, parentViewId, view, currentModel, currentContext);
111 }
112
113
114 if (StringUtils.isNotEmpty(viewBreadcrumbItem.getLabel())) {
115 resolvedBreadcrumbItems.add(viewBreadcrumbItem);
116 }
117
118
119 if (pageBreadcrumbItem != null && StringUtils.isNotEmpty(pageBreadcrumbItem.getLabel())) {
120 resolvedBreadcrumbItems.add(pageBreadcrumbItem);
121 }
122
123 return resolvedBreadcrumbItems;
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137 private void processParentViewDerivedContent(View parentView, String parentViewId, View currentView,
138 Object currentModel, Map<String, Object> currentContext) {
139
140 ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(parentView, false);
141
142
143 if (((View) parentView).getParentLocation() != null) {
144 resolvedBreadcrumbItems.addAll(
145 ((View) parentView).getParentLocation().constructParentLocationBreadcrumbItems(parentView,
146 currentModel, currentContext));
147 }
148
149 handleLabelExpressions(parentView, currentModel, currentContext, ViewLifecycle.getExpressionEvaluator());
150
151
152
153
154 if (StringUtils.isBlank(viewBreadcrumbItem.getLabel()) && parentView.getBreadcrumbItem() != null &&
155 StringUtils.isNotBlank(parentView.getBreadcrumbItem().getLabel())) {
156 viewBreadcrumbItem.setLabel(parentView.getBreadcrumbItem().getLabel());
157 } else if (StringUtils.isBlank(viewBreadcrumbItem.getLabel()) && StringUtils.isNotBlank(
158 parentView.getHeaderText())) {
159 viewBreadcrumbItem.setLabel(parentView.getHeaderText());
160 }
161
162
163 if (parentView.getBreadcrumbItem() != null
164 && parentView.getBreadcrumbItem().getSiblingBreadcrumbComponent() != null
165 && viewBreadcrumbItem.getSiblingBreadcrumbComponent() == null) {
166 viewBreadcrumbItem.setSiblingBreadcrumbComponent(
167 parentView.getBreadcrumbItem().getSiblingBreadcrumbComponent());
168 }
169
170
171 if (pageBreadcrumbItem != null && StringUtils.isNotBlank(pageBreadcrumbItem.getUrl().getPageId()) && StringUtils
172 .isNotBlank(pageBreadcrumbItem.getUrl().getViewId()) && pageBreadcrumbItem.getUrl().getViewId().equals(
173 parentViewId)) {
174 handlePageBreadcrumb(parentView, currentModel);
175 }
176 }
177
178
179
180
181
182
183
184
185
186
187 private void handleLabelExpressions(View parentView, Object currentModel, Map<String, Object> currentContext,
188 ExpressionEvaluator expressionEvaluator) {
189 try {
190 Header header = parentView.getHeader();
191
192 if (header != null) {
193 if (StringUtils.isNotBlank(parentView.getPropertyExpressions().get(
194 UifConstants.ComponentProperties.HEADER_TEXT))) {
195 header.getPropertyExpressions().put(UifConstants.ComponentProperties.HEADER_TEXT,
196 parentView.getPropertyExpressions().get(UifConstants.ComponentProperties.HEADER_TEXT));
197 }
198
199 expressionEvaluator.evaluateExpressionsOnConfigurable(parentView, header, currentContext);
200 }
201
202 BreadcrumbItem breadcrumbItem = parentView.getBreadcrumbItem();
203
204 if (breadcrumbItem != null) {
205 expressionEvaluator.evaluateExpressionsOnConfigurable(parentView, breadcrumbItem, currentContext);
206 }
207
208 if (pageBreadcrumbItem != null && pageBreadcrumbItem.getUrl() != null && StringUtils.isNotBlank(
209 pageBreadcrumbItem.getUrl().getPageId())) {
210 PageGroup thePage = null;
211 if (parentView.isSinglePageView() && parentView.getPage() != null) {
212 thePage = parentView.getPage();
213 } else {
214 for (Component item : parentView.getItems()) {
215 if (item.getId().equals(pageBreadcrumbItem.getUrl().getPageId())) {
216 thePage = (PageGroup) item;
217 break;
218 }
219 }
220 }
221
222 if (thePage == null) {
223
224 return;
225 }
226
227
228 ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(thePage, false);
229
230 Header pageHeader = thePage.getHeader();
231
232 if (pageHeader != null) {
233 if (StringUtils.isNotBlank(thePage.getPropertyExpressions().get(
234 UifConstants.ComponentProperties.HEADER_TEXT))) {
235 pageHeader.getPropertyExpressions().put(UifConstants.ComponentProperties.HEADER_TEXT,
236 thePage.getPropertyExpressions().get(UifConstants.ComponentProperties.HEADER_TEXT));
237 }
238
239 expressionEvaluator.evaluateExpressionsOnConfigurable(parentView, pageHeader, currentContext);
240 }
241
242 BreadcrumbItem pageBreadcrumb = thePage.getBreadcrumbItem();
243
244 if (pageBreadcrumb != null) {
245 expressionEvaluator.evaluateExpressionsOnConfigurable(parentView, pageBreadcrumb, currentContext);
246 }
247 }
248 } catch (RuntimeException e) {
249 throw new RuntimeException("There was likely a problem evaluating an expression in a parent view or page"
250 + " because a property may not exist in the current context - explicitly set the label for this"
251 + " parentLocation: "
252 + parentView.getId(), e);
253 }
254 }
255
256
257
258
259
260
261
262
263
264
265
266 private void handleExpressions(View view, Object currentModel, Map<String, Object> currentContext,
267 ExpressionEvaluator expressionEvaluator) {
268 try {
269
270 expressionEvaluator.initializeEvaluationContext(currentModel);
271
272
273 expressionEvaluator.evaluateExpressionsOnConfigurable(view, viewBreadcrumbItem, currentContext);
274
275 if (viewBreadcrumbItem.getUrl() != null) {
276 expressionEvaluator.evaluateExpressionsOnConfigurable(view, viewBreadcrumbItem.getUrl(),
277 currentContext);
278 }
279
280 if (parentViewUrl != null) {
281 expressionEvaluator.evaluateExpressionsOnConfigurable(view, parentViewUrl, currentContext);
282 }
283
284
285 if (pageBreadcrumbItem != null) {
286 expressionEvaluator.evaluateExpressionsOnConfigurable(view, pageBreadcrumbItem, currentContext);
287
288 if (pageBreadcrumbItem.getUrl() != null) {
289 expressionEvaluator.evaluateExpressionsOnConfigurable(view, pageBreadcrumbItem.getUrl(),
290 currentContext);
291 }
292 }
293
294 if (parentPageUrl != null) {
295 expressionEvaluator.evaluateExpressionsOnConfigurable(view, parentPageUrl, currentContext);
296 }
297 } catch (RuntimeException e) {
298 throw new RuntimeException("There was likely a problem evaluating an expression in a parent view or page"
299 + " because a property may not exist in the current context - problem in Url or BreadcrumbItem"
300 + " - set these to something that can be evaluated - of the parentLocation: "
301 + view.getId(), e);
302 }
303 }
304
305
306
307
308
309
310
311 private void handlePageBreadcrumb(View view, Object currentModel) {
312 PageGroup thePage = null;
313 if (view.isSinglePageView() && view.getPage() != null) {
314 thePage = view.getPage();
315 } else {
316 for (Component item : view.getItems()) {
317 if (item.getId().equals(pageBreadcrumbItem.getUrl().getPageId())) {
318 thePage = (PageGroup) item;
319 break;
320 }
321 }
322 }
323
324 if (thePage == null) {
325 return;
326 }
327
328
329 if (StringUtils.isBlank(pageBreadcrumbItem.getLabel()) && thePage.getBreadcrumbItem() != null &&
330 StringUtils.isNotBlank(thePage.getBreadcrumbItem().getLabel())) {
331 pageBreadcrumbItem.setLabel(thePage.getBreadcrumbItem().getLabel());
332 } else if (StringUtils.isBlank(pageBreadcrumbItem.getLabel()) && StringUtils.isNotBlank(
333 thePage.getHeaderText())) {
334 pageBreadcrumbItem.setLabel(thePage.getHeaderText());
335 }
336
337
338 if (thePage.getBreadcrumbItem() != null
339 && thePage.getBreadcrumbItem().getSiblingBreadcrumbComponent() != null
340 && pageBreadcrumbItem.getSiblingBreadcrumbComponent() == null) {
341 pageBreadcrumbItem.setSiblingBreadcrumbComponent(
342 thePage.getBreadcrumbItem().getSiblingBreadcrumbComponent());
343 }
344 }
345
346
347
348
349
350
351
352
353
354
355
356
357 @BeanTagAttribute(name = "parentViewUrl", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
358 public UrlInfo getParentViewUrl() {
359 return parentViewUrl;
360 }
361
362
363
364
365
366
367 public void setParentViewUrl(UrlInfo parentViewUrl) {
368 this.parentViewUrl = parentViewUrl;
369 }
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384 @BeanTagAttribute(name = "parentPageUrl", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
385 public UrlInfo getParentPageUrl() {
386 return parentPageUrl;
387 }
388
389
390
391
392
393
394 public void setParentPageUrl(UrlInfo parentPageUrl) {
395 this.parentPageUrl = parentPageUrl;
396 }
397
398
399
400
401
402
403
404
405
406
407
408
409
410 @BeanTagAttribute(name = "parentViewLabel")
411 public String getParentViewLabel() {
412 return parentViewLabel;
413 }
414
415
416
417
418
419
420 public void setParentViewLabel(String parentViewLabel) {
421 this.parentViewLabel = parentViewLabel;
422 }
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438 @BeanTagAttribute(name = "parentPageLabel")
439 public String getParentPageLabel() {
440 return parentPageLabel;
441 }
442
443
444
445
446
447
448 public void setParentPageLabel(String parentPageLabel) {
449 this.parentPageLabel = parentPageLabel;
450 }
451
452
453
454
455
456
457
458 @BeanTagAttribute(name = "viewBreadcrumbItem", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
459 public BreadcrumbItem getViewBreadcrumbItem() {
460 return viewBreadcrumbItem;
461 }
462
463
464
465
466
467
468 public void setViewBreadcrumbItem(BreadcrumbItem breadcrumbItem) {
469 this.viewBreadcrumbItem = breadcrumbItem;
470 }
471
472
473
474
475
476
477
478 @BeanTagAttribute(name = "pageBreadcrumbItem", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
479 public BreadcrumbItem getPageBreadcrumbItem() {
480 return pageBreadcrumbItem;
481 }
482
483
484
485
486
487
488 public void setPageBreadcrumbItem(BreadcrumbItem pageBreadcrumbItem) {
489 this.pageBreadcrumbItem = pageBreadcrumbItem;
490 }
491
492
493
494
495
496
497
498 public List<BreadcrumbItem> getResolvedBreadcrumbItems() {
499 return resolvedBreadcrumbItems;
500 }
501
502 }