1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.lookup;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.web.format.DateFormatter;
20 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
21 import org.kuali.rice.kns.document.authorization.FieldRestriction;
22 import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
23 import org.kuali.rice.kns.service.KNSServiceLocator;
24 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25 import org.kuali.rice.krad.util.KRADConstants;
26 import org.kuali.rice.krad.util.ObjectUtils;
27
28 import java.io.Serializable;
29 import java.sql.Date;
30 import java.util.HashMap;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40
41 @Deprecated
42 public abstract class HtmlData implements Serializable {
43
44 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HtmlData.class);
45
46 public static final String ANCHOR_HTML_DATA_TYPE = AnchorHtmlData.class.getName();
47 public static final String INPUT_HTML_DATA_TYPE = InputHtmlData.class.getName();
48
49 protected String name = "";
50 protected String title = "";
51 protected String methodToCall = "";
52 protected String displayText = "";
53 protected String prependDisplayText = "";
54 protected String appendDisplayText = "";
55 protected List<HtmlData> childUrlDataList;
56 protected String maxLength;
57
58
59
60
61
62
63
64
65 public abstract String constructCompleteHtmlTag();
66
67
68
69
70 public String getAppendDisplayText() {
71 return this.appendDisplayText;
72 }
73
74
75
76
77 public void setAppendDisplayText(String appendDisplayText) {
78 this.appendDisplayText = appendDisplayText;
79 }
80
81
82
83
84 public List<HtmlData> getChildUrlDataList() {
85 return this.childUrlDataList;
86 }
87
88
89
90
91 public void setChildUrlDataList(List<HtmlData> childUrlDataList) {
92 this.childUrlDataList = childUrlDataList;
93 }
94
95
96
97
98 public String getPrependDisplayText() {
99 return this.prependDisplayText;
100 }
101
102
103
104
105 public void setPrependDisplayText(String prependDisplayText) {
106 this.prependDisplayText = prependDisplayText;
107 }
108
109
110
111
112 public String getTitle() {
113 return this.title;
114 }
115
116
117
118
119 public void setTitle(String title) {
120 this.title = title;
121 }
122
123
124
125
126 public String getName() {
127 return this.name;
128 }
129
130
131
132
133 public void setName(String name) {
134 this.name = name;
135 }
136
137
138
139
140 public String getDisplayText() {
141 return this.displayText;
142 }
143
144
145
146
147 public void setDisplayText(String displayText) {
148 this.displayText = displayText;
149 }
150
151
152
153
154 public String getMethodToCall() {
155 return this.methodToCall;
156 }
157
158
159
160
161 public void setMethodToCall(String methodToCall) {
162 this.methodToCall = methodToCall;
163 }
164
165 public String getTitle(String prependText, Class bo, List keys) {
166 return KRADConstants.EMPTY_STRING;
167 }
168
169
170
171
172
173
174
175
176
177
178 public static String getTitleText(String prependText, Object dataObject, List<String> keys, BusinessObjectRestrictions businessObjectRestrictions) {
179 if (dataObject == null)
180 return KRADConstants.EMPTY_STRING;
181
182 Map<String, String> keyValueMap = new HashMap<String, String>();
183 Iterator keysIt = keys.iterator();
184 while (keysIt.hasNext()) {
185 String fieldNm = (String) keysIt.next();
186 Object fieldVal = ObjectUtils.getPropertyValue(dataObject, fieldNm);
187
188 FieldRestriction fieldRestriction = null;
189 if (businessObjectRestrictions != null) {
190 fieldRestriction = businessObjectRestrictions.getFieldRestriction(fieldNm);
191 }
192 if (fieldRestriction != null && (fieldRestriction.isMasked() || fieldRestriction.isPartiallyMasked())) {
193 fieldVal = fieldRestriction.getMaskFormatter().maskValue(fieldVal);
194 } else if (fieldVal == null) {
195 fieldVal = KRADConstants.EMPTY_STRING;
196 } else if (fieldVal instanceof Date) {
197
198 DateFormatter dateFormatter = new DateFormatter();
199 fieldVal = dateFormatter.format(fieldVal);
200 }
201 keyValueMap.put(fieldNm, fieldVal.toString());
202 }
203 return getTitleText(prependText, dataObject.getClass(), keyValueMap);
204 }
205
206 private static BusinessObjectAuthorizationService businessObjectAuthorizationService;
207 private static BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() {
208 if (businessObjectAuthorizationService == null) {
209 businessObjectAuthorizationService = KNSServiceLocator.getBusinessObjectAuthorizationService();
210 }
211 return businessObjectAuthorizationService;
212 }
213
214 public static String getTitleText(String prependText, Class<?> dataObjectClass, Map<String, String> keyValueMap) {
215 StringBuffer titleText = new StringBuffer(prependText);
216 for (String key : keyValueMap.keySet()) {
217 String fieldVal = keyValueMap.get(key).toString();
218
219 titleText.append(KRADServiceLocatorWeb.getDataDictionaryService()
220 .getAttributeLabel(dataObjectClass, key)
221 + "=" + fieldVal.toString() + " ");
222 }
223 return titleText.toString();
224 }
225
226
227
228
229
230
231
232
233 public static class AnchorHtmlData extends HtmlData {
234 public static final String TARGET_BLANK = "_blank";
235 protected String href = "";
236 protected String target = "";
237 protected String style = "";
238 protected String styleClass ="";
239 protected String onclick ="";
240
241
242
243
244 public AnchorHtmlData() {
245 }
246
247 public AnchorHtmlData(String href, String title) {
248 this.href = href;
249 this.title = title;
250 }
251
252 public AnchorHtmlData(String href, String methodToCall,
253 String displayText) {
254 this.href = href;
255 this.methodToCall = methodToCall;
256 this.displayText = displayText;
257 }
258
259
260
261
262 public void setHref(String href) {
263 this.href = href;
264 }
265
266
267
268
269
270
271
272 public String constructCompleteHtmlTag() {
273 String completeHtmlTag;
274 if (StringUtils.isEmpty(getHref()))
275 completeHtmlTag = getDisplayText();
276 else
277 completeHtmlTag = getPrependDisplayText()
278 + "<a title=\""
279 + title
280 + "\""
281 + " href=\""
282 + getHref()
283 + "\""
284 + getStyle()
285 + " "
286 + getStyleClass()
287 + " "
288 + (StringUtils.isEmpty(getOnclick()) ? "" : " onClick=\""
289 + getOnclick() + "\" ")
290 + (StringUtils.isEmpty(getTarget()) ? "" : " target=\""
291 + getTarget() + "\" ") + ">" + getDisplayText()
292 + "</a>" + getAppendDisplayText();
293 return completeHtmlTag;
294 }
295
296
297
298
299 public String getTarget() {
300 return this.target;
301 }
302
303
304
305
306
307 public void setTarget(String target) {
308 this.target = target;
309 }
310
311
312
313
314 public String getStyle() {
315 return this.style;
316 }
317
318
319
320
321 public void setStyle(String style) {
322 this.style = style;
323 }
324
325
326
327
328 public String getStyleClass() {
329 return this.styleClass;
330 }
331
332
333
334
335 public void setStyleClass(String styleClass) {
336 this.styleClass = styleClass;
337 }
338
339
340
341
342 public String getOnclick() {
343 return this.onclick;
344 }
345
346
347
348
349 public void setOnclick(String onclick) {
350 this.onclick = onclick;
351 }
352
353
354
355
356 public String getHref() {
357 return this.href;
358 }
359
360
361
362
363 public String getMethodToCall() {
364 return this.methodToCall;
365 }
366
367 }
368
369
370
371
372
373
374
375
376 public static class InputHtmlData extends HtmlData {
377 public static final String CHECKBOX_INPUT_TYPE = "checkbox";
378 public static final String CHECKBOX_CHECKED_VALUE = "checked";
379
380 protected String inputType = "";
381 protected String src = "";
382 protected String styleClass = "";
383 protected String border = "0";
384 protected String checked = "";
385 protected String value = "";
386
387 public InputHtmlData(String name, String inputType) {
388 this.name = name;
389 this.inputType = inputType;
390 }
391
392 public InputHtmlData(String name, String inputType, String src) {
393 this.name = name;
394 this.inputType = inputType;
395 this.src = src;
396 }
397
398
399
400
401
402
403
404 public String constructCompleteHtmlTag() {
405 return getPrependDisplayText()
406 + "<input title=\""
407 + title
408 + "\""
409 + " name=\""
410 + getName()
411 + "\""
412 + (StringUtils.isEmpty(src) ? ""
413 : " src=\"" + src + "\" ")
414 + " type=\""
415 + getInputType()
416 + "\""
417 + (StringUtils.isEmpty(value) ? ""
418 : " value=\"" + value + "\" ")
419 + (StringUtils.isEmpty(checked) ? ""
420 : " checked=\"" + checked + "\" ")
421 + (StringUtils.isEmpty(getStyleClass()) ? ""
422 : " styleClass=\"" + getStyleClass() + "\" ")
423 + " border=\"" + getBorder() + "\"" + " value=\""
424 + getDisplayText() + "\"" + "/>" + getAppendDisplayText();
425 }
426
427
428
429
430 public String getInputType() {
431 return this.inputType;
432 }
433
434
435
436
437 public String getSrc() {
438 return this.src;
439 }
440
441
442
443
444 public String getBorder() {
445 return this.border;
446 }
447
448
449
450
451
452 public void setBorder(String border) {
453 this.border = border;
454 }
455
456
457
458
459 public String getStyleClass() {
460 return this.styleClass;
461 }
462
463
464
465
466
467 public void setStyleClass(String styleClass) {
468 this.styleClass = styleClass;
469 }
470
471
472
473
474 public void setChecked(String checked) {
475 this.checked = checked;
476 }
477
478
479
480
481 public void setValue(String value) {
482 this.value = value;
483 }
484
485 }
486
487 public static class MultipleAnchorHtmlData extends AnchorHtmlData {
488 protected List<AnchorHtmlData> anchorHtmlData;
489 protected static final String ANCHORS_SEPARATOR = ", ";
490
491
492
493
494 public MultipleAnchorHtmlData(List<AnchorHtmlData> anchorHtmlData) {
495 this.anchorHtmlData = anchorHtmlData;
496 }
497
498
499
500
501
502
503
504 public String constructCompleteHtmlTag() {
505 StringBuffer completeHtmlTag = new StringBuffer();
506 for(AnchorHtmlData anchor: anchorHtmlData){
507 completeHtmlTag.append(anchor.constructCompleteHtmlTag()+",");
508 }
509 if(completeHtmlTag.toString().endsWith(ANCHORS_SEPARATOR))
510 completeHtmlTag.delete(completeHtmlTag.length()-ANCHORS_SEPARATOR.length(), completeHtmlTag.length());
511 return completeHtmlTag.toString();
512 }
513
514
515
516
517 public List<AnchorHtmlData> getAnchorHtmlData() {
518 return this.anchorHtmlData;
519 }
520
521 }
522
523
524
525
526 public int getMaxLength() {
527 try{
528 return Integer.parseInt(this.maxLength);
529 } catch(Exception ex){
530 return -1;
531 }
532 }
533
534
535
536
537 public void setMaxLength(String maxLength) {
538 this.maxLength = maxLength;
539 }
540
541 }