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