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