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