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 | 0 | public abstract class HtmlData implements Serializable { |
43 | |
|
44 | 0 | protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HtmlData.class); |
45 | |
|
46 | 0 | public static final String ANCHOR_HTML_DATA_TYPE = AnchorHtmlData.class.getName(); |
47 | 0 | public static final String INPUT_HTML_DATA_TYPE = InputHtmlData.class.getName(); |
48 | |
|
49 | 0 | protected String name = ""; |
50 | 0 | protected String title = ""; |
51 | 0 | protected String methodToCall = ""; |
52 | 0 | protected String displayText = ""; |
53 | 0 | protected String prependDisplayText = ""; |
54 | 0 | 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 | 0 | return this.appendDisplayText; |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public void setAppendDisplayText(String appendDisplayText) { |
78 | 0 | this.appendDisplayText = appendDisplayText; |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public List<HtmlData> getChildUrlDataList() { |
85 | 0 | return this.childUrlDataList; |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void setChildUrlDataList(List<HtmlData> childUrlDataList) { |
92 | 0 | this.childUrlDataList = childUrlDataList; |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public String getPrependDisplayText() { |
99 | 0 | return this.prependDisplayText; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public void setPrependDisplayText(String prependDisplayText) { |
106 | 0 | this.prependDisplayText = prependDisplayText; |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public String getTitle() { |
113 | 0 | return this.title; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public void setTitle(String title) { |
120 | 0 | this.title = title; |
121 | 0 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public String getName() { |
127 | 0 | return this.name; |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public void setName(String name) { |
134 | 0 | this.name = name; |
135 | 0 | } |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public String getDisplayText() { |
141 | 0 | return this.displayText; |
142 | |
} |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public void setDisplayText(String displayText) { |
148 | 0 | this.displayText = displayText; |
149 | 0 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public String getMethodToCall() { |
155 | 0 | return this.methodToCall; |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
public void setMethodToCall(String methodToCall) { |
162 | 0 | this.methodToCall = methodToCall; |
163 | 0 | } |
164 | |
|
165 | |
public String getTitle(String prependText, Class bo, List keys) { |
166 | 0 | 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 | 0 | if (dataObject == null) |
180 | 0 | return KRADConstants.EMPTY_STRING; |
181 | |
|
182 | 0 | Map<String, String> keyValueMap = new HashMap<String, String>(); |
183 | 0 | Iterator keysIt = keys.iterator(); |
184 | 0 | while (keysIt.hasNext()) { |
185 | 0 | String fieldNm = (String) keysIt.next(); |
186 | 0 | Object fieldVal = ObjectUtils.getPropertyValue(dataObject, fieldNm); |
187 | |
|
188 | 0 | FieldRestriction fieldRestriction = null; |
189 | 0 | if (businessObjectRestrictions != null) { |
190 | 0 | fieldRestriction = businessObjectRestrictions.getFieldRestriction(fieldNm); |
191 | |
} |
192 | 0 | if (fieldRestriction != null && (fieldRestriction.isMasked() || fieldRestriction.isPartiallyMasked())) { |
193 | 0 | fieldVal = fieldRestriction.getMaskFormatter().maskValue(fieldVal); |
194 | 0 | } else if (fieldVal == null) { |
195 | 0 | fieldVal = KRADConstants.EMPTY_STRING; |
196 | 0 | } else if (fieldVal instanceof Date) { |
197 | |
|
198 | 0 | DateFormatter dateFormatter = new DateFormatter(); |
199 | 0 | fieldVal = dateFormatter.format(fieldVal); |
200 | |
} |
201 | 0 | keyValueMap.put(fieldNm, fieldVal.toString()); |
202 | 0 | } |
203 | 0 | return getTitleText(prependText, dataObject.getClass(), keyValueMap); |
204 | |
} |
205 | |
|
206 | |
private static BusinessObjectAuthorizationService businessObjectAuthorizationService; |
207 | |
private static BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() { |
208 | 0 | if (businessObjectAuthorizationService == null) { |
209 | 0 | businessObjectAuthorizationService = KNSServiceLocator.getBusinessObjectAuthorizationService(); |
210 | |
} |
211 | 0 | return businessObjectAuthorizationService; |
212 | |
} |
213 | |
|
214 | |
public static String getTitleText(String prependText, Class<?> dataObjectClass, Map<String, String> keyValueMap) { |
215 | 0 | StringBuffer titleText = new StringBuffer(prependText); |
216 | 0 | for (String key : keyValueMap.keySet()) { |
217 | 0 | String fieldVal = keyValueMap.get(key).toString(); |
218 | |
|
219 | 0 | titleText.append(KRADServiceLocatorWeb.getDataDictionaryService() |
220 | |
.getAttributeLabel(dataObjectClass, key) |
221 | |
+ "=" + fieldVal.toString() + " "); |
222 | 0 | } |
223 | 0 | 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 | 0 | protected String href = ""; |
236 | 0 | protected String target = ""; |
237 | 0 | protected String style = ""; |
238 | 0 | protected String styleClass =""; |
239 | 0 | protected String onclick =""; |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | 0 | public AnchorHtmlData() { |
245 | 0 | } |
246 | |
|
247 | 0 | public AnchorHtmlData(String href, String title) { |
248 | 0 | this.href = href; |
249 | 0 | this.title = title; |
250 | 0 | } |
251 | |
|
252 | |
public AnchorHtmlData(String href, String methodToCall, |
253 | 0 | String displayText) { |
254 | 0 | this.href = href; |
255 | 0 | this.methodToCall = methodToCall; |
256 | 0 | this.displayText = displayText; |
257 | 0 | } |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
public void setHref(String href) { |
263 | 0 | this.href = href; |
264 | 0 | } |
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
public String constructCompleteHtmlTag() { |
273 | |
String completeHtmlTag; |
274 | 0 | if (StringUtils.isEmpty(getHref())) |
275 | 0 | completeHtmlTag = getDisplayText(); |
276 | |
else |
277 | 0 | 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 | 0 | return completeHtmlTag; |
294 | |
} |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
public String getTarget() { |
300 | 0 | return this.target; |
301 | |
} |
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public void setTarget(String target) { |
308 | 0 | this.target = target; |
309 | 0 | } |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
public String getStyle() { |
315 | 0 | return this.style; |
316 | |
} |
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
public void setStyle(String style) { |
322 | 0 | this.style = style; |
323 | 0 | } |
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
public String getStyleClass() { |
329 | 0 | return this.styleClass; |
330 | |
} |
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
public void setStyleClass(String styleClass) { |
336 | 0 | this.styleClass = styleClass; |
337 | 0 | } |
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
public String getOnclick() { |
343 | 0 | return this.onclick; |
344 | |
} |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
public void setOnclick(String onclick) { |
350 | 0 | this.onclick = onclick; |
351 | 0 | } |
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
public String getHref() { |
357 | 0 | return this.href; |
358 | |
} |
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
public String getMethodToCall() { |
364 | 0 | 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 | 0 | protected String inputType = ""; |
381 | 0 | protected String src = ""; |
382 | 0 | protected String styleClass = ""; |
383 | 0 | protected String border = "0"; |
384 | 0 | protected String checked = ""; |
385 | 0 | protected String value = ""; |
386 | |
|
387 | 0 | public InputHtmlData(String name, String inputType) { |
388 | 0 | this.name = name; |
389 | 0 | this.inputType = inputType; |
390 | 0 | } |
391 | |
|
392 | 0 | public InputHtmlData(String name, String inputType, String src) { |
393 | 0 | this.name = name; |
394 | 0 | this.inputType = inputType; |
395 | 0 | this.src = src; |
396 | 0 | } |
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
public String constructCompleteHtmlTag() { |
405 | 0 | 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 | 0 | return this.inputType; |
432 | |
} |
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
public String getSrc() { |
438 | 0 | return this.src; |
439 | |
} |
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
public String getBorder() { |
445 | 0 | return this.border; |
446 | |
} |
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
public void setBorder(String border) { |
453 | 0 | this.border = border; |
454 | 0 | } |
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
public String getStyleClass() { |
460 | 0 | return this.styleClass; |
461 | |
} |
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
public void setStyleClass(String styleClass) { |
468 | 0 | this.styleClass = styleClass; |
469 | 0 | } |
470 | |
|
471 | |
|
472 | |
|
473 | |
|
474 | |
public void setChecked(String checked) { |
475 | 0 | this.checked = checked; |
476 | 0 | } |
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
public void setValue(String value) { |
482 | 0 | this.value = value; |
483 | 0 | } |
484 | |
|
485 | |
} |
486 | |
|
487 | 0 | public static class MultipleAnchorHtmlData extends AnchorHtmlData { |
488 | |
protected List<AnchorHtmlData> anchorHtmlData; |
489 | |
protected static final String ANCHORS_SEPARATOR = ", "; |
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | 0 | public MultipleAnchorHtmlData(List<AnchorHtmlData> anchorHtmlData) { |
495 | 0 | this.anchorHtmlData = anchorHtmlData; |
496 | 0 | } |
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
public String constructCompleteHtmlTag() { |
505 | 0 | StringBuffer completeHtmlTag = new StringBuffer(); |
506 | 0 | for(AnchorHtmlData anchor: anchorHtmlData){ |
507 | 0 | completeHtmlTag.append(anchor.constructCompleteHtmlTag()+","); |
508 | |
} |
509 | 0 | if(completeHtmlTag.toString().endsWith(ANCHORS_SEPARATOR)) |
510 | 0 | completeHtmlTag.delete(completeHtmlTag.length()-ANCHORS_SEPARATOR.length(), completeHtmlTag.length()); |
511 | 0 | return completeHtmlTag.toString(); |
512 | |
} |
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | |
public List<AnchorHtmlData> getAnchorHtmlData() { |
518 | 0 | return this.anchorHtmlData; |
519 | |
} |
520 | |
|
521 | |
} |
522 | |
|
523 | |
|
524 | |
|
525 | |
|
526 | |
public int getMaxLength() { |
527 | |
try{ |
528 | 0 | return Integer.parseInt(this.maxLength); |
529 | 0 | } catch(Exception ex){ |
530 | 0 | return -1; |
531 | |
} |
532 | |
} |
533 | |
|
534 | |
|
535 | |
|
536 | |
|
537 | |
public void setMaxLength(String maxLength) { |
538 | 0 | this.maxLength = maxLength; |
539 | 0 | } |
540 | |
|
541 | |
} |